Index: lldb/trunk/packages/Python/lldbsuite/test/commands/add-dsym/uuid/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/add-dsym/uuid/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/add-dsym/uuid/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/add-dsym/uuid/TestAddDsymCommand.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/add-dsym/uuid/TestAddDsymCommand.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/add-dsym/uuid/TestAddDsymCommand.py @@ -0,0 +1,131 @@ +"""Test that the 'add-dsym', aka 'target symbols add', command informs the user about success or failure.""" + +from __future__ import print_function + + +import os +import time +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +@skipUnlessDarwin +class AddDsymCommandCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + TestBase.setUp(self) + self.template = 'main.cpp.template' + self.source = 'main.cpp' + self.teardown_hook_added = False + + @no_debug_info_test + def test_add_dsym_command_with_error(self): + """Test that the 'add-dsym' command informs the user about failures.""" + + # Call the program generator to produce main.cpp, version 1. + self.generate_main_cpp(version=1) + self.buildDefault(dictionary={'MAKE_DSYM':'YES'}) + + # Insert some delay and then call the program generator to produce + # main.cpp, version 2. + time.sleep(5) + self.generate_main_cpp(version=101) + # Now call make again, but this time don't generate the dSYM. + self.buildDefault(dictionary={'MAKE_DSYM':'NO'}) + + self.exe_name = 'a.out' + self.do_add_dsym_with_error(self.exe_name) + + @no_debug_info_test + def test_add_dsym_command_with_success(self): + """Test that the 'add-dsym' command informs the user about success.""" + + # Call the program generator to produce main.cpp, version 1. + self.generate_main_cpp(version=1) + self.buildDefault(dictionary={'MAKE_DSYM':'YES'}) + + self.exe_name = 'a.out' + self.do_add_dsym_with_success(self.exe_name) + + @no_debug_info_test + def test_add_dsym_with_dSYM_bundle(self): + """Test that the 'add-dsym' command informs the user about success.""" + + # Call the program generator to produce main.cpp, version 1. + self.generate_main_cpp(version=1) + self.buildDefault(dictionary={'MAKE_DSYM':'YES'}) + + self.exe_name = 'a.out' + self.do_add_dsym_with_dSYM_bundle(self.exe_name) + + def generate_main_cpp(self, version=0): + """Generate main.cpp from main.cpp.template.""" + temp = os.path.join(self.getSourceDir(), self.template) + with open(temp, 'r') as f: + content = f.read() + + new_content = content.replace( + '%ADD_EXTRA_CODE%', + 'printf("This is version %d\\n");' % + version) + src = os.path.join(self.getBuildDir(), self.source) + with open(src, 'w') as f: + f.write(new_content) + + # The main.cpp has been generated, add a teardown hook to remove it. + if not self.teardown_hook_added: + self.addTearDownHook(lambda: os.remove(src)) + self.teardown_hook_added = True + + def do_add_dsym_with_error(self, exe_name): + """Test that the 'add-dsym' command informs the user about failures.""" + exe_path = self.getBuildArtifact(exe_name) + self.runCmd("file " + exe_path, CURRENT_EXECUTABLE_SET) + + wrong_path = os.path.join(self.getBuildDir(), + "%s.dSYM" % exe_name, "Contents") + self.expect("add-dsym " + wrong_path, error=True, + substrs=['invalid module path']) + + right_path = os.path.join( + self.getBuildDir(), + "%s.dSYM" % + exe_path, + "Contents", + "Resources", + "DWARF", + exe_name) + self.expect("add-dsym " + right_path, error=True, + substrs=['symbol file', 'does not match']) + + def do_add_dsym_with_success(self, exe_name): + """Test that the 'add-dsym' command informs the user about success.""" + exe_path = self.getBuildArtifact(exe_name) + self.runCmd("file " + exe_path, CURRENT_EXECUTABLE_SET) + + # This time, the UUID should match and we expect some feedback from + # lldb. + right_path = os.path.join( + self.getBuildDir(), + "%s.dSYM" % + exe_path, + "Contents", + "Resources", + "DWARF", + exe_name) + self.expect("add-dsym " + right_path, + substrs=['symbol file', 'has been added to']) + + def do_add_dsym_with_dSYM_bundle(self, exe_name): + """Test that the 'add-dsym' command informs the user about success when loading files in bundles.""" + exe_path = self.getBuildArtifact(exe_name) + self.runCmd("file " + exe_path, CURRENT_EXECUTABLE_SET) + + # This time, the UUID should be found inside the bundle + right_path = "%s.dSYM" % exe_path + self.expect("add-dsym " + right_path, + substrs=['symbol file', 'has been added to']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/add-dsym/uuid/main.cpp.template =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/add-dsym/uuid/main.cpp.template +++ lldb/trunk/packages/Python/lldbsuite/test/commands/add-dsym/uuid/main.cpp.template @@ -0,0 +1,18 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include + +int +main(int argc, char const *argv[]) +{ + int my_int = argc + 3; + printf("Hello UUID Mismatch: %d\n", my_int); // Set breakpoint here. + %ADD_EXTRA_CODE% + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/apropos/basic/TestApropos.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/apropos/basic/TestApropos.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/apropos/basic/TestApropos.py @@ -0,0 +1,29 @@ +import lldb +from lldbsuite.test.lldbtest import * +from lldbsuite.test.decorators import * + +class AproposTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + TestBase.setUp(self) + + @no_debug_info_test + def test_apropos(self): + self.expect("apropos", error=True, + substrs=[' must be called with exactly one argument']) + self.expect("apropos a b", error=True, + substrs=[' must be called with exactly one argument']) + self.expect("apropos ''", error=True, + substrs=['\'\' is not a valid search word']) + + @no_debug_info_test + def test_apropos_variable(self): + """Test that 'apropos variable' prints the fully qualified command name""" + self.expect( + 'apropos variable', + substrs=[ + 'frame variable', + 'target variable', + 'watchpoint set variable']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/apropos/with-process/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/apropos/with-process/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/apropos/with-process/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/apropos/with-process/TestAproposWithProcess.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/apropos/with-process/TestAproposWithProcess.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/apropos/with-process/TestAproposWithProcess.py @@ -0,0 +1,43 @@ +""" +Test that apropos env doesn't crash trying to touch the process plugin command +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + + +class AproposWithProcessTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break inside main(). + self.line = line_number('main.cpp', '// break here') + + def test_apropos_with_process(self): + """Test that apropos env doesn't crash trying to touch the process plugin command.""" + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Break in main() after the variables are assigned values. + 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) + + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', 'stop reason = breakpoint']) + + # The breakpoint should have a hit count of 1. + self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, + substrs=[' resolved, hit count = 1']) + + self.runCmd('apropos env') Index: lldb/trunk/packages/Python/lldbsuite/test/commands/apropos/with-process/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/apropos/with-process/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/apropos/with-process/main.cpp @@ -0,0 +1,14 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#include + +int main (int argc, char const *argv[]) +{ + return 0; // break here +} + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +C_SOURCES := main.c a.c b.c + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/TestBreakpointCommand.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/TestBreakpointCommand.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/TestBreakpointCommand.py @@ -0,0 +1,285 @@ +""" +Test lldb breakpoint command add/list/delete. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil +import side_effect + + +class BreakpointCommandTestCase(TestBase): + + NO_DEBUG_INFO_TESTCASE = True + mydir = TestBase.compute_mydir(__file__) + + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24528") + def test_breakpoint_command_sequence(self): + """Test a sequence of breakpoint command add, list, and delete.""" + self.build() + self.breakpoint_command_sequence() + + def test_script_parameters(self): + """Test a sequence of breakpoint command add, list, and delete.""" + self.build() + self.breakpoint_command_script_parameters() + + def test_commands_on_creation(self): + self.build() + self.breakpoint_commands_on_creation() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break inside main(). + self.line = line_number('main.c', '// Set break point at this line.') + # disable "There is a running process, kill it and restart?" prompt + self.runCmd("settings set auto-confirm true") + self.addTearDownHook( + lambda: self.runCmd("settings clear auto-confirm")) + + def test_delete_all_breakpoints(self): + """Test that deleting all breakpoints works.""" + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_symbol(self, "main") + lldbutil.run_break_set_by_file_and_line( + self, "main.c", self.line, num_expected_locations=1, loc_exact=True) + + self.runCmd("run", RUN_SUCCEEDED) + + self.runCmd("breakpoint delete") + self.runCmd("process continue") + self.expect("process status", PROCESS_STOPPED, + patterns=['Process .* exited with status = 0']) + + + def breakpoint_command_sequence(self): + """Test a sequence of breakpoint command add, list, and delete.""" + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Add three breakpoints on the same line. The first time we don't specify the file, + # since the default file is the one containing main: + lldbutil.run_break_set_by_file_and_line( + self, None, self.line, num_expected_locations=1, loc_exact=True) + lldbutil.run_break_set_by_file_and_line( + self, "main.c", self.line, num_expected_locations=1, loc_exact=True) + lldbutil.run_break_set_by_file_and_line( + self, "main.c", self.line, num_expected_locations=1, loc_exact=True) + # Breakpoint 4 - set at the same location as breakpoint 1 to test + # setting breakpoint commands on two breakpoints at a time + lldbutil.run_break_set_by_file_and_line( + self, None, self.line, num_expected_locations=1, loc_exact=True) + # Make sure relative path source breakpoints work as expected. We test + # with partial paths with and without "./" prefixes. + lldbutil.run_break_set_by_file_and_line( + self, "./main.c", self.line, + num_expected_locations=1, loc_exact=True) + lldbutil.run_break_set_by_file_and_line( + self, "breakpoint_command/main.c", self.line, + num_expected_locations=1, loc_exact=True) + lldbutil.run_break_set_by_file_and_line( + self, "./breakpoint_command/main.c", self.line, + num_expected_locations=1, loc_exact=True) + lldbutil.run_break_set_by_file_and_line( + self, "breakpoint/breakpoint_command/main.c", self.line, + num_expected_locations=1, loc_exact=True) + lldbutil.run_break_set_by_file_and_line( + self, "./breakpoint/breakpoint_command/main.c", self.line, + num_expected_locations=1, loc_exact=True) + # Test relative breakpoints with incorrect paths and make sure we get + # no breakpoint locations + lldbutil.run_break_set_by_file_and_line( + self, "invalid/main.c", self.line, + num_expected_locations=0, loc_exact=True) + lldbutil.run_break_set_by_file_and_line( + self, "./invalid/main.c", self.line, + num_expected_locations=0, loc_exact=True) + # Now add callbacks for the breakpoints just created. + self.runCmd( + "breakpoint command add -s command -o 'frame variable --show-types --scope' 1 4") + self.runCmd( + "breakpoint command add -s python -o 'import side_effect; side_effect.one_liner = \"one liner was here\"' 2") + self.runCmd( + "breakpoint command add --python-function bktptcmd.function 3") + + # Check that the breakpoint commands are correctly set. + + # The breakpoint list now only contains breakpoint 1. + self.expect( + "breakpoint list", "Breakpoints 1 & 2 created", substrs=[ + "2: file = 'main.c', line = %d, exact_match = 0, locations = 1" % + self.line], patterns=[ + "1: file = '.*main.c', line = %d, exact_match = 0, locations = 1" % + self.line]) + + self.expect( + "breakpoint list -f", + "Breakpoints 1 & 2 created", + substrs=[ + "2: file = 'main.c', line = %d, exact_match = 0, locations = 1" % + self.line], + patterns=[ + "1: file = '.*main.c', line = %d, exact_match = 0, locations = 1" % + self.line, + "1.1: .+at main.c:%d:?[0-9]*, .+unresolved, hit count = 0" % + self.line, + "2.1: .+at main.c:%d:?[0-9]*, .+unresolved, hit count = 0" % + self.line]) + + self.expect("breakpoint command list 1", "Breakpoint 1 command ok", + substrs=["Breakpoint commands:", + "frame variable --show-types --scope"]) + self.expect("breakpoint command list 2", "Breakpoint 2 command ok", + substrs=["Breakpoint commands (Python):", + "import side_effect", + "side_effect.one_liner"]) + self.expect("breakpoint command list 3", "Breakpoint 3 command ok", + substrs=["Breakpoint commands (Python):", + "bktptcmd.function(frame, bp_loc, internal_dict)"]) + + self.expect("breakpoint command list 4", "Breakpoint 4 command ok", + substrs=["Breakpoint commands:", + "frame variable --show-types --scope"]) + + self.runCmd("breakpoint delete 4") + + self.runCmd("command script import --allow-reload ./bktptcmd.py") + + # Next lets try some other breakpoint kinds. First break with a regular expression + # and then specify only one file. The first time we should get two locations, + # the second time only one: + + lldbutil.run_break_set_by_regexp( + self, r"._MyFunction", num_expected_locations=2) + + lldbutil.run_break_set_by_regexp( + self, + r"._MyFunction", + extra_options="-f a.c", + num_expected_locations=1) + + lldbutil.run_break_set_by_regexp( + self, + r"._MyFunction", + extra_options="-f a.c -f b.c", + num_expected_locations=2) + + # Now try a source regex breakpoint: + lldbutil.run_break_set_by_source_regexp( + self, + r"is about to return [12]0", + extra_options="-f a.c -f b.c", + num_expected_locations=2) + + lldbutil.run_break_set_by_source_regexp( + self, + r"is about to return [12]0", + extra_options="-f a.c", + num_expected_locations=1) + + # Reset our canary variables and run the program. + side_effect.one_liner = None + side_effect.bktptcmd = None + self.runCmd("run", RUN_SUCCEEDED) + + # Check the value of canary variables. + self.assertEquals("one liner was here", side_effect.one_liner) + self.assertEquals("function was here", side_effect.bktptcmd) + + # Finish the program. + self.runCmd("process continue") + + # Remove the breakpoint command associated with breakpoint 1. + self.runCmd("breakpoint command delete 1") + + # Remove breakpoint 2. + self.runCmd("breakpoint delete 2") + + self.expect( + "breakpoint command list 1", + startstr="Breakpoint 1 does not have an associated command.") + self.expect( + "breakpoint command list 2", + error=True, + startstr="error: '2' is not a currently valid breakpoint ID.") + + # The breakpoint list now only contains breakpoint 1. + self.expect( + "breakpoint list -f", + "Breakpoint 1 exists", + patterns=[ + "1: file = '.*main.c', line = %d, exact_match = 0, locations = 1, resolved = 1" % + self.line, + "hit count = 1"]) + + # Not breakpoint 2. + self.expect( + "breakpoint list -f", + "No more breakpoint 2", + matching=False, + substrs=[ + "2: file = 'main.c', line = %d, exact_match = 0, locations = 1, resolved = 1" % + self.line]) + + # Run the program again, with breakpoint 1 remaining. + self.runCmd("run", RUN_SUCCEEDED) + + # We should be stopped again due to breakpoint 1. + + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', + 'stop reason = breakpoint']) + + # The breakpoint should have a hit count of 2. + self.expect("breakpoint list -f", BREAKPOINT_HIT_TWICE, + substrs=['resolved, hit count = 2']) + + def breakpoint_command_script_parameters(self): + """Test that the frame and breakpoint location are being properly passed to the script breakpoint command function.""" + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Add a breakpoint. + lldbutil.run_break_set_by_file_and_line( + self, "main.c", self.line, num_expected_locations=1, loc_exact=True) + + # Now add callbacks for the breakpoints just created. + self.runCmd("breakpoint command add -s python -o 'import side_effect; side_effect.frame = str(frame); side_effect.bp_loc = str(bp_loc)' 1") + + # Reset canary variables and run. + side_effect.frame = None + side_effect.bp_loc = None + self.runCmd("run", RUN_SUCCEEDED) + + self.expect(side_effect.frame, exe=False, startstr="frame #0:") + self.expect(side_effect.bp_loc, exe=False, + patterns=["1.* where = .*main .* resolved, hit count = 1"]) + + def breakpoint_commands_on_creation(self): + """Test that setting breakpoint commands when creating the breakpoint works""" + exe = self.getBuildArtifact("a.out") + target = self.dbg.CreateTarget(exe) + self.assertTrue(target.IsValid(), "Created an invalid target.") + + # Add a breakpoint. + lldbutil.run_break_set_by_file_and_line( + self, "main.c", self.line, num_expected_locations=1, loc_exact=True, + extra_options='-C bt -C "thread list" -C continue') + + bkpt = target.FindBreakpointByID(1) + self.assertTrue(bkpt.IsValid(), "Couldn't find breakpoint 1") + com_list = lldb.SBStringList() + bkpt.GetCommandLineCommands(com_list) + self.assertEqual(com_list.GetSize(), 3, "Got the wrong number of commands") + self.assertEqual(com_list.GetStringAtIndex(0), "bt", "First bt") + self.assertEqual(com_list.GetStringAtIndex(1), "thread list", "Next thread list") + self.assertEqual(com_list.GetStringAtIndex(2), "continue", "Last continue") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/TestBreakpointCommandsFromPython.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/TestBreakpointCommandsFromPython.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/TestBreakpointCommandsFromPython.py @@ -0,0 +1,99 @@ +""" +Test that you can set breakpoint commands successfully with the Python API's: +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil +import side_effect + + +class PythonBreakpointCommandSettingTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True + + @add_test_categories(['pyapi']) + def test_step_out_python(self): + """Test stepping out using avoid-no-debug with dsyms.""" + self.build() + self.do_set_python_command_from_python() + + def setUp(self): + TestBase.setUp(self) + self.main_source = "main.c" + self.main_source_spec = lldb.SBFileSpec(self.main_source) + + def do_set_python_command_from_python(self): + exe = self.getBuildArtifact("a.out") + error = lldb.SBError() + + self.target = self.dbg.CreateTarget(exe) + self.assertTrue(self.target, VALID_TARGET) + + body_bkpt = self.target.BreakpointCreateBySourceRegex( + "Set break point at this line.", self.main_source_spec) + self.assertTrue(body_bkpt, VALID_BREAKPOINT) + + func_bkpt = self.target.BreakpointCreateBySourceRegex( + "Set break point at this line.", self.main_source_spec) + self.assertTrue(func_bkpt, VALID_BREAKPOINT) + + # Also test that setting a source regex breakpoint with an empty file + # spec list sets it on all files: + no_files_bkpt = self.target.BreakpointCreateBySourceRegex( + "Set a breakpoint here", lldb.SBFileSpecList(), lldb.SBFileSpecList()) + self.assertTrue(no_files_bkpt, VALID_BREAKPOINT) + num_locations = no_files_bkpt.GetNumLocations() + self.assertTrue( + num_locations >= 2, + "Got at least two breakpoint locations") + got_one_in_A = False + got_one_in_B = False + for idx in range(0, num_locations): + comp_unit = no_files_bkpt.GetLocationAtIndex(idx).GetAddress().GetSymbolContext( + lldb.eSymbolContextCompUnit).GetCompileUnit().GetFileSpec() + print("Got comp unit: ", comp_unit.GetFilename()) + if comp_unit.GetFilename() == "a.c": + got_one_in_A = True + elif comp_unit.GetFilename() == "b.c": + got_one_in_B = True + + self.assertTrue(got_one_in_A, "Failed to match the pattern in A") + self.assertTrue(got_one_in_B, "Failed to match the pattern in B") + self.target.BreakpointDelete(no_files_bkpt.GetID()) + + error = lldb.SBError() + error = body_bkpt.SetScriptCallbackBody( + "import side_effect; side_effect.callback = 'callback was here'") + self.assertTrue( + error.Success(), + "Failed to set the script callback body: %s." % + (error.GetCString())) + + self.dbg.HandleCommand( + "command script import --allow-reload ./bktptcmd.py") + func_bkpt.SetScriptCallbackFunction("bktptcmd.function") + + # Clear out canary variables + side_effect.bktptcmd = None + side_effect.callback = None + + # Now launch the process, and do not stop at entry point. + self.process = self.target.LaunchSimple( + None, None, self.get_process_working_directory()) + + self.assertTrue(self.process, PROCESS_IS_VALID) + + # Now finish, and make sure the return value is correct. + threads = lldbutil.get_threads_stopped_at_breakpoint( + self.process, body_bkpt) + self.assertTrue(len(threads) == 1, "Stopped at inner breakpoint.") + self.thread = threads[0] + + self.assertEquals("callback was here", side_effect.callback) + self.assertEquals("function was here", side_effect.bktptcmd) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/TestRegexpBreakCommand.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/TestRegexpBreakCommand.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/TestRegexpBreakCommand.py @@ -0,0 +1,71 @@ +""" +Test _regexp-break command which uses regular expression matching to dispatch to other built in breakpoint commands. +""" + +from __future__ import print_function + + +import os +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + + +class RegexpBreakCommandTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def test(self): + """Test _regexp-break command.""" + self.build() + self.regexp_break_command() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break inside main(). + self.source = 'main.c' + self.line = line_number( + self.source, '// Set break point at this line.') + + def regexp_break_command(self): + """Test the super consie "b" command, which is analias for _regexp-break.""" + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + break_results = lldbutil.run_break_set_command( + self, "b %d" % + self.line) + lldbutil.check_breakpoint_result( + self, + break_results, + file_name='main.c', + line_number=self.line, + num_locations=1) + + break_results = lldbutil.run_break_set_command( + self, "b %s:%d" % (self.source, self.line)) + lldbutil.check_breakpoint_result( + self, + break_results, + file_name='main.c', + line_number=self.line, + num_locations=1) + + # Check breakpoint with full file path. + full_path = os.path.join(self.getSourceDir(), self.source) + break_results = lldbutil.run_break_set_command( + self, "b %s:%d" % (full_path, self.line)) + lldbutil.check_breakpoint_result( + self, + break_results, + file_name='main.c', + line_number=self.line, + num_locations=1) + + 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']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/a.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/a.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/a.c @@ -0,0 +1,9 @@ +#include + +int +a_MyFunction () +{ + // Set a breakpoint here. + printf ("a is about to return 10.\n"); + return 10; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/b.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/b.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/b.c @@ -0,0 +1,9 @@ +#include + +int +b_MyFunction () +{ + // Set a breakpoint here. + printf ("b is about to return 20.\n"); + return 20; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/bktptcmd.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/bktptcmd.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/bktptcmd.py @@ -0,0 +1,5 @@ +from __future__ import print_function +import side_effect + +def function(frame, bp_loc, dict): + side_effect.bktptcmd = "function was here" Index: lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/main.c @@ -0,0 +1,16 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +int main (int argc, char const *argv[]) +{ + // Add a body to the function, so we can set more than one + // breakpoint in it. + static volatile int var = 0; + var++; + return 0; // Set break point at this line. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/side_effect.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/side_effect.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/breakpoint/basic/side_effect.py @@ -0,0 +1,5 @@ +""" +A dummy module for testing the execution of various breakpoint commands. A +command will modify a global variable in this module and test will check its +value. +""" Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/history/.categories =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/history/.categories +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/history/.categories @@ -0,0 +1 @@ +cmdline Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/history/TestCommandHistory.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/history/TestCommandHistory.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/history/TestCommandHistory.py @@ -0,0 +1,107 @@ +""" +Test the command history mechanism +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class CommandHistoryTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @no_debug_info_test + def test_history(self): + self.runCmd('command history --clear', inHistory=False) + self.runCmd('breakpoint list', check=False, inHistory=True) # 0 + self.runCmd('register read', check=False, inHistory=True) # 1 + self.runCmd('apropos hello', check=False, inHistory=True) # 2 + self.runCmd('memory write', check=False, inHistory=True) # 3 + self.runCmd('log list', check=False, inHistory=True) # 4 + self.runCmd('disassemble', check=False, inHistory=True) # 5 + self.runCmd('expression 1', check=False, inHistory=True) # 6 + self.runCmd( + 'type summary list -w default', + check=False, + inHistory=True) # 7 + self.runCmd('version', check=False, inHistory=True) # 8 + self.runCmd('frame select 1', check=False, inHistory=True) # 9 + + self.expect( + "command history -s 3 -c 3", + inHistory=True, + substrs=[ + '3: memory write', + '4: log list', + '5: disassemble']) + + self.expect("command history -s 3 -e 3", inHistory=True, + substrs=['3: memory write']) + + self.expect( + "command history -s 6 -e 7", + inHistory=True, + substrs=[ + '6: expression 1', + '7: type summary list -w default']) + + self.expect("command history -c 2", inHistory=True, + substrs=['0: breakpoint list', '1: register read']) + + self.expect("command history -e 3 -c 1", inHistory=True, + substrs=['3: memory write']) + + self.expect( + "command history -e 2", + inHistory=True, + substrs=[ + '0: breakpoint list', + '1: register read', + '2: apropos hello']) + + self.expect( + "command history -s 12", + inHistory=True, + substrs=[ + '12: command history -s 6 -e 7', + '13: command history -c 2', + '14: command history -e 3 -c 1', + '15: command history -e 2', + '16: command history -s 12']) + + self.expect( + "command history -s end -c 3", + inHistory=True, + substrs=[ + '15: command history -e 2', + '16: command history -s 12', + '17: command history -s end -c 3']) + + self.expect( + "command history -s end -e 15", + inHistory=True, + substrs=[ + '15: command history -e 2', + '16: command history -s 12', + '17: command history -s end -c 3', + 'command history -s end -e 15']) + + self.expect("command history -s 5 -c 1", inHistory=True, + substrs=['5: disassemble']) + + self.expect("command history -c 1 -s 5", inHistory=True, + substrs=['5: disassemble']) + + self.expect("command history -c 1 -e 3", inHistory=True, + substrs=['3: memory write']) + + self.expect( + "command history -c 1 -e 3 -s 5", + error=True, + inHistory=True, + substrs=['error: --count, --start-index and --end-index cannot be all specified in the same invocation']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/nested_alias/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/nested_alias/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/nested_alias/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/nested_alias/TestNestedAlias.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/nested_alias/TestNestedAlias.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/nested_alias/TestNestedAlias.py @@ -0,0 +1,90 @@ +""" +Test that an alias can reference other aliases without crashing. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + + +class NestedAliasTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break inside main(). + self.line = line_number('main.cpp', '// break here') + + def test_nested_alias(self): + """Test that an alias can reference other aliases without crashing.""" + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Break in main() after the variables are assigned values. + 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) + + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', 'stop reason = breakpoint']) + + # The breakpoint should have a hit count of 1. + self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, + substrs=[' resolved, hit count = 1']) + + # This is the function to remove the custom aliases in order to have a + # clean slate for the next test case. + def cleanup(): + self.runCmd('command unalias read', check=False) + self.runCmd('command unalias rd', check=False) + self.runCmd('command unalias fo', check=False) + self.runCmd('command unalias foself', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.runCmd('command alias read memory read -f A') + self.runCmd('command alias rd read -c 3') + + self.expect( + 'memory read -f A -c 3 `&my_ptr[0]`', + substrs=[ + 'deadbeef', + 'main.cpp:', + 'feedbeef']) + self.expect( + 'rd `&my_ptr[0]`', + substrs=[ + 'deadbeef', + 'main.cpp:', + 'feedbeef']) + + self.expect( + 'memory read -f A -c 3 `&my_ptr[0]`', + substrs=['deadfeed'], + matching=False) + self.expect('rd `&my_ptr[0]`', substrs=['deadfeed'], matching=False) + + self.runCmd('command alias fo frame variable -O --') + self.runCmd('command alias foself fo self') + + self.expect( + 'help foself', + substrs=[ + '--show-all-children', + '--raw-output'], + matching=False) + self.expect( + 'help foself', + substrs=[ + 'Show variables for the current', + 'stack frame.'], + matching=True) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/nested_alias/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/nested_alias/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/nested_alias/main.cpp @@ -0,0 +1,21 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#include + +int main (int argc, char const *argv[]) +{ + void* my_ptr[] = { + reinterpret_cast(0xDEADBEEF), + reinterpret_cast(main), + reinterpret_cast(0xFEEDBEEF), + reinterpret_cast(0xFEEDDEAD), + reinterpret_cast(0xDEADFEED) + }; + return 0; // break here +} + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/.categories =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/.categories +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/.categories @@ -0,0 +1 @@ +cmdline Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/TestCommandScript.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/TestCommandScript.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/TestCommandScript.py @@ -0,0 +1,153 @@ +""" +Test lldb Python commands. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * + + +class CmdPythonTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True + + def test(self): + self.build() + self.pycmd_tests() + + def pycmd_tests(self): + self.runCmd("command source py_import") + + # Verify command that specifies eCommandRequiresTarget returns failure + # without a target. + self.expect('targetname', + substrs=['a.out'], matching=False, error=True) + + exe = self.getBuildArtifact("a.out") + self.expect("file " + exe, + patterns=["Current executable set to .*a.out"]) + + self.expect('targetname', + substrs=['a.out'], matching=True, error=False) + + # This is the function to remove the custom commands in order to have a + # clean slate for the next test case. + def cleanup(): + self.runCmd('command script delete welcome', check=False) + self.runCmd('command script delete targetname', check=False) + self.runCmd('command script delete longwait', check=False) + self.runCmd('command script delete mysto', check=False) + self.runCmd('command script delete tell_sync', check=False) + self.runCmd('command script delete tell_async', check=False) + self.runCmd('command script delete tell_curr', check=False) + self.runCmd('command script delete bug11569', check=False) + self.runCmd('command script delete takes_exe_ctx', check=False) + self.runCmd('command script delete decorated', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + # Interact with debugger in synchronous mode + self.setAsync(False) + + # We don't want to display the stdout if not in TraceOn() mode. + if not self.TraceOn(): + self.HideStdout() + + self.expect('welcome Enrico', + substrs=['Hello Enrico, welcome to LLDB']) + + self.expect("help welcome", + substrs=['Just a docstring for welcome_impl', + 'A command that says hello to LLDB users']) + + decorated_commands = ["decorated" + str(n) for n in range(1, 5)] + for name in decorated_commands: + self.expect(name, substrs=["hello from " + name]) + self.expect("help " + name, + substrs=["Python command defined by @lldb.command"]) + + self.expect("help", + substrs=['For more information run', + 'welcome'] + decorated_commands) + + self.expect("help -a", + substrs=['For more information run', + 'welcome'] + decorated_commands) + + self.expect("help -u", matching=False, + substrs=['For more information run']) + + self.runCmd("command script delete welcome") + + self.expect('welcome Enrico', matching=False, error=True, + substrs=['Hello Enrico, welcome to LLDB']) + + self.expect('targetname fail', error=True, + substrs=['a test for error in command']) + + self.expect('command script list', + substrs=['targetname', + 'For more information run']) + + self.expect("help targetname", + substrs=['Expects', '\'raw\'', 'input', + 'help', 'raw-input']) + + self.expect("longwait", + substrs=['Done; if you saw the delays I am doing OK']) + + self.runCmd("b main") + self.runCmd("run") + self.runCmd("mysto 3") + self.expect("frame variable array", + substrs=['[0] = 79630', '[1] = 388785018', '[2] = 0']) + self.runCmd("mysto 3") + self.expect("frame variable array", + substrs=['[0] = 79630', '[4] = 388785018', '[5] = 0']) + +# we cannot use the stepover command to check for async execution mode since LLDB +# seems to get confused when events start to queue up + self.expect("tell_sync", + substrs=['running sync']) + self.expect("tell_async", + substrs=['running async']) + self.expect("tell_curr", + substrs=['I am running sync']) + +# check that the execution context is passed in to commands that ask for it + self.expect("takes_exe_ctx", substrs=["a.out"]) + + # Test that a python command can redefine itself + self.expect('command script add -f foobar welcome -h "just some help"') + + self.runCmd("command script clear") + + # Test that re-defining an existing command works + self.runCmd( + 'command script add my_command --class welcome.WelcomeCommand') + self.expect('my_command Blah', substrs=['Hello Blah, welcome to LLDB']) + + self.runCmd( + 'command script add my_command --class welcome.TargetnameCommand') + self.expect('my_command', substrs=['a.out']) + + self.runCmd("command script clear") + + self.expect('command script list', matching=False, + substrs=['targetname', + 'longwait']) + + self.expect('command script add -f foobar frame', error=True, + substrs=['cannot add command']) + + # http://llvm.org/bugs/show_bug.cgi?id=11569 + # LLDBSwigPythonCallCommand crashes when a command script returns an + # object + self.runCmd('command script add -f bug11569 bug11569') + # This should not crash. + self.runCmd('bug11569', check=False) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/bug11569.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/bug11569.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/bug11569.py @@ -0,0 +1,6 @@ +def bug11569(debugger, args, result, dict): + """ + http://llvm.org/bugs/show_bug.cgi?id=11569 + LLDBSwigPythonCallCommand crashes when a command script returns an object. + """ + return ["return", "a", "non-string", "should", "not", "crash", "LLDB"] Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/decorated.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/decorated.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/decorated.py @@ -0,0 +1,35 @@ +from __future__ import print_function + +import lldb + + +@lldb.command() +def decorated1(debugger, args, exe_ctx, result, dict): + """ + Python command defined by @lldb.command + """ + print("hello from decorated1", file=result) + + +@lldb.command(doc="Python command defined by @lldb.command") +def decorated2(debugger, args, exe_ctx, result, dict): + """ + This docstring is overridden. + """ + print("hello from decorated2", file=result) + + +@lldb.command() +def decorated3(debugger, args, result, dict): + """ + Python command defined by @lldb.command + """ + print("hello from decorated3", file=result) + + +@lldb.command("decorated4") +def _decorated4(debugger, args, exe_ctx, result, dict): + """ + Python command defined by @lldb.command + """ + print("hello from decorated4", file=result) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/Makefile @@ -0,0 +1,6 @@ +LEVEL = ../../../make + +C_SOURCES := main.c +EXE := hello_world + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/TestImport.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/TestImport.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/TestImport.py @@ -0,0 +1,76 @@ +"""Test custom import command to import files by path.""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class ImportTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @add_test_categories(['pyapi']) + @no_debug_info_test + def test_import_command(self): + """Import some Python scripts by path and test them""" + self.run_test() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + def run_test(self): + """Import some Python scripts by path and test them.""" + + # This is the function to remove the custom commands in order to have a + # clean slate for the next test case. + def cleanup(): + self.runCmd('command script delete foo2cmd', check=False) + self.runCmd('command script delete foocmd', check=False) + self.runCmd('command script delete foobarcmd', check=False) + self.runCmd('command script delete barcmd', check=False) + self.runCmd('command script delete barothercmd', check=False) + self.runCmd('command script delete TPcommandA', check=False) + self.runCmd('command script delete TPcommandB', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.runCmd("command script import ./foo/foo.py --allow-reload") + self.runCmd("command script import ./foo/foo2.py --allow-reload") + self.runCmd("command script import ./foo/bar/foobar.py --allow-reload") + self.runCmd("command script import ./bar/bar.py --allow-reload") + + self.expect("command script import ./nosuchfile.py", + error=True, startstr='error: module importing failed') + self.expect("command script import ./nosuchfolder/", + error=True, startstr='error: module importing failed') + self.expect("command script import ./foo/foo.py", error=False) + + self.runCmd("command script import --allow-reload ./thepackage") + self.expect("TPcommandA", substrs=["hello world A"]) + self.expect("TPcommandB", substrs=["hello world B"]) + + self.runCmd("script import dummymodule") + self.expect("command script import ./dummymodule.py", error=False) + self.expect( + "command script import --allow-reload ./dummymodule.py", + error=False) + + self.runCmd("command script add -f foo.foo_function foocmd") + self.runCmd("command script add -f foobar.foo_function foobarcmd") + self.runCmd("command script add -f bar.bar_function barcmd") + self.expect("foocmd hello", + substrs=['foo says', 'hello']) + self.expect("foo2cmd hello", + substrs=['foo2 says', 'hello']) + self.expect("barcmd hello", + substrs=['barutil says', 'bar told me', 'hello']) + self.expect("barothercmd hello", + substrs=['barutil says', 'bar told me', 'hello']) + self.expect("foobarcmd hello", + substrs=['foobar says', 'hello']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/bar/bar.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/bar/bar.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/bar/bar.py @@ -0,0 +1,15 @@ +from __future__ import print_function + + +def bar_function(debugger, args, result, dict): + global UtilityModule + print(UtilityModule.barutil_function("bar told me " + args), file=result) + return None + + +def __lldb_init_module(debugger, session_dict): + global UtilityModule + UtilityModule = __import__("barutil") + debugger.HandleCommand( + "command script add -f bar.bar_function barothercmd") + return None Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/bar/barutil.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/bar/barutil.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/bar/barutil.py @@ -0,0 +1,2 @@ +def barutil_function(x): + return "barutil says: " + x Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/dummymodule.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/dummymodule.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/dummymodule.py @@ -0,0 +1,2 @@ +def no_useful_code(foo): + return foo Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/foo/bar/foobar.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/foo/bar/foobar.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/foo/bar/foobar.py @@ -0,0 +1,6 @@ +from __future__ import print_function + + +def foo_function(debugger, args, result, dict): + print("foobar says " + args, file=result) + return None Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/foo/foo.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/foo/foo.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/foo/foo.py @@ -0,0 +1,6 @@ +from __future__ import print_function + + +def foo_function(debugger, args, result, dict): + print("foo says " + args, file=result) + return None Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/foo/foo2.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/foo/foo2.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/foo/foo2.py @@ -0,0 +1,11 @@ +from __future__ import print_function + + +def foo2_function(debugger, args, result, dict): + print("foo2 says " + args, file=result) + return None + + +def __lldb_init_module(debugger, session_dict): + debugger.HandleCommand("command script add -f foo2.foo2_function foo2cmd") + return None Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/main.c @@ -0,0 +1,15 @@ +#include + +int main(int argc, char const *argv[]) { + printf("Hello world.\n"); // Set break point at this line. + if (argc == 1) + return 0; + + // Waiting to be attached by the debugger, otherwise. + char line[100]; + while (fgets(line, sizeof(line), stdin)) { // Waiting to be attached... + printf("input line=>%s\n", line); + } + + printf("Exiting now\n"); +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/rdar-12586188/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/rdar-12586188/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/rdar-12586188/Makefile @@ -0,0 +1,3 @@ +LEVEL = ../../../../make + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/rdar-12586188/TestRdar12586188.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/rdar-12586188/TestRdar12586188.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/rdar-12586188/TestRdar12586188.py @@ -0,0 +1,36 @@ +"""Check that we handle an ImportError in a special way when command script importing files.""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class Rdar12586188TestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @add_test_categories(['pyapi']) + @no_debug_info_test + def test_rdar12586188_command(self): + """Check that we handle an ImportError in a special way when command script importing files.""" + self.run_test() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + def run_test(self): + """Check that we handle an ImportError in a special way when command script importing files.""" + + self.expect( + "command script import ./fail12586188.py --allow-reload", + error=True, + substrs=['raise ImportError("I do not want to be imported")']) + self.expect( + "command script import ./fail212586188.py --allow-reload", + error=True, + substrs=['raise ValueError("I do not want to be imported")']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/rdar-12586188/fail12586188.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/rdar-12586188/fail12586188.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/rdar-12586188/fail12586188.py @@ -0,0 +1,4 @@ +def f(x): + return x + 1 + +raise ImportError("I do not want to be imported") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/rdar-12586188/fail212586188.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/rdar-12586188/fail212586188.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/rdar-12586188/fail212586188.py @@ -0,0 +1,4 @@ +def f(x): + return x + 1 + +raise ValueError("I do not want to be imported") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/thepackage/TPunitA.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/thepackage/TPunitA.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/thepackage/TPunitA.py @@ -0,0 +1,7 @@ + +import six + + +def command(debugger, command, result, internal_dict): + result.PutCString(six.u("hello world A")) + return None Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/thepackage/TPunitB.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/thepackage/TPunitB.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/thepackage/TPunitB.py @@ -0,0 +1,7 @@ + +import six + + +def command(debugger, command, result, internal_dict): + result.PutCString(six.u("hello world B")) + return None Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/thepackage/__init__.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/thepackage/__init__.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/import/thepackage/__init__.py @@ -0,0 +1,11 @@ +from __future__ import absolute_import + +from . import TPunitA +from . import TPunitB + + +def __lldb_init_module(debugger, *args): + debugger.HandleCommand( + "command script add -f thepackage.TPunitA.command TPcommandA") + debugger.HandleCommand( + "command script add -f thepackage.TPunitB.command TPcommandB") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/main.cpp @@ -0,0 +1,69 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include +#include +#include +#include +#include + +int +product (int x, int y) +{ + int result = x * y; + return result; +} + +int +sum (int a, int b) +{ + int result = a + b; + return result; +} + +int +strange_max (int m, int n) +{ + if (m > n) + return m; + else if (n > m) + return n; + else + return 0; +} + +int +foo (int i, int j) +{ + if (strange_max (i, j) == i) + return product (i, j); + else if (strange_max (i, j) == j) + return sum (i, j); + else + return product (sum (i, i), sum (j, j)); +} + +int +main(int argc, char const *argv[]) +{ + + int array[9]; + memset(array,0,9*sizeof(int)); + + array[0] = foo (1238, 78392); + array[1] = foo (379265, 23674); + array[2] = foo (872934, 234); + array[3] = foo (1238, 78392); + array[4] = foo (379265, 23674); + array[5] = foo (872934, 234); + array[6] = foo (1238, 78392); + array[7] = foo (379265, 23674); + array[8] = foo (872934, 234); + + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/mysto.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/mysto.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/mysto.py @@ -0,0 +1,22 @@ +from __future__ import print_function + +import lldb + + +def StepOver(debugger, args, result, dict): + """ + Step over a given number of times instead of only just once + """ + arg_split = args.split(" ") + print(type(arg_split)) + count = int(arg_split[0]) + for i in range(0, count): + debugger.GetSelectedTarget().GetProcess( + ).GetSelectedThread().StepOver(lldb.eOnlyThisThread) + print("step<%d>" % i) + + +def __lldb_init_module(debugger, session_dict): + # by default, --synchronicity is set to synchronous + debugger.HandleCommand("command script add -f mysto.StepOver mysto") + return None Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/py_import =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/py_import +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/py_import @@ -0,0 +1,13 @@ +script import sys, os +script sys.path.append(os.path.join(os.getcwd(), os.pardir)) +script import welcome +script import bug11569 +command script add welcome --class welcome.WelcomeCommand +command script add targetname --class welcome.TargetnameCommand +command script add longwait --function welcome.print_wait_impl +command script import mysto.py --allow-reload +command script add tell_sync --function welcome.check_for_synchro --synchronicity sync +command script add tell_async --function welcome.check_for_synchro --synchronicity async +command script add tell_curr --function welcome.check_for_synchro --synchronicity curr +command script add takes_exe_ctx --function welcome.takes_exe_ctx +command script import decorated.py Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/welcome.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/welcome.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script/welcome.py @@ -0,0 +1,53 @@ +from __future__ import print_function +import lldb +import sys + + +class WelcomeCommand(object): + + def __init__(self, debugger, session_dict): + pass + + def get_short_help(self): + return "Just a docstring for welcome_impl\nA command that says hello to LLDB users" + + def __call__(self, debugger, args, exe_ctx, result): + print('Hello ' + args + ', welcome to LLDB', file=result) + return None + + +class TargetnameCommand(object): + + def __init__(self, debugger, session_dict): + pass + + def __call__(self, debugger, args, exe_ctx, result): + target = debugger.GetSelectedTarget() + file = target.GetExecutable() + print('Current target ' + file.GetFilename(), file=result) + if args == 'fail': + result.SetError('a test for error in command') + + def get_flags(self): + return lldb.eCommandRequiresTarget + + +def print_wait_impl(debugger, args, result, dict): + result.SetImmediateOutputFile(sys.stdout) + print('Trying to do long task..', file=result) + import time + time.sleep(1) + print('Still doing long task..', file=result) + time.sleep(1) + print('Done; if you saw the delays I am doing OK', file=result) + + +def check_for_synchro(debugger, args, result, dict): + if debugger.GetAsync(): + print('I am running async', file=result) + if debugger.GetAsync() == False: + print('I am running sync', file=result) + + +def takes_exe_ctx(debugger, args, exe_ctx, result, dict): + print(str(exe_ctx.GetTarget()), file=result) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script_alias/.categories =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script_alias/.categories +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script_alias/.categories @@ -0,0 +1 @@ +cmdline Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script_alias/TestCommandScriptAlias.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script_alias/TestCommandScriptAlias.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script_alias/TestCommandScriptAlias.py @@ -0,0 +1,38 @@ +""" +Test lldb Python commands. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.lldbtest import * + + +class CommandScriptAliasTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def test(self): + self.pycmd_tests() + + def pycmd_tests(self): + self.runCmd("command script import tcsacmd.py") + self.runCmd("command script add -f tcsacmd.some_command_here attach") + + # This is the function to remove the custom commands in order to have a + # clean slate for the next test case. + def cleanup(): + self.runCmd('command script delete attach', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + # We don't want to display the stdout if not in TraceOn() mode. + if not self.TraceOn(): + self.HideStdout() + + self.expect('attach a', substrs=['Victory is mine']) + self.runCmd("command script delete attach") + # this can't crash but we don't care whether the actual attach works + self.runCmd('attach noprocessexistswiththisname', check=False) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/script_alias/tcsacmd.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/script_alias/tcsacmd.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/script_alias/tcsacmd.py @@ -0,0 +1,11 @@ +from __future__ import print_function +import lldb + + +def some_command_here(debugger, command, result, d): + if command == "a": + print("Victory is mine", file=result) + return True + else: + print("Sadness for all", file=result) + return False Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/source/.categories =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/source/.categories +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/source/.categories @@ -0,0 +1 @@ +cmdline Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/source/.lldb =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/source/.lldb +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/source/.lldb @@ -0,0 +1,2 @@ +# one more level of indirection to stress the command interpreter reentrancy +command source commands.txt Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/source/TestCommandSource.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/source/TestCommandSource.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/source/TestCommandSource.py @@ -0,0 +1,35 @@ +""" +Test that lldb command "command source" works correctly. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class CommandSourceTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @no_debug_info_test + def test_command_source(self): + """Test that lldb command "command source" works correctly.""" + + # Sourcing .lldb in the current working directory, which in turn imports + # the "my" package that defines the date() function. + self.runCmd("command source .lldb") + + # Python should evaluate "my.date()" successfully. + command_interpreter = self.dbg.GetCommandInterpreter() + self.assertTrue(command_interpreter, VALID_COMMAND_INTERPRETER) + result = lldb.SBCommandReturnObject() + command_interpreter.HandleCommand("script my.date()", result) + + import datetime + self.expect(result.GetOutput(), "script my.date() runs successfully", + exe=False, + substrs=[str(datetime.date.today())]) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/source/commands.txt =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/source/commands.txt +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/source/commands.txt @@ -0,0 +1,2 @@ +script import my +p 1 + 1 Index: lldb/trunk/packages/Python/lldbsuite/test/commands/command/source/my.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/command/source/my.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/command/source/my.py @@ -0,0 +1,7 @@ +from __future__ import print_function + + +def date(): + import datetime + today = datetime.date.today() + print(today) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/disassemble/basic/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/disassemble/basic/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/disassemble/basic/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/disassemble/basic/TestDisassembleBreakpoint.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/disassemble/basic/TestDisassembleBreakpoint.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/disassemble/basic/TestDisassembleBreakpoint.py @@ -0,0 +1,39 @@ +""" +Test some lldb command abbreviations. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class DisassemblyTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True + + def test(self): + self.build() + target, _, _, bkpt = lldbutil.run_to_source_breakpoint(self, + "Set a breakpoint here", lldb.SBFileSpec("main.cpp")) + self.runCmd("dis -f") + disassembly_with_break = self.res.GetOutput().splitlines() + + self.assertTrue(target.BreakpointDelete(bkpt.GetID())) + + self.runCmd("dis -f") + disassembly_without_break = self.res.GetOutput().splitlines() + + # Make sure all assembly instructions are the same as instructions + # with the breakpoint removed. + self.assertEqual(len(disassembly_with_break), + len(disassembly_without_break)) + for dis_inst_with, dis_inst_without in \ + zip(disassembly_with_break, disassembly_without_break): + inst_with = dis_inst_with.split(':')[-1] + inst_without = dis_inst_without.split(':')[-1] + self.assertEqual(inst_with, inst_without) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/disassemble/basic/TestFrameDisassemble.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/disassemble/basic/TestFrameDisassemble.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/disassemble/basic/TestFrameDisassemble.py @@ -0,0 +1,65 @@ +""" +Test to ensure SBFrame::Disassemble produces SOME output +""" + +from __future__ import print_function + + +import lldb +import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.lldbtest import * + + +class FrameDisassembleTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + NO_DEBUG_INFO_TESTCASE = True + + def test_frame_disassemble(self): + """Sample test to ensure SBFrame::Disassemble produces SOME output.""" + self.build() + self.frame_disassemble_test() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + def frame_disassemble_test(self): + """Sample test to ensure SBFrame::Disassemble produces SOME output""" + exe = self.getBuildArtifact("a.out") + + # Create a target by the debugger. + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + # Now create a breakpoint in main.c at the source matching + # "Set a breakpoint here" + breakpoint = target.BreakpointCreateBySourceRegex( + "Set a breakpoint here", lldb.SBFileSpec("main.cpp")) + self.assertTrue(breakpoint and + breakpoint.GetNumLocations() >= 1, + VALID_BREAKPOINT) + + error = lldb.SBError() + # This is the launch info. If you want to launch with arguments or + # environment variables, add them using SetArguments or + # SetEnvironmentEntries + + launch_info = lldb.SBLaunchInfo(None) + process = target.Launch(launch_info, error) + self.assertTrue(process, PROCESS_IS_VALID) + + # Did we hit our breakpoint? + from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint + threads = get_threads_stopped_at_breakpoint(process, breakpoint) + self.assertTrue( + len(threads) == 1, + "There should be a thread stopped at our breakpoint") + + # The hit count for the breakpoint should be 1. + self.assertTrue(breakpoint.GetHitCount() == 1) + + frame = threads[0].GetFrameAtIndex(0) + disassembly = frame.Disassemble() + self.assertTrue(len(disassembly) != 0, "Disassembly was empty.") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/disassemble/basic/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/disassemble/basic/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/disassemble/basic/main.cpp @@ -0,0 +1,27 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +int +sum (int a, int b) +{ + int result = a + b; // Set a breakpoint here + return result; +} + +int +main(int argc, char const *argv[]) +{ + + int array[3]; + + array[0] = sum (1238, 78392); + array[1] = sum (379265, 23674); + array[2] = sum (872934, 234); + + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/.categories =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/.categories +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/.categories @@ -0,0 +1 @@ +expression Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/anonymous-struct/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/anonymous-struct/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/anonymous-struct/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/anonymous-struct/TestCallUserAnonTypedef.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/anonymous-struct/TestCallUserAnonTypedef.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/anonymous-struct/TestCallUserAnonTypedef.py @@ -0,0 +1,45 @@ +""" +Test calling user defined functions using expression evaluation. +This test checks that typesystem lookup works correctly for typedefs of +untagged structures. + +Ticket: https://llvm.org/bugs/show_bug.cgi?id=26790 +""" + +from __future__ import print_function + +import lldb + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestExprLookupAnonStructTypedef(TestBase): + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + TestBase.setUp(self) + # Find the breakpoint + self.line = line_number('main.cpp', '// lldb testsuite break') + + @expectedFailureAll( + oslist=['linux'], + archs=['arm'], + bugnumber="llvm.org/pr27868") + def test(self): + """Test typedeffed untagged struct arguments for function call expressions""" + self.build() + + self.runCmd("file "+self.getBuildArtifact("a.out"), + CURRENT_EXECUTABLE_SET) + lldbutil.run_break_set_by_file_and_line( + self, + "main.cpp", + self.line, + num_expected_locations=-1, + loc_exact=True + ) + + self.runCmd("run", RUN_SUCCEEDED) + self.expect("expr multiply(&s)", substrs=['$0 = 1']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/anonymous-struct/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/anonymous-struct/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/anonymous-struct/main.cpp @@ -0,0 +1,26 @@ +#include + +typedef struct { + float f; + int i; +} my_untagged_struct; + +double multiply(my_untagged_struct *s) +{ + return s->f * s->i; +} + +double multiply(my_untagged_struct *s, int x) +{ + return multiply(s) * x; +} + +int main(int argc, char **argv) +{ + my_untagged_struct s = { + .f = (float)argc, + .i = argc, + }; + // lldb testsuite break + return !(multiply(&s, argc) == pow(argc, 3)); +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/argument_passing_restrictions/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/argument_passing_restrictions/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/argument_passing_restrictions/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/argument_passing_restrictions/TestArgumentPassingRestrictions.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/argument_passing_restrictions/TestArgumentPassingRestrictions.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/argument_passing_restrictions/TestArgumentPassingRestrictions.py @@ -0,0 +1,33 @@ +""" +This is a test to ensure that both lldb is reconstructing the right +calling convention for a CXXRecordDecl as represented by: + + DW_CC_pass_by_reference + DW_CC_pass_by_value + +and to also make sure that the ASTImporter is copying over this +setting when importing the CXXRecordDecl via setArgPassingRestrictions. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestArgumentPassingRestrictions(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @skipIf(compiler="clang", compiler_version=['<', '7.0']) + def test_argument_passing_restrictions(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, '// break here', + lldb.SBFileSpec("main.cpp")) + + self.expect("expr returnPassByRef()", + substrs=['(PassByRef)', '= 11223344']) + + self.expect("expr takePassByRef(p)", + substrs=['(int)', '= 42']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/argument_passing_restrictions/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/argument_passing_restrictions/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/argument_passing_restrictions/main.cpp @@ -0,0 +1,19 @@ +// This structure has a non-trivial copy constructor so +// it needs to be passed by reference. +struct PassByRef { + PassByRef() = default; + PassByRef(const PassByRef &p){x = p.x;}; + + int x = 11223344; +}; + +PassByRef returnPassByRef() { return PassByRef(); } +int takePassByRef(PassByRef p) { + return p.x; +} + +int main() { + PassByRef p = returnPassByRef(); + p.x = 42; + return takePassByRef(p); // break here +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/calculator_mode/TestCalculatorMode.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/calculator_mode/TestCalculatorMode.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/calculator_mode/TestCalculatorMode.py @@ -0,0 +1,27 @@ +""" +Test calling an expression without a target. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestCalculatorMode(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + def test__calculator_mode(self): + """Test calling expressions in the dummy target.""" + self.expect("expression 11 + 22", "11 + 22 didn't get the expected result", substrs=["33"]) + # Now try it with a specific language: + self.expect("expression -l c -- 11 + 22", "11 + 22 didn't get the expected result", substrs=["33"]) + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-function/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-function/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-function/Makefile @@ -0,0 +1,8 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules + +clean:: + rm -rf $(wildcard *.o *.d *.dSYM) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-function/TestCallBuiltinFunction.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-function/TestCallBuiltinFunction.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-function/TestCallBuiltinFunction.py @@ -0,0 +1,53 @@ +""" +Tests calling builtin functions using expression evaluation. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class ExprCommandCallBuiltinFunction(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # Builtins are expanded by Clang, so debug info shouldn't matter. + NO_DEBUG_INFO_TESTCASE = True + + def setUp(self): + 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:') + + def test(self): + self.build() + + # Set breakpoint in main and run exe + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + lldbutil.run_break_set_by_file_and_line( + self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True) + + self.runCmd("run", RUN_SUCCEEDED) + + interp = self.dbg.GetCommandInterpreter() + result = lldb.SBCommandReturnObject() + + # Test different builtin functions. + + interp.HandleCommand("expr __builtin_isinf(0.0f)", result) + self.assertEqual(result.GetOutput(), "(int) $0 = 0\n") + + interp.HandleCommand("expr __builtin_isnormal(0.0f)", result) + self.assertEqual(result.GetOutput(), "(int) $1 = 0\n") + + interp.HandleCommand("expr __builtin_constant_p(1)", result) + self.assertEqual(result.GetOutput(), "(int) $2 = 1\n") + + interp.HandleCommand("expr __builtin_abs(-14)", result) + self.assertEqual(result.GetOutput(), "(int) $3 = 14\n") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-function/TestCallStdStringFunction.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-function/TestCallStdStringFunction.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-function/TestCallStdStringFunction.py @@ -0,0 +1,57 @@ +""" +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__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break for main.c. + self.line = line_number( + 'main.cpp', + '// Please test these expressions while stopped at this line:') + + @expectedFailureAll( + compiler="icc", + bugnumber="llvm.org/pr14437, fails with ICC 13.1") + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765") + def test_with(self): + """Test calling std::String member function.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("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) + + self.runCmd("run", RUN_SUCCEEDED) + + self.expect("print str", + 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. + + # clang's libstdc++ on ios arm64 inlines std::string::c_str() always; + # skip this part of the test. + triple = self.dbg.GetSelectedPlatform().GetTriple() + do_cstr_test = True + if triple == "arm64-apple-ios" or triple == "arm64-apple-tvos" or triple == "armv7k-apple-watchos" or triple == "arm64-apple-bridgeos": + do_cstr_test = False + if do_cstr_test: + self.expect("print str.c_str()", + substrs=['Hello world']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-function/TestCallStopAndContinue.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-function/TestCallStopAndContinue.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-function/TestCallStopAndContinue.py @@ -0,0 +1,53 @@ +""" +Test calling a function, stopping in the call, continue and gather the result on stop. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class ExprCommandCallStopContinueTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break for main.c. + self.line = line_number( + 'main.cpp', + '// Please test these expressions while stopped at this line:') + self.func_line = line_number('main.cpp', '{5, "five"}') + + def test(self): + """Test gathering result from interrupted function call.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("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) + + 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) + + self.expect("expr -i false -- returnsFive()", error=True, + 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")']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-function/TestCallUserDefinedFunction.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-function/TestCallUserDefinedFunction.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-function/TestCallUserDefinedFunction.py @@ -0,0 +1,58 @@ +""" +Test calling user defined functions using expression evaluation. + +Note: + LLDBs current first choice of evaluating functions is using the IR interpreter, + which is only supported on Hexagon. Otherwise JIT is used for the evaluation. + +""" + +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__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break for main.c. + self.line = line_number( + 'main.cpp', + '// Please test these expressions while stopped at this line:') + + def test(self): + """Test return values of user defined function calls.""" + self.build() + + # Set breakpoint in main and run exe + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + lldbutil.run_break_set_by_file_and_line( + self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True) + + self.runCmd("run", RUN_SUCCEEDED) + + # Test recursive function call. + self.expect("expr fib(5)", substrs=['$0 = 5']) + + # Test function with more than one paramter + 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']) + + # 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']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-function/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-function/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-function/main.cpp @@ -0,0 +1,53 @@ +#include +#include +#include + +struct Five +{ + int number; + const char *name; +}; + +Five +returnsFive() +{ + Five my_five = {5, "five"}; + return my_five; +} + +unsigned int +fib(unsigned int n) +{ + if (n < 2) + return n; + else + return fib(n - 1) + fib(n - 2); +} + +int +add(int a, int b) +{ + return a + b; +} + +bool +stringCompare(const char *str) +{ + if (strcmp( str, "Hello world" ) == 0) + return true; + else + return false; +} + +int main (int argc, char const *argv[]) +{ + std::string str = "Hello world"; + std::cout << str << std::endl; + std::cout << str.c_str() << std::endl; + Five main_five = returnsFive(); +#if 0 + print str + print str.c_str() +#endif + return 0; // Please test these expressions while stopped at this line: +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/Makefile @@ -0,0 +1,8 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules + +clean:: + rm -rf $(wildcard *.o *.d *.dSYM) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/TestCallOverriddenMethod.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/TestCallOverriddenMethod.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/TestCallOverriddenMethod.py @@ -0,0 +1,49 @@ +""" +Test calling an overriden method. + +Note: + This verifies that LLDB is correctly building the method overrides table. + If this table is not built correctly then calls to overridden methods in + derived classes may generate references to non-existant vtable entries, + as the compiler treats the overridden method as a totally new virtual + method definition. + + +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class ExprCommandCallOverriddenMethod(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break for main.c. + self.line = line_number('main.cpp', '// Set breakpoint here') + + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765") + def test(self): + """Test calls to overridden methods in derived classes.""" + self.build() + + # Set breakpoint in main and run exe + self.runCmd("file " + self.getBuildArtifact("a.out"), + CURRENT_EXECUTABLE_SET) + lldbutil.run_break_set_by_file_and_line( + self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True) + + self.runCmd("run", RUN_SUCCEEDED) + + # Test call to method in base class (this should always work as the base + # class method is never an override). + self.expect("expr b->foo()") + + # Test call to overridden method in derived class (this will fail if the + # overrides table is not correctly set up, as Derived::foo will be assigned + # a vtable entry that does not exist in the compiled program). + self.expect("expr d.foo()") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/main.cpp @@ -0,0 +1,16 @@ +class Base { +public: + virtual ~Base() {} + virtual void foo() {} +}; + +class Derived : public Base { +public: + virtual void foo() {} +}; + +int main() { + Derived d; + Base *b = &d; + return 0; // Set breakpoint here +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-restarts/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-restarts/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-restarts/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +C_SOURCES := lotta-signals.c + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-restarts/TestCallThatRestarts.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-restarts/TestCallThatRestarts.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-restarts/TestCallThatRestarts.py @@ -0,0 +1,166 @@ +""" +Test calling a function that hits a signal set to auto-restart, make sure the call completes. +""" + +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__) + NO_DEBUG_INFO_TESTCASE = True + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + self.main_source = "lotta-signals.c" + 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 + @expectedFlakeyAndroid(bugnumber="llvm.org/pr19246") + def test(self): + """Test calling function that hits a signal and restarts.""" + self.build() + self.call_function() + + 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.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") + + def call_function(self): + (target, process, self.thread, bkpt) = lldbutil.run_to_source_breakpoint(self, + 'Stop here in main.', self.main_source_spec) + + # 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(), "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.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 + options.SetUnwindOnError(True) + + frame = self.thread.GetFrameAtIndex(0) + # 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()) + 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) + options.SetIgnoreBreakpoints(True) + options.SetUnwindOnError(True) + + value = frame.EvaluateExpression( + "call_me (%d)" % + (num_sigchld), options) + + 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(), + "Set SIGCHLD to pass, no-stop, notify") + + value = frame.EvaluateExpression( + "call_me (%d)" % + (num_sigchld), options) + + 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: + options.SetUnwindOnError(False) + value = frame.EvaluateExpression( + "call_me (%d)" % + (num_sigchld), options) + + 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(), + "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.") + + frame = self.thread.GetFrameAtIndex(0) + self.assertTrue( + frame.GetPC() == self.orig_frame_pc, + "Continuing returned to the place we started.") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-restarts/lotta-signals.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-restarts/lotta-signals.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-restarts/lotta-signals.c @@ -0,0 +1,61 @@ +#include +#include +#include + +static int sigchld_no; +static int nosig_no; +static int weird_value; + +void +sigchld_handler (int signo) +{ + sigchld_no++; + printf ("Got sigchld %d.\n", sigchld_no); +} + +int +call_me (int some_value) +{ + int ret_val = 0; + int i; + for (i = 0; i < some_value; i++) + { + int result = 0; + if (i%2 == 0) + result = kill (getpid(), SIGCHLD); + else + sigchld_no++; + + usleep(1000); + if (result == 0) + ret_val++; + } + usleep (10000); + return ret_val; +} + +int +call_me_nosig (int some_value) +{ + int ret_val = 0; + int i; + for (i = 0; i < some_value; i++) + weird_value += i % 4; + + nosig_no += some_value; + return some_value; +} + +int +main () +{ + int ret_val; + signal (SIGCHLD, sigchld_handler); + + ret_val = call_me (2); // Stop here in main. + + ret_val = call_me_nosig (10); + + return 0; + +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-throws/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-throws/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-throws/Makefile @@ -0,0 +1,6 @@ +LEVEL = ../../make + +OBJC_SOURCES := call-throws.m + +include $(LEVEL)/Makefile.rules +LDFLAGS += -framework Foundation Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-throws/TestCallThatThrows.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-throws/TestCallThatThrows.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-throws/TestCallThatThrows.py @@ -0,0 +1,104 @@ +""" +Test calling a function that throws an ObjC exception, make sure that it doesn't propagate the exception. +""" + +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__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + self.main_source = "call-throws.m" + self.main_source_spec = lldb.SBFileSpec(self.main_source) + + @skipUnlessDarwin + def test(self): + """Test calling a function that throws and ObjC exception.""" + self.build() + self.call_function() + + 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") + + def call_function(self): + """Test calling function that throws.""" + (target, process, self.thread, bkpt) = lldbutil.run_to_source_breakpoint(self, + 'I am about to throw.', self.main_source_spec) + + 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 + self.orig_frame_pc = frame.GetPC() + + 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) + options.SetIgnoreBreakpoints(True) + options.SetUnwindOnError(True) + + value = frame.EvaluateExpression("[my_class callMeIThrow]", options) + + 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) + self.assertTrue(exception_bkpt.GetNumLocations() > 0) + + options.SetIgnoreBreakpoints(True) + options.SetUnwindOnError(True) + + value = frame.EvaluateExpression("[my_class callMeIThrow]", options) + + 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: + options.SetTrapExceptions(False) + 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 + options.SetUnwindOnError(False) + value = frame.EvaluateExpression("[my_class callMeIThrow]", options) + + self.assertTrue( + value.IsValid() and value.GetError().Success() == False) + self.check_after_call() Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-throws/call-throws.m =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-throws/call-throws.m +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/call-throws/call-throws.m @@ -0,0 +1,47 @@ +#import + +@interface MyClass : NSObject +{ +} +- (int) callMeIThrow; +- (int) iCatchMyself; +@end + +@implementation MyClass +- (int) callMeIThrow +{ + NSException *e = [NSException + exceptionWithName:@"JustForTheHeckOfItException" + reason:@"I felt like it" + userInfo:nil]; + @throw e; + return 56; +} + +- (int) iCatchMyself +{ + int return_value = 55; + @try + { + return_value = [self callMeIThrow]; + } + @catch (NSException *e) + { + return_value = 57; + } + return return_value; +} +@end + +int +main () +{ + int return_value; + MyClass *my_class = [[MyClass alloc] init]; + + NSLog (@"I am about to throw."); + + return_value = [my_class iCatchMyself]; + + return return_value; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/cast_int_to_anonymous_enum/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/cast_int_to_anonymous_enum/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/cast_int_to_anonymous_enum/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/cast_int_to_anonymous_enum/TestCastIntToAnonymousEnum.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/cast_int_to_anonymous_enum/TestCastIntToAnonymousEnum.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/cast_int_to_anonymous_enum/TestCastIntToAnonymousEnum.py @@ -0,0 +1,22 @@ +""" +Test Expression Parser regression text to ensure that we handle anonymous +enums importing correctly. +""" + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestCastIntToAnonymousEnum(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def test_cast_int_to_anonymous_enum(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, '// break here', + lldb.SBFileSpec("main.cpp", False)) + + self.expect("expr (flow_e)0", substrs=['(flow_e) $0 = A']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/cast_int_to_anonymous_enum/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/cast_int_to_anonymous_enum/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/cast_int_to_anonymous_enum/main.cpp @@ -0,0 +1,9 @@ +enum flow_e { + A=0, +}; + +int main() { + flow_e f; + + return 0; // break here +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/char/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/char/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/char/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/char/TestExprsChar.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/char/TestExprsChar.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/char/TestExprsChar.py @@ -0,0 +1,67 @@ +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__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + self.main_source = "main.cpp" + self.main_source_spec = lldb.SBFileSpec(self.main_source) + + def do_test(self, dictionary=None): + """These basic expression commands should work as expected.""" + self.build(dictionary=dictionary) + + (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, + '// Break here', self.main_source_spec) + frame = thread.GetFrameAtIndex(0) + + value = frame.EvaluateExpression("foo(c)") + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertEqual(value.GetValueAsSigned(0), 1) + + value = frame.EvaluateExpression("foo(sc)") + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertEqual(value.GetValueAsSigned(0), 2) + + value = frame.EvaluateExpression("foo(uc)") + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertEqual(value.GetValueAsSigned(0), 3) + + def test_default_char(self): + self.do_test() + + @expectedFailureAll( + archs=[ + "arm", + "aarch64", + "powerpc64le", + "s390x"], + bugnumber="llvm.org/pr23069") + def test_signed_char(self): + self.do_test(dictionary={'CFLAGS_EXTRAS': '-fsigned-char'}) + + @expectedFailureAll( + archs=[ + "i[3-6]86", + "x86_64", + "arm64", + 'armv7', + 'armv7k'], + bugnumber="llvm.org/pr23069, ") + @expectedFailureAll(triple='mips*', bugnumber="llvm.org/pr23069") + def test_unsigned_char(self): + self.do_test(dictionary={'CFLAGS_EXTRAS': '-funsigned-char'}) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/char/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/char/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/char/main.cpp @@ -0,0 +1,10 @@ +int foo(char c) { return 1; } +int foo(signed char c) { return 2; } +int foo(unsigned char c) { return 3; } + +int main() { + char c = 0; + signed char sc = 0; + unsigned char uc = 0; + return 0; // Break here +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/class_template_specialization_empty_pack/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/class_template_specialization_empty_pack/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/class_template_specialization_empty_pack/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/class_template_specialization_empty_pack/TestClassTemplateSpecializationParametersHandling.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/class_template_specialization_empty_pack/TestClassTemplateSpecializationParametersHandling.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/class_template_specialization_empty_pack/TestClassTemplateSpecializationParametersHandling.py @@ -0,0 +1,23 @@ +""" +Test Expression Parser code gen for ClassTemplateSpecializationDecl to insure +that we generate a TemplateTypeParmDecl in the TemplateParameterList for empty +variadic packs. +""" + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestClassTemplateSpecializationParametersHandling(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def test_class_template_specialization(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, '// break here', + lldb.SBFileSpec("main.cpp", False)) + + self.expect("expr -u 0 -- b.foo()", substrs=['$0 = 1']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/class_template_specialization_empty_pack/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/class_template_specialization_empty_pack/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/class_template_specialization_empty_pack/main.cpp @@ -0,0 +1,9 @@ +template +struct A { + int foo() { return 1;} +}; + +int main() { + A b; + return b.foo(); // break here +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash-incomplete-record/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash-incomplete-record/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash-incomplete-record/Makefile @@ -0,0 +1,3 @@ +LEVEL = ../../make +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash-incomplete-record/TestCompletionCrashIncompleteRecord.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash-incomplete-record/TestCompletionCrashIncompleteRecord.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash-incomplete-record/TestCompletionCrashIncompleteRecord.py @@ -0,0 +1,4 @@ +from lldbsuite.test import lldbinline +from lldbsuite.test import decorators + +lldbinline.MakeInlineTest(__file__, globals(), [decorators.skipIf(bugnumber="rdar://53756116")]) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash-incomplete-record/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash-incomplete-record/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash-incomplete-record/main.cpp @@ -0,0 +1,11 @@ +int i; +struct F { + int &r; + F() : r(i) {} +}; +template struct unique_ptr { + F i; + unique_ptr() : i() {//%self.dbg.GetCommandInterpreter().HandleCompletion("e ", len("e "), 0, -1, lldb.SBStringList()) +} +}; +int main() {unique_ptr u; } Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash-lambda/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash-lambda/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash-lambda/Makefile @@ -0,0 +1,3 @@ +LEVEL = ../../make +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash1/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash1/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash1/Makefile @@ -0,0 +1,3 @@ +LEVEL = ../../make +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash1/TestCompletionCrash1.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash1/TestCompletionCrash1.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash1/TestCompletionCrash1.py @@ -0,0 +1,4 @@ +from lldbsuite.test import lldbinline +from lldbsuite.test import decorators + +lldbinline.MakeInlineTest(__file__, globals(), [decorators.skipIf(bugnumber="rdar://53659341")]) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash1/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash1/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash1/main.cpp @@ -0,0 +1,12 @@ +namespace std { +struct a { + a() {} + a(a &&); +}; +template struct au { + a ay; + ~au() { //%self.dbg.GetCommandInterpreter().HandleCompletion("e ", len("e "), 0, -1, lldb.SBStringList()) + } +}; +} +int main() { std::au{}; } Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash2/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash2/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash2/Makefile @@ -0,0 +1,3 @@ +LEVEL = ../../make +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash2/TestCompletionCrash2.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash2/TestCompletionCrash2.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash2/TestCompletionCrash2.py @@ -0,0 +1,4 @@ +from lldbsuite.test import lldbinline +from lldbsuite.test import decorators + +lldbinline.MakeInlineTest(__file__, globals(), [decorators.skipIf(bugnumber="rdar://53754063")]) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash2/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash2/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-crash2/main.cpp @@ -0,0 +1,11 @@ +namespace n { +template class a {}; +template struct shared_ptr { + template + static void make_shared() { //%self.dbg.GetCommandInterpreter().HandleCompletion("e ", len("e "), 0, -1, lldb.SBStringList()) + typedef a c; + c d; + } +}; +} // namespace n +int main() { n::shared_ptr::make_shared(); } Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-in-lambda-and-unnnamed-class/TestCompletionInLambdaAndUnnamedClass.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-in-lambda-and-unnnamed-class/TestCompletionInLambdaAndUnnamedClass.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-in-lambda-and-unnnamed-class/TestCompletionInLambdaAndUnnamedClass.py @@ -0,0 +1,4 @@ +from lldbsuite.test import lldbinline +from lldbsuite.test import decorators + +lldbinline.MakeInlineTest(__file__, globals(),) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-in-lambda-and-unnnamed-class/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-in-lambda-and-unnnamed-class/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion-in-lambda-and-unnnamed-class/main.cpp @@ -0,0 +1,11 @@ +int main() { + []() + { //%self.dbg.GetCommandInterpreter().HandleCompletion("e ", len("e "), 0, -1, lldb.SBStringList()) + } + (); + struct { + void f() + { //%self.dbg.GetCommandInterpreter().HandleCompletion("e ", len("e "), 0, -1, lldb.SBStringList()) + } + } A; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion/.categories =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion/.categories +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion/.categories @@ -0,0 +1 @@ +cmdline Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp other.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion/TestExprCompletion.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion/TestExprCompletion.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion/TestExprCompletion.py @@ -0,0 +1,255 @@ +""" +Test the lldb command line completion mechanism for the 'expr' command. +""" + +from __future__ import print_function + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbplatform +from lldbsuite.test import lldbutil + +class CommandLineExprCompletionTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + NO_DEBUG_INFO_TESTCASE = True + + def test_expr_completion(self): + self.build() + self.main_source = "main.cpp" + self.main_source_spec = lldb.SBFileSpec(self.main_source) + self.dbg.CreateTarget(self.getBuildArtifact("a.out")) + + # Try the completion before we have a context to complete on. + self.assume_no_completions('expr some_expr') + self.assume_no_completions('expr ') + self.assume_no_completions('expr f') + + + (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, + '// Break here', self.main_source_spec) + + # Completing member functions + self.complete_exactly('expr some_expr.FooNoArgs', + 'expr some_expr.FooNoArgsBar()') + self.complete_exactly('expr some_expr.FooWithArgs', + 'expr some_expr.FooWithArgsBar(') + self.complete_exactly('expr some_expr.FooWithMultipleArgs', + 'expr some_expr.FooWithMultipleArgsBar(') + self.complete_exactly('expr some_expr.FooUnderscore', + 'expr some_expr.FooUnderscoreBar_()') + self.complete_exactly('expr some_expr.FooNumbers', + 'expr some_expr.FooNumbersBar1()') + self.complete_exactly('expr some_expr.StaticMemberMethod', + 'expr some_expr.StaticMemberMethodBar()') + + # Completing static functions + self.complete_exactly('expr Expr::StaticMemberMethod', + 'expr Expr::StaticMemberMethodBar()') + + # Completing member variables + self.complete_exactly('expr some_expr.MemberVariab', + 'expr some_expr.MemberVariableBar') + + # Multiple completions + self.completions_contain('expr some_expr.', + ['some_expr.FooNumbersBar1()', + 'some_expr.FooUnderscoreBar_()', + 'some_expr.FooWithArgsBar(', + 'some_expr.MemberVariableBar']) + + self.completions_contain('expr some_expr.Foo', + ['some_expr.FooNumbersBar1()', + 'some_expr.FooUnderscoreBar_()', + 'some_expr.FooWithArgsBar(']) + + self.completions_contain('expr ', + ['static_cast', + 'reinterpret_cast', + 'dynamic_cast']) + + self.completions_contain('expr 1 + ', + ['static_cast', + 'reinterpret_cast', + 'dynamic_cast']) + + # Completion expr without spaces + # This is a bit awkward looking for the user, but that's how + # the completion API works at the moment. + self.completions_contain('expr 1+', + ['1+some_expr', "1+static_cast"]) + + # Test with spaces + self.complete_exactly('expr some_expr .FooNoArgs', + 'expr some_expr .FooNoArgsBar()') + self.complete_exactly('expr some_expr .FooNoArgs', + 'expr some_expr .FooNoArgsBar()') + self.complete_exactly('expr some_expr .FooNoArgs', + 'expr some_expr .FooNoArgsBar()') + self.complete_exactly('expr some_expr. FooNoArgs', + 'expr some_expr. FooNoArgsBar()') + self.complete_exactly('expr some_expr . FooNoArgs', + 'expr some_expr . FooNoArgsBar()') + self.complete_exactly('expr Expr :: StaticMemberMethod', + 'expr Expr :: StaticMemberMethodBar()') + self.complete_exactly('expr Expr ::StaticMemberMethod', + 'expr Expr ::StaticMemberMethodBar()') + self.complete_exactly('expr Expr:: StaticMemberMethod', + 'expr Expr:: StaticMemberMethodBar()') + + # Test that string literals don't break our parsing logic. + self.complete_exactly('expr const char *cstr = "some_e"; char c = *cst', + 'expr const char *cstr = "some_e"; char c = *cstr') + self.complete_exactly('expr const char *cstr = "some_e" ; char c = *cst', + 'expr const char *cstr = "some_e" ; char c = *cstr') + # Requesting completions inside an incomplete string doesn't provide any + # completions. + self.complete_exactly('expr const char *cstr = "some_e', + 'expr const char *cstr = "some_e') + + # Completing inside double dash should do nothing + self.assume_no_completions('expr -i0 -- some_expr.', 10) + self.assume_no_completions('expr -i0 -- some_expr.', 11) + + # Test with expr arguments + self.complete_exactly('expr -i0 -- some_expr .FooNoArgs', + 'expr -i0 -- some_expr .FooNoArgsBar()') + self.complete_exactly('expr -i0 -- some_expr .FooNoArgs', + 'expr -i0 -- some_expr .FooNoArgsBar()') + + # Addrof and deref + self.complete_exactly('expr (*(&some_expr)).FooNoArgs', + 'expr (*(&some_expr)).FooNoArgsBar()') + self.complete_exactly('expr (*(&some_expr)) .FooNoArgs', + 'expr (*(&some_expr)) .FooNoArgsBar()') + self.complete_exactly('expr (* (&some_expr)) .FooNoArgs', + 'expr (* (&some_expr)) .FooNoArgsBar()') + self.complete_exactly('expr (* (& some_expr)) .FooNoArgs', + 'expr (* (& some_expr)) .FooNoArgsBar()') + + # Addrof and deref (part 2) + self.complete_exactly('expr (&some_expr)->FooNoArgs', + 'expr (&some_expr)->FooNoArgsBar()') + self.complete_exactly('expr (&some_expr) ->FooNoArgs', + 'expr (&some_expr) ->FooNoArgsBar()') + self.complete_exactly('expr (&some_expr) -> FooNoArgs', + 'expr (&some_expr) -> FooNoArgsBar()') + self.complete_exactly('expr (&some_expr)-> FooNoArgs', + 'expr (&some_expr)-> FooNoArgsBar()') + + # Builtin arg + self.complete_exactly('expr static_ca', + 'expr static_cast') + + # From other files + self.complete_exactly('expr fwd_decl_ptr->Hidden', + 'expr fwd_decl_ptr->HiddenMember') + + + # Types + self.complete_exactly('expr LongClassNa', + 'expr LongClassName') + self.complete_exactly('expr LongNamespaceName::NestedCla', + 'expr LongNamespaceName::NestedClass') + + # Namespaces + self.complete_exactly('expr LongNamespaceNa', + 'expr LongNamespaceName::') + + # Multiple arguments + self.complete_exactly('expr &some_expr + &some_e', + 'expr &some_expr + &some_expr') + self.complete_exactly('expr SomeLongVarNameWithCapitals + SomeLongVarName', + 'expr SomeLongVarNameWithCapitals + SomeLongVarNameWithCapitals') + self.complete_exactly('expr SomeIntVar + SomeIntV', + 'expr SomeIntVar + SomeIntVar') + + # Multiple statements + self.complete_exactly('expr long LocalVariable = 0; LocalVaria', + 'expr long LocalVariable = 0; LocalVariable') + + # Custom Decls + self.complete_exactly('expr auto l = [](int LeftHandSide, int bx){ return LeftHandS', + 'expr auto l = [](int LeftHandSide, int bx){ return LeftHandSide') + self.complete_exactly('expr struct LocalStruct { long MemberName; } ; LocalStruct S; S.Mem', + 'expr struct LocalStruct { long MemberName; } ; LocalStruct S; S.MemberName') + + # Completing function call arguments + self.complete_exactly('expr some_expr.FooWithArgsBar(some_exp', + 'expr some_expr.FooWithArgsBar(some_expr') + self.complete_exactly('expr some_expr.FooWithArgsBar(SomeIntV', + 'expr some_expr.FooWithArgsBar(SomeIntVar') + self.complete_exactly('expr some_expr.FooWithMultipleArgsBar(SomeIntVar, SomeIntVa', + 'expr some_expr.FooWithMultipleArgsBar(SomeIntVar, SomeIntVar') + + # Function return values + self.complete_exactly('expr some_expr.Self().FooNoArgs', + 'expr some_expr.Self().FooNoArgsBar()') + self.complete_exactly('expr some_expr.Self() .FooNoArgs', + 'expr some_expr.Self() .FooNoArgsBar()') + self.complete_exactly('expr some_expr.Self(). FooNoArgs', + 'expr some_expr.Self(). FooNoArgsBar()') + + def test_expr_completion_with_descriptions(self): + self.build() + self.main_source = "main.cpp" + self.main_source_spec = lldb.SBFileSpec(self.main_source) + self.dbg.CreateTarget(self.getBuildArtifact("a.out")) + + (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, + '// Break here', self.main_source_spec) + + self.check_completion_with_desc("expr ", [ + # VarDecls have their type as description. + ["some_expr", "Expr &"], + # builtin types have no description. + ["int", ""], + ["float", ""] + ]) + self.check_completion_with_desc("expr some_expr.", [ + # Functions have their signature as description. + ["some_expr.Self()", "Expr &Self()"], + ["some_expr.operator=(", "inline Expr &operator=(const Expr &)"], + ["some_expr.FooNumbersBar1()", "int FooNumbersBar1()"], + ["some_expr.StaticMemberMethodBar()", "static int StaticMemberMethodBar()"], + ["some_expr.FooWithArgsBar(", "int FooWithArgsBar(int)"], + ["some_expr.FooNoArgsBar()", "int FooNoArgsBar()"], + ["some_expr.FooUnderscoreBar_()", "int FooUnderscoreBar_()"], + ["some_expr.FooWithMultipleArgsBar(", "int FooWithMultipleArgsBar(int, int)"], + ["some_expr.~Expr()", "inline ~Expr()"], + # FieldDecls have their type as description. + ["some_expr.MemberVariableBar", "int"], + ]) + + def assume_no_completions(self, str_input, cursor_pos = None): + interp = self.dbg.GetCommandInterpreter() + match_strings = lldb.SBStringList() + if cursor_pos is None: + cursor_pos = len(str_input) + num_matches = interp.HandleCompletion(str_input, cursor_pos, 0, -1, match_strings) + + available_completions = [] + for m in match_strings: + available_completions.append(m) + + self.assertEquals(num_matches, 0, "Got matches, but didn't expect any: " + str(available_completions)) + + def completions_contain(self, str_input, items): + interp = self.dbg.GetCommandInterpreter() + match_strings = lldb.SBStringList() + num_matches = interp.HandleCompletion(str_input, len(str_input), 0, -1, match_strings) + common_match = match_strings.GetStringAtIndex(0) + + for item in items: + found = False + for m in match_strings: + if m == item: + found = True + if not found: + # Transform match_strings to a python list with strings + available_completions = [] + for m in match_strings: + available_completions.append(m) + self.assertTrue(found, "Couldn't find completion " + item + " in completions " + str(available_completions)) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion/main.cpp @@ -0,0 +1,35 @@ +namespace LongNamespaceName { class NestedClass { long m; }; } + +// Defined in other.cpp, we only have a forward declaration here. +struct ForwardDecl; +extern ForwardDecl fwd_decl; + +class LongClassName { long i ; }; + +class Expr { +public: + int FooNoArgsBar() { return 1; } + int FooWithArgsBar(int i) { return i; } + int FooWithMultipleArgsBar(int i, int j) { return i + j; } + int FooUnderscoreBar_() { return 4; } + int FooNumbersBar1() { return 8; } + int MemberVariableBar = 0; + Expr &Self() { return *this; } + static int StaticMemberMethodBar() { return 82; } +}; + +int main() +{ + LongClassName a; + LongNamespaceName::NestedClass NestedFoo; + long SomeLongVarNameWithCapitals = 44; + int SomeIntVar = 33; + Expr some_expr; + some_expr.FooNoArgsBar(); + some_expr.FooWithArgsBar(1); + some_expr.FooUnderscoreBar_(); + some_expr.FooNumbersBar1(); + Expr::StaticMemberMethodBar(); + ForwardDecl *fwd_decl_ptr = &fwd_decl; + return 0; // Break here +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion/other.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion/other.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/completion/other.cpp @@ -0,0 +1,4 @@ +struct ForwardDecl { + long HiddenMemberName; +}; +ForwardDecl fwd_decl; Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/context-object-objc/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/context-object-objc/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/context-object-objc/Makefile @@ -0,0 +1,6 @@ +LEVEL = ../../make + +OBJC_SOURCES := main.m + +include $(LEVEL)/Makefile.rules +LDFLAGS += -framework Foundation Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/context-object-objc/TestContextObjectObjc.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/context-object-objc/TestContextObjectObjc.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/context-object-objc/TestContextObjectObjc.py @@ -0,0 +1,78 @@ +""" +Tests expression evaluation in context of an objc class. +""" + +import lldb +import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * + +class ContextObjectObjcTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + def test_context_object_objc(self): + """Tests expression evaluation in context of an objc class.""" + self.build() + + (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, '// Break here', self.main_source_spec) + frame = thread.GetFrameAtIndex(0) + + # + # Test objc class variable + # + + obj_val = frame.FindVariable("objcClass") + self.assertTrue(obj_val.IsValid()) + obj_val = obj_val.Dereference() + self.assertTrue(obj_val.IsValid()) + + # Test an empty expression evaluation + value = obj_val.EvaluateExpression("") + self.assertFalse(value.IsValid()) + self.assertFalse(value.GetError().Success()) + + # Test retrieving of a field (not a local with the same name) + value = obj_val.EvaluateExpression("field") + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertEqual(value.GetValueAsSigned(), 1111) + + # Test if the self pointer is properly evaluated + + # Test retrieving of an objcClass's property through the self pointer + value = obj_val.EvaluateExpression("self.property") + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertEqual(value.GetValueAsSigned(), 2222) + + # Test objcClass's methods evaluation through the self pointer + value = obj_val.EvaluateExpression("[self method]") + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertEqual(value.GetValueAsSigned(), 3333) + + # Test if we can use a computation result reference object correctly + + obj_val = frame.EvaluateExpression("[ObjcClass createNew]") + self.assertTrue(obj_val.IsValid()) + obj_val = obj_val.Dereference() + self.assertTrue(obj_val.IsValid()) + + # Test an expression evaluation on it + value = obj_val.EvaluateExpression("1") + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + + # Test retrieving of a field on it + value = obj_val.EvaluateExpression("field") + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertEqual(value.GetValueAsSigned(), 1111) + + def setUp(self): + TestBase.setUp(self) + + self.main_source = "main.m" + self.main_source_spec = lldb.SBFileSpec(self.main_source) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/context-object-objc/main.m =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/context-object-objc/main.m +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/context-object-objc/main.m @@ -0,0 +1,47 @@ +#import + +@interface ObjcClass : NSObject { + int field; +} + +@property int property; + ++(ObjcClass*)createNew; + +-(id)init; + +-(int)method; + +@end + +@implementation ObjcClass + ++(ObjcClass*)createNew { + return [ObjcClass new]; +} + +-(id)init { + self = [super init]; + if (self) { + field = 1111; + _property = 2222; + } + return self; +} + +-(int)method { + return 3333; +} + +@end + +int main() +{ + @autoreleasepool { + ObjcClass* objcClass = [ObjcClass new]; + + int field = 4444; + + return 0; // Break here + } +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/context-object/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/context-object/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/context-object/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/context-object/TestContextObject.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/context-object/TestContextObject.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/context-object/TestContextObject.py @@ -0,0 +1,145 @@ +""" +Tests expression evaluation in context of an object. +""" + +import lldb +import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.lldbtest import * + +class ContextObjectTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def test_context_object(self): + """Tests expression evaluation in context of an object.""" + self.build() + + (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, '// Break here', self.main_source_spec) + frame = thread.GetFrameAtIndex(0) + + # + # Test C++ struct variable + # + + obj_val = frame.FindVariable("cpp_struct") + self.assertTrue(obj_val.IsValid()) + + # Test an empty expression evaluation + value = obj_val.EvaluateExpression("") + self.assertFalse(value.IsValid()) + self.assertFalse(value.GetError().Success()) + + # Test retrieveing of a field (not a local with the same name) + value = obj_val.EvaluateExpression("field") + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertEqual(value.GetValueAsSigned(), 1111) + + # Test functions evaluation + value = obj_val.EvaluateExpression("function()") + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertEqual(value.GetValueAsSigned(), 2222) + + # Test that we retrieve the right global + value = obj_val.EvaluateExpression("global.field") + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertEqual(value.GetValueAsSigned(), 1111) + + # + # Test C++ union variable + # + + obj_val = frame.FindVariable("cpp_union") + self.assertTrue(obj_val.IsValid()) + + # Test retrieveing of a field + value = obj_val.EvaluateExpression("field_int") + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertEqual(value.GetValueAsSigned(), 5555) + + # + # Test C++ scalar + # + + obj_val = frame.FindVariable("cpp_scalar") + self.assertTrue(obj_val.IsValid()) + + # Test an expression evaluation + value = obj_val.EvaluateExpression("1") + self.assertFalse(value.IsValid()) + self.assertFalse(value.GetError().Success()) + + # + # Test C++ array + # + + obj_val = frame.FindVariable("cpp_array") + self.assertTrue(obj_val.IsValid()) + + # Test an expression evaluation + value = obj_val.EvaluateExpression("1") + self.assertFalse(value.IsValid()) + self.assertFalse(value.GetError().Success()) + + # Test retrieveing of an element's field + value = obj_val.GetValueForExpressionPath("[7]").EvaluateExpression("field") + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertEqual(value.GetValueAsSigned(), 1111) + + # + # Test C++ pointer + # + + obj_val = frame.FindVariable("cpp_pointer") + self.assertTrue(obj_val.IsValid()) + + # Test an expression evaluation + value = obj_val.EvaluateExpression("1") + self.assertFalse(value.IsValid()) + self.assertFalse(value.GetError().Success()) + + # Test retrieveing of a dereferenced object's field + value = obj_val.Dereference().EvaluateExpression("field") + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertEqual(value.GetValueAsSigned(), 1111) + + # + # Test C++ computation result + # + + obj_val = frame.EvaluateExpression("cpp_namespace::GetCppStruct()") + self.assertTrue(obj_val.IsValid()) + + # Test an expression evaluation + value = obj_val.EvaluateExpression("1") + self.assertTrue(value.IsValid()) + self.assertFalse(value.GetError().Success()) + + # + # Test C++ computation result located in debuggee memory + # + + obj_val = frame.EvaluateExpression("cpp_namespace::GetCppStructPtr()") + self.assertTrue(obj_val.IsValid()) + + # Test an expression evaluation + value = obj_val.EvaluateExpression("1") + self.assertFalse(value.IsValid()) + self.assertFalse(value.GetError().Success()) + + # Test retrieveing of a dereferenced object's field + value = obj_val.Dereference().EvaluateExpression("field") + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertEqual(value.GetValueAsSigned(), 1111) + + def setUp(self): + TestBase.setUp(self) + + self.main_source = "main.cpp" + self.main_source_spec = lldb.SBFileSpec(self.main_source) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/context-object/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/context-object/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/context-object/main.cpp @@ -0,0 +1,46 @@ +namespace cpp_namespace { + struct CppStruct { + int field = 1111; + + int function() { + return 2222; + } + }; + + union CppUnion { + char field_char; + short field_short; + int field_int; + }; + + CppStruct GetCppStruct() { + return CppStruct(); + } + + CppStruct global; + + CppStruct *GetCppStructPtr() { + return &global; + } +} + +int global = 3333; + +int main() +{ + cpp_namespace::CppStruct cpp_struct = cpp_namespace::GetCppStruct(); + cpp_struct.function(); + + int field = 4444; + + cpp_namespace::CppUnion cpp_union; + cpp_union.field_int = 5555; + + int cpp_scalar = 6666; + + cpp_namespace::CppStruct cpp_array[16]; + + cpp_namespace::CppStruct *cpp_pointer = cpp_namespace::GetCppStructPtr(); + + return 0; // Break here +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/dollar-in-variable/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/dollar-in-variable/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/dollar-in-variable/Makefile @@ -0,0 +1,3 @@ +LEVEL = ../../make +C_SOURCES := main.c +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/dollar-in-variable/TestDollarInVariable.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/dollar-in-variable/TestDollarInVariable.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/dollar-in-variable/TestDollarInVariable.py @@ -0,0 +1,5 @@ +from lldbsuite.test import lldbinline +from lldbsuite.test import decorators + +lldbinline.MakeInlineTest(__file__, globals(), + [lldbinline.expectedFailureAll(oslist=["windows"])]) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/dollar-in-variable/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/dollar-in-variable/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/dollar-in-variable/main.c @@ -0,0 +1,21 @@ +// Make sure we correctly handle $ in variable names. + +int main() { + // Some variables that might conflict with our variables below. + int __lldb_expr_result = 2; + int $$foo = 1; + int R0 = 2; + + // Some variables with dollar signs that should work (and shadow + // any built-in LLDB variables). + int $__lldb_expr_result = 11; + int $foo = 12; + int $R0 = 13; + int $0 = 14; + + //%self.expect("expr $__lldb_expr_result", substrs=['(int) $0 = 11']) + //%self.expect("expr $foo", substrs=['(int)', ' = 12']) + //%self.expect("expr $R0", substrs=['(int)', ' = 13']) + //%self.expect("expr int $foo = 123", error=True, substrs=["declaration conflicts"]) + return 0; //%self.expect("expr $0", substrs=['(int)', ' = 14']) +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/dont_allow_jit/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/dont_allow_jit/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/dont_allow_jit/Makefile @@ -0,0 +1,6 @@ +LEVEL = ../../make + +C_SOURCES := main.c +CFLAGS_EXTRAS += -std=c99 + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/dont_allow_jit/TestAllowJIT.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/dont_allow_jit/TestAllowJIT.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/dont_allow_jit/TestAllowJIT.py @@ -0,0 +1,87 @@ +""" +Test that --allow-jit=false does disallow JITting: +""" + +from __future__ import print_function + + +import lldb +import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.lldbtest import * +from lldbsuite.test.decorators import * + +class TestAllowJIT(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # If your test case doesn't stress debug info, the + # set this to true. That way it won't be run once for + # each debug info format. + NO_DEBUG_INFO_TESTCASE = True + + def test_allow_jit_expr_command(self): + """Test the --allow-jit command line flag""" + self.build() + self.main_source_file = lldb.SBFileSpec("main.c") + self.expr_cmd_test() + + def test_allow_jit_options(self): + """Test the SetAllowJIT SBExpressionOption setting""" + self.build() + self.main_source_file = lldb.SBFileSpec("main.c") + self.expr_options_test() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + def expr_cmd_test(self): + (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, + "Set a breakpoint here", self.main_source_file) + + frame = thread.GetFrameAtIndex(0) + + # First make sure we can call the function with + interp = self.dbg.GetCommandInterpreter() + self.expect("expr --allow-jit 1 -- call_me(10)", + substrs = ["(int) $", "= 18"]) + # Now make sure it fails with the "can't IR interpret message" if allow-jit is false: + self.expect("expr --allow-jit 0 -- call_me(10)", + error=True, + substrs = ["Can't run the expression locally"]) + + def expr_options_test(self): + (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, + "Set a breakpoint here", self.main_source_file) + + frame = thread.GetFrameAtIndex(0) + + # First make sure we can call the function with the default option set. + options = lldb.SBExpressionOptions() + # Check that the default is to allow JIT: + self.assertEqual(options.GetAllowJIT(), True, "Default is true") + + # Now use the options: + result = frame.EvaluateExpression("call_me(10)", options) + self.assertTrue(result.GetError().Success(), "expression succeeded") + self.assertEqual(result.GetValueAsSigned(), 18, "got the right value.") + + # Now disallow JIT and make sure it fails: + options.SetAllowJIT(False) + # Check that we got the right value: + self.assertEqual(options.GetAllowJIT(), False, "Got False after setting to False") + + # Again use it and ensure we fail: + result = frame.EvaluateExpression("call_me(10)", options) + self.assertTrue(result.GetError().Fail(), "expression failed with no JIT") + self.assertTrue("Can't run the expression locally" in result.GetError().GetCString(), "Got right error") + + # Finally set the allow JIT value back to true and make sure that works: + options.SetAllowJIT(True) + self.assertEqual(options.GetAllowJIT(), True, "Set back to True correctly") + + # And again, make sure this works: + result = frame.EvaluateExpression("call_me(10)", options) + self.assertTrue(result.GetError().Success(), "expression succeeded") + self.assertEqual(result.GetValueAsSigned(), 18, "got the right value.") + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/dont_allow_jit/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/dont_allow_jit/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/dont_allow_jit/main.c @@ -0,0 +1,15 @@ +#include + +int +call_me(int input) +{ + return printf("I was called: %d.\n", input); +} + +int +main() +{ + int test_var = 10; + printf ("Set a breakpoint here: %d.\n", test_var); + return call_me(100); +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/entry-bp/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/entry-bp/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/entry-bp/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/entry-bp/TestExprEntryBP.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/entry-bp/TestExprEntryBP.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/entry-bp/TestExprEntryBP.py @@ -0,0 +1,34 @@ +""" +Tests expressions evaluation when the breakpoint on module's entry is set. +""" + +import lldb +import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.lldbtest import * + +class ExprEntryBPTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + NO_DEBUG_INFO_TESTCASE = True + + def test_expr_entry_bp(self): + """Tests expressions evaluation when the breakpoint on module's entry is set.""" + self.build() + self.main_source_file = lldb.SBFileSpec("main.c") + + (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, "Set a breakpoint here", self.main_source_file) + + self.assertEqual(1, bkpt.GetNumLocations()) + entry = bkpt.GetLocationAtIndex(0).GetAddress().GetModule().GetObjectFileEntryPointAddress() + self.assertTrue(entry.IsValid(), "Can't get a module entry point") + + entry_bp = target.BreakpointCreateBySBAddress(entry) + self.assertTrue(entry_bp.IsValid(), "Can't set a breakpoint on the module entry point") + + result = target.EvaluateExpression("sum(7, 1)") + self.assertTrue(result.IsValid(), "Can't evaluate expression") + self.assertEqual(8, result.GetValueAsSigned()) + + def setUp(self): + TestBase.setUp(self) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/entry-bp/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/entry-bp/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/entry-bp/main.c @@ -0,0 +1,10 @@ +#include + +int sum(int x, int y) { + return x + y; +} + +int main() { + printf("Set a breakpoint here.\n"); + return sum(-1, 1); +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/expr-in-syscall/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/expr-in-syscall/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/expr-in-syscall/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/expr-in-syscall/TestExpressionInSyscall.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/expr-in-syscall/TestExpressionInSyscall.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/expr-in-syscall/TestExpressionInSyscall.py @@ -0,0 +1,92 @@ +"""Test that we are able to evaluate expressions when the inferior is blocked in a syscall""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class ExprSyscallTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr21765, getpid() does not exist on Windows") + @expectedFailureNetBSD + def test_setpgid(self): + self.build() + self.expr_syscall() + + def expr_syscall(self): + exe = self.getBuildArtifact("a.out") + + # Create a target by the debugger. + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + listener = lldb.SBListener("my listener") + + # 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 + + self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID) + + event = lldb.SBEvent() + + # Give the child enough time to reach the syscall, + # while clearing out all the pending events. + # The last WaitForEvent call will time out after 2 seconds. + while listener.WaitForEvent(2, event): + pass + + # now the process should be running (blocked in the syscall) + self.assertEqual( + process.GetState(), + lldb.eStateRunning, + "Process is running") + + # send the process a signal + process.SendAsyncInterrupt() + while listener.WaitForEvent(2, event): + 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) + 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())]) + + # and run the process to completion + process.Continue() + + # process all events + while listener.WaitForEvent(10, event): + new_state = lldb.SBProcess.GetStateFromEvent(event) + if new_state == lldb.eStateExited: + break + + self.assertEqual(process.GetState(), lldb.eStateExited) + self.assertEqual(process.GetExitStatus(), 0) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/expr-in-syscall/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/expr-in-syscall/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/expr-in-syscall/main.cpp @@ -0,0 +1,12 @@ +#include +#include + +volatile int release_flag = 0; + +int main(int argc, char const *argv[]) +{ + while (! release_flag) // Wait for debugger to attach + std::this_thread::sleep_for(std::chrono::seconds(3)); + + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/fixits/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/fixits/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/fixits/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/fixits/TestFixIts.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/fixits/TestFixIts.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/fixits/TestFixIts.py @@ -0,0 +1,72 @@ +""" +Test calling an expression with errors that a FixIt can fix. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class ExprCommandWithFixits(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + self.main_source = "main.cpp" + self.main_source_spec = lldb.SBFileSpec(self.main_source) + + @skipUnlessDarwin + def test_with_target(self): + """Test calling expressions with errors that can be fixed by the FixIts.""" + self.build() + self.try_expressions() + + def test_with_dummy_target(self): + """Test calling expressions in the dummy target with errors that can be fixed by the FixIts.""" + ret_val = lldb.SBCommandReturnObject() + result = self.dbg.GetCommandInterpreter().HandleCommand("expression ((1 << 16) - 1))", ret_val) + self.assertEqual(result, lldb.eReturnStatusSuccessFinishResult, "The expression was successful.") + self.assertTrue("Fix-it applied" in ret_val.GetError(), "Found the applied FixIt.") + + def try_expressions(self): + """Test calling expressions with errors that can be fixed by the FixIts.""" + (target, process, self.thread, bkpt) = lldbutil.run_to_source_breakpoint(self, + 'Stop here to evaluate expressions', self.main_source_spec) + + options = lldb.SBExpressionOptions() + options.SetAutoApplyFixIts(True) + + frame = self.thread.GetFrameAtIndex(0) + + # Try with one error: + value = frame.EvaluateExpression("my_pointer.first", options) + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertTrue(value.GetValueAsUnsigned() == 10) + + # Try with two errors: + two_error_expression = "my_pointer.second->a" + value = frame.EvaluateExpression(two_error_expression, options) + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertTrue(value.GetValueAsUnsigned() == 20) + + # Now turn off the fixits, and the expression should fail: + options.SetAutoApplyFixIts(False) + value = frame.EvaluateExpression(two_error_expression, options) + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Fail()) + error_string = value.GetError().GetCString() + self.assertTrue( + error_string.find("fixed expression suggested:") != -1, + "Fix was suggested") + self.assertTrue( + error_string.find("my_pointer->second.a") != -1, + "Fix was right") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/fixits/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/fixits/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/fixits/main.cpp @@ -0,0 +1,25 @@ +#include + +struct SubStruct +{ + int a; + int b; +}; + +struct MyStruct +{ + int first; + struct SubStruct second; +}; + +int +main() +{ + struct MyStruct my_struct = {10, {20, 30}}; + struct MyStruct *my_pointer = &my_struct; + printf ("Stop here to evaluate expressions: %d %d %p\n", my_pointer->first, my_pointer->second.a, my_pointer); + return 0; +} + + + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/formatters/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/formatters/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/formatters/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/formatters/TestFormatters.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/formatters/TestFormatters.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/formatters/TestFormatters.py @@ -0,0 +1,287 @@ +""" +Test using LLDB data formatters with frozen objects coming from the expression parser. +""" + +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__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break for main.cpp. + self.line = line_number('main.cpp', + '// Stop here') + + @skipIfFreeBSD # llvm.org/pr24691 skipping to avoid crashing the test runner + @expectedFailureNetBSD + @expectedFailureAll( + oslist=['freebsd'], + bugnumber='llvm.org/pr19011 Newer Clang omits C1 complete object constructor') + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765") + @skipIfTargetAndroid() # skipping to avoid crashing the test runner + @expectedFailureAndroid('llvm.org/pr24691') # we hit an assertion in clang + def test(self): + """Test expr + formatters for good interoperability.""" + 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 " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + 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.filecheck("expression --show-types -- *(new foo(47))", __file__, + '-check-prefix=EXPR-TYPES-NEW-FOO') + # EXPR-TYPES-NEW-FOO: (foo) ${{.*}} = { + # EXPR-TYPES-NEW-FOO-NEXT: (int) a = 47 + # EXPR-TYPES-NEW-FOO-NEXT: (int *) a_ptr = 0x + # EXPR-TYPES-NEW-FOO-NEXT: (bar) b = { + # EXPR-TYPES-NEW-FOO-NEXT: (int) i = 94 + # EXPR-TYPES-NEW-FOO-NEXT: (int *) i_ptr = 0x + # EXPR-TYPES-NEW-FOO-NEXT: (baz) b = { + # EXPR-TYPES-NEW-FOO-NEXT: (int) h = 97 + # EXPR-TYPES-NEW-FOO-NEXT: (int) k = 99 + # EXPR-TYPES-NEW-FOO-NEXT: } + # EXPR-TYPES-NEW-FOO-NEXT: (baz &) b_ref = 0x + # EXPR-TYPES-NEW-FOO-NEXT: } + # EXPR-TYPES-NEW-FOO-NEXT: } + + self.runCmd("type summary add -F formatters.foo_SummaryProvider foo") + + self.expect("expression new int(12)", + substrs=['(int *) $', ' = 0x']) + + self.runCmd( + "type summary add -s \"${var%pointer} -> ${*var%decimal}\" \"int *\"") + + self.expect("expression new int(12)", + substrs=['(int *) $', '= 0x', ' -> 12']) + + self.expect("expression foo1.a_ptr", + substrs=['(int *) $', '= 0x', ' -> 13']) + + self.filecheck("expression foo1", __file__, '-check-prefix=EXPR-FOO1') + # EXPR-FOO1: (foo) $ + # EXPR-FOO1-SAME: a = 12 + # EXPR-FOO1-SAME: a_ptr = {{[0-9]+}} -> 13 + # EXPR-FOO1-SAME: i = 24 + # EXPR-FOO1-SAME: i_ptr = {{[0-9]+}} -> 25 + # EXPR-FOO1-SAME: b_ref = {{[0-9]+}} + # EXPR-FOO1-SAME: h = 27 + # EXPR-FOO1-SAME: k = 29 + + self.filecheck("expression --ptr-depth=1 -- new foo(47)", __file__, + '-check-prefix=EXPR-PTR-DEPTH1') + # EXPR-PTR-DEPTH1: (foo *) $ + # EXPR-PTR-DEPTH1-SAME: a = 47 + # EXPR-PTR-DEPTH1-SAME: a_ptr = {{[0-9]+}} -> 48 + # EXPR-PTR-DEPTH1-SAME: i = 94 + # EXPR-PTR-DEPTH1-SAME: i_ptr = {{[0-9]+}} -> 95 + + self.filecheck("expression foo2", __file__, '-check-prefix=EXPR-FOO2') + # EXPR-FOO2: (foo) $ + # EXPR-FOO2-SAME: a = 121 + # EXPR-FOO2-SAME: a_ptr = {{[0-9]+}} -> 122 + # EXPR-FOO2-SAME: i = 242 + # EXPR-FOO2-SAME: i_ptr = {{[0-9]+}} -> 243 + # EXPR-FOO2-SAME: h = 245 + # EXPR-FOO2-SAME: k = 247 + + object_name = self.res.GetOutput() + object_name = object_name[7:] + object_name = object_name[0:object_name.find(' =')] + + self.filecheck("frame variable foo2", __file__, '-check-prefix=VAR-FOO2') + # VAR-FOO2: (foo) foo2 + # VAR-FOO2-SAME: a = 121 + # VAR-FOO2-SAME: a_ptr = {{[0-9]+}} -> 122 + # VAR-FOO2-SAME: i = 242 + # VAR-FOO2-SAME: i_ptr = {{[0-9]+}} -> 243 + # VAR-FOO2-SAME: h = 245 + # VAR-FOO2-SAME: k = 247 + + # The object is the same as foo2, so use the EXPR-FOO2 checks. + self.filecheck("expression $" + object_name, __file__, + '-check-prefix=EXPR-FOO2') + + self.runCmd("type summary delete foo") + self.runCmd( + "type synthetic add --python-class foosynth.FooSyntheticProvider foo") + + self.expect("expression --show-types -- $" + object_name, + substrs=['(foo) $', ' = {', '(int) *i_ptr = 243']) + + self.runCmd("n") + self.runCmd("n") + + 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 $" + object_name + '.a', + 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']) + + self.runCmd("type summary delete foo") + self.runCmd( + "type synthetic add --python-class foosynth.FooSyntheticProvider foo") + + self.expect("expression --show-types -- $" + object_name, + 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']) + + process = self.dbg.GetSelectedTarget().GetProcess() + thread = process.GetThreadAtIndex(0) + frame = thread.GetSelectedFrame() + + frozen = frame.EvaluateExpression("$" + object_name + ".a_ptr") + + a_data = frozen.GetPointeeData() + + error = lldb.SBError() + self.assertTrue( + a_data.GetUnsignedInt32( + error, + 0) == 122, + '*a_ptr = 122') + + self.runCmd("n") + self.runCmd("n") + self.runCmd("n") + + self.expect("frame variable numbers", + substrs=['1', '2', '3', '4', '5']) + + self.expect("expression numbers", + 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') + + 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') Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/formatters/foosynth.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/formatters/foosynth.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/formatters/foosynth.py @@ -0,0 +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') Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/formatters/formatters.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/formatters/formatters.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/formatters/formatters.py @@ -0,0 +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)) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/formatters/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/formatters/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/formatters/main.cpp @@ -0,0 +1,48 @@ +#include +#include + +struct baz + { + int h; + int k; + baz(int a, int b) : h(a), k(b) {} + }; + +struct bar + { + int i; + int* i_ptr; + baz b; + baz& b_ref; + bar(int x) : i(x),i_ptr(new int(x+1)),b(i+3,i+5),b_ref(b) {} + }; + +struct foo + { + int a; + int* a_ptr; + bar b; + + foo(int x) : a(x), + a_ptr(new int(x+1)), + b(2*x) {} + + }; + +int main(int argc, char** argv) +{ + foo foo1(12); + foo foo2(121); + + foo2.a = 7777; // Stop here + *(foo2.b.i_ptr) = 8888; + foo2.b.b.h = 9999; + + *(foo1.a_ptr) = 9999; + foo1.b.i = 9999; + + int numbers[5] = {1,2,3,4,5}; + + return 0; + +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/function_template_specialization_temp_args/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/function_template_specialization_temp_args/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/function_template_specialization_temp_args/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/function_template_specialization_temp_args/TestFunctionTemplateSpecializationTempArgs.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/function_template_specialization_temp_args/TestFunctionTemplateSpecializationTempArgs.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/function_template_specialization_temp_args/TestFunctionTemplateSpecializationTempArgs.py @@ -0,0 +1,17 @@ +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestFunctionTemplateSpecializationTempArgs(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def test_function_template_specialization_temp_args(self): + self.build() + + (self.target, self.process, _, bkpt) = lldbutil.run_to_source_breakpoint(self, '// break here', + lldb.SBFileSpec("main.cpp", False)) + + self.expect("expr p0", + substrs=['(VType) $0 = {}']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/function_template_specialization_temp_args/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/function_template_specialization_temp_args/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/function_template_specialization_temp_args/main.cpp @@ -0,0 +1,17 @@ +template struct M {}; + +template void f(T &t); + +template <> void f(int &t) { + typedef M VType; + + VType p0; // break here +} + +int main() { + int x; + + f(x); + + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/basic/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/basic/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/basic/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make +USE_LIBCPP := 1 +CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/basic/TestImportStdModule.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/basic/TestImportStdModule.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/basic/TestImportStdModule.py @@ -0,0 +1,56 @@ +""" +Test importing the 'std' C++ module and evaluate expressions with it. +""" + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class ImportStdModule(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # FIXME: This should work on more setups, so remove these + # skipIf's in the future. + @add_test_categories(["libc++"]) + @skipIf(compiler=no_match("clang")) + @skipIf(oslist=no_match(["linux"])) + @skipIf(debug_info=no_match(["dwarf"])) + def test(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, + "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) + + # Activate importing of std module. + self.runCmd("settings set target.import-std-module true") + # Calling some normal std functions that return non-template types. + self.expect("expr std::abs(-42)", substrs=['(int) $0 = 42']) + self.expect("expr std::div(2, 1).quot", substrs=['(int) $1 = 2']) + # Using types from std. + self.expect("expr (std::size_t)33U", substrs=['(size_t) $2 = 33']) + # Calling templated functions that return non-template types. + self.expect("expr char char_a = 'b'; char char_b = 'a'; std::swap(char_a, char_b); char_a", + substrs=["(char) $3 = 'a'"]) + + # FIXME: This should work on more setups, so remove these + # skipIf's in the future. + @add_test_categories(["libc++"]) + @skipIf(compiler=no_match("clang")) + @skipIf(oslist=no_match(["linux"])) + @skipIf(debug_info=no_match(["dwarf"])) + def test_non_cpp_language(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, + "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) + + # Activate importing of std module. + self.runCmd("settings set target.import-std-module true") + # These languages don't support C++ modules, so they shouldn't + # be able to evaluate the expression. + self.expect("expr -l C -- std::abs(-42)", error=True) + self.expect("expr -l C99 -- std::abs(-42)", error=True) + self.expect("expr -l C11 -- std::abs(-42)", error=True) + self.expect("expr -l ObjC -- std::abs(-42)", error=True) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/basic/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/basic/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/basic/main.cpp @@ -0,0 +1,7 @@ +// We need to import any std module. It doesn't matter which one. +#include + +int main(int argc, char **argv) { + std::cout << "Test" << std::endl; + return 0; // Set break point at this line. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/conflicts/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/conflicts/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/conflicts/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make +USE_LIBCPP := 1 +CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/conflicts/TestStdModuleWithConflicts.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/conflicts/TestStdModuleWithConflicts.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/conflicts/TestStdModuleWithConflicts.py @@ -0,0 +1,36 @@ +""" +Test importing the 'std' C++ module and check if we can handle +prioritizing the conflicting functions from debug info and std +module. + +See also import-std-module/basic/TestImportStdModule.py for +the same test on a 'clean' code base without conflicts. +""" + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestImportStdModuleConflicts(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # FIXME: This should work on more setups, so remove these + # skipIf's in the future. + @add_test_categories(["libc++"]) + @skipIf(compiler=no_match("clang")) + @skipIf(oslist=no_match(["linux"])) + @skipIf(debug_info=no_match(["dwarf"])) + def test(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, + "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) + + self.runCmd("settings set target.import-std-module true") + self.expect("expr std::abs(-42)", substrs=['(int) $0 = 42']) + self.expect("expr std::div(2, 1).quot", substrs=['(int) $1 = 2']) + self.expect("expr (std::size_t)33U", substrs=['(size_t) $2 = 33']) + self.expect("expr char char_a = 'b'; char char_b = 'a'; std::swap(char_a, char_b); char_a", + substrs=["(char) $3 = 'a'"]) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/conflicts/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/conflicts/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/conflicts/main.cpp @@ -0,0 +1,10 @@ +#include +#include + +int main(int argc, char **argv) { + std::size_t f = argc; + f = std::abs(argc); + f = std::div(argc * 2, argc).quot; + std::swap(f, f); + return f; // Set break point at this line. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/deque-basic/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/deque-basic/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/deque-basic/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make +USE_LIBCPP := 1 +CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/deque-basic/TestBasicDeque.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/deque-basic/TestBasicDeque.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/deque-basic/TestBasicDeque.py @@ -0,0 +1,41 @@ +""" +Test basic std::list functionality. +""" + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestBasicDeque(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # FIXME: This should work on more setups, so remove these + # skipIf's in the future. + @add_test_categories(["libc++"]) + @skipIf(compiler=no_match("clang")) + @skipIf(oslist=no_match(["linux"])) + @skipIf(debug_info=no_match(["dwarf"])) + def test(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, + "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) + + self.runCmd("settings set target.import-std-module true") + + self.expect("expr (size_t)a.size()", substrs=['(size_t) $0 = 3']) + self.expect("expr (int)a.front()", substrs=['(int) $1 = 3']) + self.expect("expr (int)a.back()", substrs=['(int) $2 = 2']) + + self.expect("expr std::sort(a.begin(), a.end())") + self.expect("expr (int)a.front()", substrs=['(int) $3 = 1']) + self.expect("expr (int)a.back()", substrs=['(int) $4 = 3']) + + self.expect("expr std::reverse(a.begin(), a.end())") + self.expect("expr (int)a.front()", substrs=['(int) $5 = 3']) + self.expect("expr (int)a.back()", substrs=['(int) $6 = 1']) + + self.expect("expr (int)(*a.begin())", substrs=['(int) $7 = 3']) + self.expect("expr (int)(*a.rbegin())", substrs=['(int) $8 = 1']) + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/deque-basic/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/deque-basic/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/deque-basic/main.cpp @@ -0,0 +1,6 @@ +#include + +int main(int argc, char **argv) { + std::deque a = {3, 1, 2}; + return 0; // Set break point at this line. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/deque-dbg-info-content/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/deque-dbg-info-content/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/deque-dbg-info-content/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make +USE_LIBCPP := 1 +CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/deque-dbg-info-content/TestDbgInfoContentDeque.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/deque-dbg-info-content/TestDbgInfoContentDeque.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/deque-dbg-info-content/TestDbgInfoContentDeque.py @@ -0,0 +1,37 @@ +""" +Test std::deque functionality with a decl from dbg info as content. +""" + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestDbgInfoContentDeque(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # FIXME: This should work on more setups, so remove these + # skipIf's in the future. + @add_test_categories(["libc++"]) + @skipIf(compiler=no_match("clang")) + @skipIf(oslist=no_match(["linux"])) + @skipIf(debug_info=no_match(["dwarf"])) + def test(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, + "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) + + self.runCmd("settings set target.import-std-module true") + + self.expect("expr (size_t)a.size()", substrs=['(size_t) $0 = 3']) + self.expect("expr (int)a.front().a", substrs=['(int) $1 = 3']) + self.expect("expr (int)a.back().a", substrs=['(int) $2 = 2']) + + self.expect("expr std::reverse(a.begin(), a.end())") + self.expect("expr (int)a.front().a", substrs=['(int) $3 = 2']) + self.expect("expr (int)a.back().a", substrs=['(int) $4 = 3']) + + self.expect("expr (int)(a.begin()->a)", substrs=['(int) $5 = 2']) + self.expect("expr (int)(a.rbegin()->a)", substrs=['(int) $6 = 3']) + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/deque-dbg-info-content/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/deque-dbg-info-content/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/deque-dbg-info-content/main.cpp @@ -0,0 +1,10 @@ +#include + +struct Foo { + int a; +}; + +int main(int argc, char **argv) { + std::deque a = {{3}, {1}, {2}}; + return 0; // Set break point at this line. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/forward_list-basic/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/forward_list-basic/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/forward_list-basic/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make +USE_LIBCPP := 1 +CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/forward_list-basic/TestBasicForwardList.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/forward_list-basic/TestBasicForwardList.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/forward_list-basic/TestBasicForwardList.py @@ -0,0 +1,34 @@ +""" +Test basic std::forward_list functionality. +""" + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestBasicForwardList(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # FIXME: This should work on more setups, so remove these + # skipIf's in the future. + @add_test_categories(["libc++"]) + @skipIf(compiler=no_match("clang")) + @skipIf(oslist=no_match(["linux"])) + @skipIf(debug_info=no_match(["dwarf"])) + def test(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, + "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) + + self.runCmd("settings set target.import-std-module true") + + self.expect("expr (size_t)std::distance(a.begin(), a.end())", substrs=['(size_t) $0 = 3']) + self.expect("expr (int)a.front()", substrs=['(int) $1 = 3']) + + self.expect("expr a.sort()") + self.expect("expr (int)a.front()", substrs=['(int) $2 = 1']) + + self.expect("expr (int)(*a.begin())", substrs=['(int) $3 = 1']) + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/forward_list-basic/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/forward_list-basic/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/forward_list-basic/main.cpp @@ -0,0 +1,6 @@ +#include + +int main(int argc, char **argv) { + std::forward_list a = {3, 1, 2}; + return 0; // Set break point at this line. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/forward_list-dbg-info-content/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/forward_list-dbg-info-content/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/forward_list-dbg-info-content/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make +USE_LIBCPP := 1 +CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/forward_list-dbg-info-content/TestDbgInfoContentForwardList.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/forward_list-dbg-info-content/TestDbgInfoContentForwardList.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/forward_list-dbg-info-content/TestDbgInfoContentForwardList.py @@ -0,0 +1,31 @@ +""" +Test std::forward_list functionality with a decl from debug info as content. +""" + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestDbgInfoContentForwardList(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # FIXME: This should work on more setups, so remove these + # skipIf's in the future. + @add_test_categories(["libc++"]) + @skipIf(compiler=no_match("clang")) + @skipIf(oslist=no_match(["linux"])) + @skipIf(debug_info=no_match(["dwarf"])) + def test(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, + "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) + + self.runCmd("settings set target.import-std-module true") + + self.expect("expr (size_t)std::distance(a.begin(), a.end())", substrs=['(size_t) $0 = 3']) + self.expect("expr (int)a.front().a", substrs=['(int) $1 = 3']) + + self.expect("expr (int)(a.begin()->a)", substrs=['(int) $2 = 3']) + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/forward_list-dbg-info-content/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/forward_list-dbg-info-content/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/forward_list-dbg-info-content/main.cpp @@ -0,0 +1,10 @@ +#include + +struct Foo { + int a; +}; + +int main(int argc, char **argv) { + std::forward_list a = {{3}, {1}, {2}}; + return 0; // Set break point at this line. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/list-basic/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/list-basic/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/list-basic/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make +USE_LIBCPP := 1 +CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/list-basic/TestBasicList.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/list-basic/TestBasicList.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/list-basic/TestBasicList.py @@ -0,0 +1,41 @@ +""" +Test basic std::list functionality. +""" + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestBasicList(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # FIXME: This should work on more setups, so remove these + # skipIf's in the future. + @add_test_categories(["libc++"]) + @skipIf(compiler=no_match("clang")) + @skipIf(oslist=no_match(["linux"])) + @skipIf(debug_info=no_match(["dwarf"])) + def test(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, + "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) + + self.runCmd("settings set target.import-std-module true") + + self.expect("expr (size_t)a.size()", substrs=['(size_t) $0 = 3']) + self.expect("expr (int)a.front()", substrs=['(int) $1 = 3']) + self.expect("expr (int)a.back()", substrs=['(int) $2 = 2']) + + self.expect("expr a.sort()") + self.expect("expr (int)a.front()", substrs=['(int) $3 = 1']) + self.expect("expr (int)a.back()", substrs=['(int) $4 = 3']) + + self.expect("expr std::reverse(a.begin(), a.end())") + self.expect("expr (int)a.front()", substrs=['(int) $5 = 3']) + self.expect("expr (int)a.back()", substrs=['(int) $6 = 1']) + + self.expect("expr (int)(*a.begin())", substrs=['(int) $7 = 3']) + self.expect("expr (int)(*a.rbegin())", substrs=['(int) $8 = 1']) + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/list-basic/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/list-basic/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/list-basic/main.cpp @@ -0,0 +1,6 @@ +#include + +int main(int argc, char **argv) { + std::list a = {3, 1, 2}; + return 0; // Set break point at this line. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/list-dbg-info-content/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/list-dbg-info-content/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/list-dbg-info-content/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make +USE_LIBCPP := 1 +CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentList.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentList.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentList.py @@ -0,0 +1,38 @@ +""" +Test basic std::list functionality but with a declaration from +the debug info (the Foo struct) as content. +""" + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestDbgInfoContentList(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # FIXME: This should work on more setups, so remove these + # skipIf's in the future. + @add_test_categories(["libc++"]) + @skipIf(compiler=no_match("clang")) + @skipIf(oslist=no_match(["linux"])) + @skipIf(debug_info=no_match(["dwarf"])) + def test(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, + "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) + + self.runCmd("settings set target.import-std-module true") + + self.expect("expr (size_t)a.size()", substrs=['(size_t) $0 = 3']) + self.expect("expr (int)a.front().a", substrs=['(int) $1 = 3']) + self.expect("expr (int)a.back().a", substrs=['(int) $2 = 2']) + + self.expect("expr std::reverse(a.begin(), a.end())") + self.expect("expr (int)a.front().a", substrs=['(int) $3 = 2']) + self.expect("expr (int)a.back().a", substrs=['(int) $4 = 3']) + + self.expect("expr (int)(a.begin()->a)", substrs=['(int) $5 = 2']) + self.expect("expr (int)(a.rbegin()->a)", substrs=['(int) $6 = 3']) + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/list-dbg-info-content/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/list-dbg-info-content/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/list-dbg-info-content/main.cpp @@ -0,0 +1,10 @@ +#include + +struct Foo { + int a; +}; + +int main(int argc, char **argv) { + std::list a = {{3}, {1}, {2}}; + return 0; // Set break point at this line. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/no-std-module/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/no-std-module/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/no-std-module/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make +USE_LIBCPP := 1 +CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/no-std-module/TestMissingStdModule.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/no-std-module/TestMissingStdModule.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/no-std-module/TestMissingStdModule.py @@ -0,0 +1,40 @@ +""" +Test that importing the std module on a compile unit +that doesn't use the std module will not break LLDB. + +It's not really specified at the moment what kind of +error we should report back to the user in this +situation. Currently Clang will just complain that +the std module doesn't exist or can't be loaded. +""" + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class STLTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # FIXME: This should work on more setups, so remove these + # skipIf's in the future. + @add_test_categories(["libc++"]) + @skipIf(compiler=no_match("clang")) + @skipIf(oslist=no_match(["linux"])) + @skipIf(debug_info=no_match(["dwarf"])) + def test(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, + "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) + + # Activate importing of std module. + self.runCmd("settings set target.import-std-module true") + + # Run some commands that should all fail without our std module. + self.expect("expr std::abs(-42)", error=True) + self.expect("expr std::div(2, 1).quot", error=True) + self.expect("expr (std::size_t)33U", error=True) + self.expect("expr char a = 'b'; char b = 'a'; std::swap(a, b); a", + error=True) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/no-std-module/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/no-std-module/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/no-std-module/main.cpp @@ -0,0 +1,5 @@ +// We don't import any std module here. + +int main(int argc, char **argv) { + return 0; // Set break point at this line. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/queue/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/queue/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/queue/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make +USE_LIBCPP := 1 +CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/queue/TestQueue.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/queue/TestQueue.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/queue/TestQueue.py @@ -0,0 +1,47 @@ +""" +Tests std::queue functionality. +""" + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestQueue(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # FIXME: This should work on more setups, so remove these + # skipIf's in the future. + @add_test_categories(["libc++"]) + @skipIf(compiler=no_match("clang")) + @skipIf(oslist=no_match(["linux"])) + @skipIf(debug_info=no_match(["dwarf"])) + def test(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, + "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) + + self.runCmd("settings set target.import-std-module true") + + # Test std::queue functionality with a std::deque. + self.expect("expr q_deque.pop()") + self.expect("expr q_deque.push({4})") + self.expect("expr (size_t)q_deque.size()", substrs=['(size_t) $0 = 1']) + self.expect("expr (int)q_deque.front().i", substrs=['(int) $1 = 4']) + self.expect("expr (int)q_deque.back().i", substrs=['(int) $2 = 4']) + self.expect("expr q_deque.empty()", substrs=['(bool) $3 = false']) + self.expect("expr q_deque.pop()") + self.expect("expr q_deque.emplace(5)") + self.expect("expr (int)q_deque.front().i", substrs=['(int) $4 = 5']) + + # Test std::queue functionality with a std::list. + self.expect("expr q_list.pop()") + self.expect("expr q_list.push({4})") + self.expect("expr (size_t)q_list.size()", substrs=['(size_t) $5 = 1']) + self.expect("expr (int)q_list.front().i", substrs=['(int) $6 = 4']) + self.expect("expr (int)q_list.back().i", substrs=['(int) $7 = 4']) + self.expect("expr q_list.empty()", substrs=['(bool) $8 = false']) + self.expect("expr q_list.pop()") + self.expect("expr q_list.emplace(5)") + self.expect("expr (int)q_list.front().i", substrs=['(int) $9 = 5']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/queue/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/queue/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/queue/main.cpp @@ -0,0 +1,16 @@ +#include +#include +#include + +struct C { + // Constructor for testing emplace. + C(int i) : i(i) {}; + int i; +}; + +int main(int argc, char **argv) { + // std::deque is the default container. + std::queue q_deque({{1}}); + std::queue> q_list({{1}}); + return 0; // Set break point at this line. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/shared_ptr-dbg-info-content/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/shared_ptr-dbg-info-content/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/shared_ptr-dbg-info-content/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make +USE_LIBCPP := 1 +CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/shared_ptr-dbg-info-content/TestSharedPtrDbgInfoContent.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/shared_ptr-dbg-info-content/TestSharedPtrDbgInfoContent.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/shared_ptr-dbg-info-content/TestSharedPtrDbgInfoContent.py @@ -0,0 +1,33 @@ +""" +Test std::shared_ptr functionality with a class from debug info as content. +""" + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestSharedPtrDbgInfoContent(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # FIXME: This should work on more setups, so remove these + # skipIf's in the future. + @add_test_categories(["libc++"]) + @skipIf(compiler=no_match("clang")) + @skipIf(oslist=no_match(["linux"])) + @skipIf(debug_info=no_match(["dwarf"])) + def test(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, + "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) + + self.runCmd("settings set target.import-std-module true") + + self.expect("expr (int)s->a", substrs=['(int) $0 = 3']) + self.expect("expr (int)(s->a = 5)", substrs=['(int) $1 = 5']) + self.expect("expr (int)s->a", substrs=['(int) $2 = 5']) + self.expect("expr (bool)s", substrs=['(bool) $3 = true']) + self.expect("expr s.reset()") + self.expect("expr (bool)s", substrs=['(bool) $4 = false']) + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/shared_ptr-dbg-info-content/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/shared_ptr-dbg-info-content/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/shared_ptr-dbg-info-content/main.cpp @@ -0,0 +1,11 @@ +#include + +struct Foo { + int a; +}; + +int main(int argc, char **argv) { + std::shared_ptr s(new Foo); + s->a = 3; + return s->a; // Set break point at this line. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/shared_ptr/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/shared_ptr/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/shared_ptr/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make +USE_LIBCPP := 1 +CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/shared_ptr/TestSharedPtr.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/shared_ptr/TestSharedPtr.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/shared_ptr/TestSharedPtr.py @@ -0,0 +1,33 @@ +""" +Test basic std::shared_ptr functionality. +""" + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestSharedPtr(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # FIXME: This should work on more setups, so remove these + # skipIf's in the future. + @add_test_categories(["libc++"]) + @skipIf(compiler=no_match("clang")) + @skipIf(oslist=no_match(["linux"])) + @skipIf(debug_info=no_match(["dwarf"])) + def test(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, + "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) + + self.runCmd("settings set target.import-std-module true") + + self.expect("expr (int)*s", substrs=['(int) $0 = 3']) + self.expect("expr (int)(*s = 5)", substrs=['(int) $1 = 5']) + self.expect("expr (int)*s", substrs=['(int) $2 = 5']) + self.expect("expr (bool)s", substrs=['(bool) $3 = true']) + self.expect("expr s.reset()") + self.expect("expr (bool)s", substrs=['(bool) $4 = false']) + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/shared_ptr/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/shared_ptr/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/shared_ptr/main.cpp @@ -0,0 +1,7 @@ +#include + +int main(int argc, char **argv) { + std::shared_ptr s(new int); + *s = 3; + return *s; // Set break point at this line. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/stack/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/stack/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/stack/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make +USE_LIBCPP := 1 +CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/stack/TestStack.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/stack/TestStack.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/stack/TestStack.py @@ -0,0 +1,49 @@ +""" +Tests std::stack functionality. +""" + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestStack(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # FIXME: This should work on more setups, so remove these + # skipIf's in the future. + @add_test_categories(["libc++"]) + @skipIf(compiler=no_match("clang")) + @skipIf(oslist=no_match(["linux"])) + @skipIf(debug_info=no_match(["dwarf"])) + def test(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, + "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) + + self.runCmd("settings set target.import-std-module true") + + # Test std::stack functionality with a std::deque. + self.expect("expr s_deque.pop()") + self.expect("expr s_deque.push({4})") + self.expect("expr (size_t)s_deque.size()", substrs=['(size_t) $0 = 3']) + self.expect("expr (int)s_deque.top().i", substrs=['(int) $1 = 4']) + self.expect("expr s_deque.emplace(5)") + self.expect("expr (int)s_deque.top().i", substrs=['(int) $2 = 5']) + + # Test std::stack functionality with a std::vector. + self.expect("expr s_vector.pop()") + self.expect("expr s_vector.push({4})") + self.expect("expr (size_t)s_vector.size()", substrs=['(size_t) $3 = 3']) + self.expect("expr (int)s_vector.top().i", substrs=['(int) $4 = 4']) + self.expect("expr s_vector.emplace(5)") + self.expect("expr (int)s_vector.top().i", substrs=['(int) $5 = 5']) + + # Test std::stack functionality with a std::list. + self.expect("expr s_list.pop()") + self.expect("expr s_list.push({4})") + self.expect("expr (size_t)s_list.size()", substrs=['(size_t) $6 = 3']) + self.expect("expr (int)s_list.top().i", substrs=['(int) $7 = 4']) + self.expect("expr s_list.emplace(5)") + self.expect("expr (int)s_list.top().i", substrs=['(int) $8 = 5']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/stack/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/stack/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/stack/main.cpp @@ -0,0 +1,17 @@ +#include +#include +#include + +struct C { + // Constructor for testing emplace. + C(int i) : i(i) {}; + int i; +}; + +int main(int argc, char **argv) { + // std::deque is the default container. + std::stack s_deque({{1}, {2}, {3}}); + std::stack> s_vector({{1}, {2}, {3}}); + std::stack> s_list({{1}, {2}, {3}}); + return 0; // Set break point at this line. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/sysroot/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/sysroot/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/sysroot/Makefile @@ -0,0 +1,10 @@ +LEVEL = ../../../make +# We don't have any standard include directories, so we can't +# parse the test_common.h header we usually inject as it includes +# system headers. +NO_TEST_COMMON_H := 1 + +CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) +CXXFLAGS += -I $(SRCDIR)/root/usr/include/c++/include/ -I $(SRCDIR)/root/usr/include/ -nostdinc -nostdinc++ -nostdlib++ +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/sysroot/TestStdModuleSysroot.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/sysroot/TestStdModuleSysroot.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/sysroot/TestStdModuleSysroot.py @@ -0,0 +1,34 @@ +""" +Test that we respect the sysroot when building the std module. +""" + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil +import os + +class ImportStdModule(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # FIXME: This should work on more setups, so remove these + # skipIf's in the future. + @skipIf(compiler=no_match("clang")) + @skipIf(oslist=no_match(["linux"])) + @skipIf(debug_info=no_match(["dwarf"])) + def test(self): + self.build() + + sysroot = os.path.join(os.getcwd(), "root") + + # Set the sysroot. + self.runCmd("platform select --sysroot '" + sysroot + "' host", CURRENT_EXECUTABLE_SET) + + lldbutil.run_to_source_breakpoint(self, + "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) + + self.runCmd("settings set target.import-std-module true") + + # Call our custom function in our sysroot std module. + # If this gives us the correct result, then we used the sysroot. + self.expect("expr std::myabs(-42)", substrs=['(int) $0 = 42']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/sysroot/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/sysroot/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/sysroot/main.cpp @@ -0,0 +1,6 @@ +#include + +int main(int argc, char **argv) { + libc_struct s; + return 0; // Set break point at this line. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/sysroot/root/usr/include/c++/include/algorithm =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/sysroot/root/usr/include/c++/include/algorithm +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/sysroot/root/usr/include/c++/include/algorithm @@ -0,0 +1,7 @@ +#include "libc_header.h" + +namespace std { + int myabs(int i) { + return i < 0 ? -i : i; + } +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/sysroot/root/usr/include/c++/include/module.modulemap =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/sysroot/root/usr/include/c++/include/module.modulemap +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/sysroot/root/usr/include/c++/include/module.modulemap @@ -0,0 +1,3 @@ +module std { + module "algorithm" { header "algorithm" export * } +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/sysroot/root/usr/include/libc_header.h =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/sysroot/root/usr/include/libc_header.h +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/sysroot/root/usr/include/libc_header.h @@ -0,0 +1 @@ +struct libc_struct {}; Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/unique_ptr-dbg-info-content/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/unique_ptr-dbg-info-content/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/unique_ptr-dbg-info-content/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make +USE_LIBCPP := 1 +CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/unique_ptr-dbg-info-content/TestUniquePtrDbgInfoContent.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/unique_ptr-dbg-info-content/TestUniquePtrDbgInfoContent.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/unique_ptr-dbg-info-content/TestUniquePtrDbgInfoContent.py @@ -0,0 +1,33 @@ +""" +Test std::unique_ptr functionality with a decl from debug info as content. +""" + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestUniquePtrDbgInfoContent(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # FIXME: This should work on more setups, so remove these + # skipIf's in the future. + @add_test_categories(["libc++"]) + @skipIf(compiler=no_match("clang")) + @skipIf(oslist=no_match(["linux"])) + @skipIf(debug_info=no_match(["dwarf"])) + def test(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, + "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) + + self.runCmd("settings set target.import-std-module true") + + self.expect("expr (int)s->a", substrs=['(int) $0 = 3']) + self.expect("expr (int)(s->a = 5)", substrs=['(int) $1 = 5']) + self.expect("expr (int)s->a", substrs=['(int) $2 = 5']) + self.expect("expr (bool)s", substrs=['(bool) $3 = true']) + self.expect("expr s.reset()") + self.expect("expr (bool)s", substrs=['(bool) $4 = false']) + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/unique_ptr-dbg-info-content/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/unique_ptr-dbg-info-content/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/unique_ptr-dbg-info-content/main.cpp @@ -0,0 +1,11 @@ +#include + +struct Foo { + int a; +}; + +int main(int argc, char **argv) { + std::shared_ptr s(new Foo); + s->a = 3; + return s->a; // Set break point at this line. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/unique_ptr/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/unique_ptr/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/unique_ptr/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make +USE_LIBCPP := 1 +CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/unique_ptr/TestUniquePtr.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/unique_ptr/TestUniquePtr.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/unique_ptr/TestUniquePtr.py @@ -0,0 +1,33 @@ +""" +Test basic std::unique_ptr functionality. +""" + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestUniquePtr(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # FIXME: This should work on more setups, so remove these + # skipIf's in the future. + @add_test_categories(["libc++"]) + @skipIf(compiler=no_match("clang")) + @skipIf(oslist=no_match(["linux"])) + @skipIf(debug_info=no_match(["dwarf"])) + def test(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, + "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) + + self.runCmd("settings set target.import-std-module true") + + self.expect("expr (int)*s", substrs=['(int) $0 = 3']) + self.expect("expr (int)(*s = 5)", substrs=['(int) $1 = 5']) + self.expect("expr (int)*s", substrs=['(int) $2 = 5']) + self.expect("expr (bool)s", substrs=['(bool) $3 = true']) + self.expect("expr s.reset()") + self.expect("expr (bool)s", substrs=['(bool) $4 = false']) + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/unique_ptr/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/unique_ptr/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/unique_ptr/main.cpp @@ -0,0 +1,7 @@ +#include + +int main(int argc, char **argv) { + std::shared_ptr s(new int); + *s = 3; + return *s; // Set break point at this line. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-basic/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-basic/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-basic/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make +USE_LIBCPP := 1 +CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-basic/TestBasicVector.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-basic/TestBasicVector.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-basic/TestBasicVector.py @@ -0,0 +1,57 @@ +""" +Test basic std::vector functionality. +""" + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestBasicVector(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # FIXME: This should work on more setups, so remove these + # skipIf's in the future. + @add_test_categories(["libc++"]) + @skipIf(compiler=no_match("clang")) + @skipIf(oslist=no_match(["linux"])) + @skipIf(debug_info=no_match(["dwarf"])) + def test(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, + "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) + + self.runCmd("settings set target.import-std-module true") + + self.expect("expr (size_t)a.size()", substrs=['(size_t) $0 = 3']) + self.expect("expr (int)a.front()", substrs=['(int) $1 = 3']) + self.expect("expr (int)a[1]", substrs=['(int) $2 = 1']) + self.expect("expr (int)a.back()", substrs=['(int) $3 = 2']) + + self.expect("expr std::sort(a.begin(), a.end())") + self.expect("expr (int)a.front()", substrs=['(int) $4 = 1']) + self.expect("expr (int)a[1]", substrs=['(int) $5 = 2']) + self.expect("expr (int)a.back()", substrs=['(int) $6 = 3']) + + self.expect("expr std::reverse(a.begin(), a.end())") + self.expect("expr (int)a.front()", substrs=['(int) $7 = 3']) + self.expect("expr (int)a[1]", substrs=['(int) $8 = 2']) + self.expect("expr (int)a.back()", substrs=['(int) $9 = 1']) + + self.expect("expr (int)(*a.begin())", substrs=['(int) $10 = 3']) + self.expect("expr (int)(*a.rbegin())", substrs=['(int) $11 = 1']) + + self.expect("expr a.pop_back()") + self.expect("expr (int)a.back()", substrs=['(int) $12 = 2']) + self.expect("expr (size_t)a.size()", substrs=['(size_t) $13 = 2']) + + self.expect("expr (int)a.at(0)", substrs=['(int) $14 = 3']) + + self.expect("expr a.push_back(4)") + self.expect("expr (int)a.back()", substrs=['(int) $15 = 4']) + self.expect("expr (size_t)a.size()", substrs=['(size_t) $16 = 3']) + + self.expect("expr a.emplace_back(5)") + self.expect("expr (int)a.back()", substrs=['(int) $17 = 5']) + self.expect("expr (size_t)a.size()", substrs=['(size_t) $18 = 4']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-basic/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-basic/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-basic/main.cpp @@ -0,0 +1,6 @@ +#include + +int main(int argc, char **argv) { + std::vector a = {3, 1, 2}; + return 0; // Set break point at this line. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-bool/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-bool/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-bool/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make +USE_LIBCPP := 1 +CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-bool/TestBoolVector.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-bool/TestBoolVector.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-bool/TestBoolVector.py @@ -0,0 +1,34 @@ +""" +Test basic std::vector functionality. +""" + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestBoolVector(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # FIXME: This should work on more setups, so remove these + # skipIf's in the future. + @add_test_categories(["libc++"]) + @skipIf(compiler=no_match("clang")) + @skipIf(oslist=no_match(["linux"])) + @skipIf(debug_info=no_match(["dwarf"])) + def test(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, + "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) + + self.runCmd("settings set target.import-std-module true") + + self.expect("expr (size_t)a.size()", substrs=['(size_t) $0 = 4']) + self.expect("expr (bool)a.front()", substrs=['(bool) $1 = false']) + self.expect("expr (bool)a[1]", substrs=['(bool) $2 = true']) + self.expect("expr (bool)a.back()", substrs=['(bool) $3 = true']) + + self.expect("expr (bool)(*a.begin())", substrs=['(bool) $4 = false']) + self.expect("expr (bool)(*a.rbegin())", substrs=['(bool) $5 = true']) + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-bool/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-bool/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-bool/main.cpp @@ -0,0 +1,6 @@ +#include + +int main(int argc, char **argv) { + std::vector a = {0, 1, 0, 1}; + return 0; // Set break point at this line. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-dbg-info-content/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-dbg-info-content/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-dbg-info-content/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make +USE_LIBCPP := 1 +CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVector.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVector.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVector.py @@ -0,0 +1,47 @@ +""" +Test basic std::vector functionality but with a declaration from +the debug info (the Foo struct) as content. +""" + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestDbgInfoContentVector(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # FIXME: This should work on more setups, so remove these + # skipIf's in the future. + @add_test_categories(["libc++"]) + @skipIf(compiler=no_match("clang")) + @skipIf(oslist=no_match(["linux"])) + @skipIf(debug_info=no_match(["dwarf"])) + def test(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, + "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) + + self.runCmd("settings set target.import-std-module true") + + self.expect("expr (size_t)a.size()", substrs=['(size_t) $0 = 3']) + self.expect("expr (int)a.front().a", substrs=['(int) $1 = 3']) + self.expect("expr (int)a[1].a", substrs=['(int) $2 = 1']) + self.expect("expr (int)a.back().a", substrs=['(int) $3 = 2']) + + self.expect("expr std::reverse(a.begin(), a.end())") + self.expect("expr (int)a.front().a", substrs=['(int) $4 = 2']) + + self.expect("expr (int)(a.begin()->a)", substrs=['(int) $5 = 2']) + self.expect("expr (int)(a.rbegin()->a)", substrs=['(int) $6 = 3']) + + self.expect("expr a.pop_back()") + self.expect("expr (int)a.back().a", substrs=['(int) $7 = 1']) + self.expect("expr (size_t)a.size()", substrs=['(size_t) $8 = 2']) + + self.expect("expr (int)a.at(0).a", substrs=['(int) $9 = 2']) + + self.expect("expr a.push_back({4})") + self.expect("expr (int)a.back().a", substrs=['(int) $10 = 4']) + self.expect("expr (size_t)a.size()", substrs=['(size_t) $11 = 3']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-dbg-info-content/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-dbg-info-content/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-dbg-info-content/main.cpp @@ -0,0 +1,10 @@ +#include + +struct Foo { + int a; +}; + +int main(int argc, char **argv) { + std::vector a = {{3}, {1}, {2}}; + return 0; // Set break point at this line. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-of-vectors/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-of-vectors/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-of-vectors/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make +USE_LIBCPP := 1 +CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-of-vectors/TestVectorOfVectors.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-of-vectors/TestVectorOfVectors.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-of-vectors/TestVectorOfVectors.py @@ -0,0 +1,30 @@ +""" +Test std::vector functionality when it's contents are vectors. +""" + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestVectorOfVectors(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # FIXME: This should work on more setups, so remove these + # skipIf's in the future. + @add_test_categories(["libc++"]) + @skipIf(compiler=no_match("clang")) + @skipIf(oslist=no_match(["linux"])) + @skipIf(debug_info=no_match(["dwarf"])) + def test(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, + "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) + + self.runCmd("settings set target.import-std-module true") + + self.expect("expr (size_t)a.size()", substrs=['(size_t) $0 = 2']) + self.expect("expr (int)a.front().front()", substrs=['(int) $1 = 1']) + self.expect("expr (int)a[1][1]", substrs=['(int) $2 = 2']) + self.expect("expr (int)a.back().at(0)", substrs=['(int) $3 = 3']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-of-vectors/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-of-vectors/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-of-vectors/main.cpp @@ -0,0 +1,6 @@ +#include + +int main(int argc, char **argv) { + std::vector > a = {{1, 2, 3}, {3, 2, 1}}; + return 0; // Set break point at this line. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/weak_ptr-dbg-info-content/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/weak_ptr-dbg-info-content/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/weak_ptr-dbg-info-content/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make +USE_LIBCPP := 1 +CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtr.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtr.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtr.py @@ -0,0 +1,33 @@ +""" +Test std::weak_ptr functionality with a decl from debug info as content. +""" + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestDbgInfoContentWeakPtr(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # FIXME: This should work on more setups, so remove these + # skipIf's in the future. + @add_test_categories(["libc++"]) + @skipIf(compiler=no_match("clang")) + @skipIf(oslist=no_match(["linux"])) + @skipIf(debug_info=no_match(["dwarf"])) + def test(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, + "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) + + self.runCmd("settings set target.import-std-module true") + + self.expect("expr (int)w.lock()->a", substrs=['(int) $0 = 3']) + self.expect("expr (int)(w.lock()->a = 5)", substrs=['(int) $1 = 5']) + self.expect("expr (int)w.lock()->a", substrs=['(int) $2 = 5']) + self.expect("expr w.use_count()", substrs=['(long) $3 = 1']) + self.expect("expr w.reset()") + self.expect("expr w.use_count()", substrs=['(long) $4 = 0']) + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/weak_ptr-dbg-info-content/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/weak_ptr-dbg-info-content/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/weak_ptr-dbg-info-content/main.cpp @@ -0,0 +1,12 @@ +#include + +struct Foo { + int a; +}; + +int main(int argc, char **argv) { + std::shared_ptr s(new Foo); + s->a = 3; + std::weak_ptr w = s; + return s->a; // Set break point at this line. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/weak_ptr/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/weak_ptr/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/weak_ptr/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make +USE_LIBCPP := 1 +CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/weak_ptr/TestWeakPtr.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/weak_ptr/TestWeakPtr.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/weak_ptr/TestWeakPtr.py @@ -0,0 +1,33 @@ +""" +Test basic std::weak_ptr functionality. +""" + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestSharedPtr(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # FIXME: This should work on more setups, so remove these + # skipIf's in the future. + @add_test_categories(["libc++"]) + @skipIf(compiler=no_match("clang")) + @skipIf(oslist=no_match(["linux"])) + @skipIf(debug_info=no_match(["dwarf"])) + def test(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, + "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) + + self.runCmd("settings set target.import-std-module true") + + self.expect("expr (int)*w.lock()", substrs=['(int) $0 = 3']) + self.expect("expr (int)(*w.lock() = 5)", substrs=['(int) $1 = 5']) + self.expect("expr (int)*w.lock()", substrs=['(int) $2 = 5']) + self.expect("expr w.use_count()", substrs=['(long) $3 = 1']) + self.expect("expr w.reset()") + self.expect("expr w.use_count()", substrs=['(long) $4 = 0']) + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/weak_ptr/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/weak_ptr/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import-std-module/weak_ptr/main.cpp @@ -0,0 +1,8 @@ +#include + +int main(int argc, char **argv) { + std::shared_ptr s(new int); + *s = 3; + std::weak_ptr w = s; + return *s; // Set break point at this line. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import_builtin_fileid/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import_builtin_fileid/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import_builtin_fileid/Makefile @@ -0,0 +1,6 @@ +LEVEL = ../../make + +OBJC_SOURCES := main.m + +include $(LEVEL)/Makefile.rules +LDFLAGS += -framework Cocoa Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import_builtin_fileid/TestImportBuiltinFileID.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import_builtin_fileid/TestImportBuiltinFileID.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import_builtin_fileid/TestImportBuiltinFileID.py @@ -0,0 +1,27 @@ +""" +They may be cases where an expression will import SourceLocation and if the +SourceLocation ends up with a FileID that is a built-in we need to copy that +buffer over correctly. +""" + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestImportBuiltinFileID(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + @skipIfDarwinEmbedded + @add_test_categories(["gmodules"]) + def test_import_builtin_fileid(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, '// break here', + lldb.SBFileSpec("main.m", False)) + + self.expect("expr int (*DBG_CGImageGetRenderingIntent)(void *) = ((int (*)(void *))CGImageGetRenderingIntent); DBG_CGImageGetRenderingIntent((void *)0x00000000000000);", + substrs=['$0 = 0']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import_builtin_fileid/main.m =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import_builtin_fileid/main.m +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/import_builtin_fileid/main.m @@ -0,0 +1,6 @@ +#import + +int main(int argc, const char * argv[]) { + + return 0; // break here +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/inline-namespace/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/inline-namespace/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/inline-namespace/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/inline-namespace/TestInlineNamespace.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/inline-namespace/TestInlineNamespace.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/inline-namespace/TestInlineNamespace.py @@ -0,0 +1,26 @@ +""" +Test that we correctly handle inline namespaces. +""" + +import lldb + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestInlineNamespace(TestBase): + mydir = TestBase.compute_mydir(__file__) + + def test(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, + "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) + + # The 'A::B::f' function must be found via 'A::f' as 'B' is an inline + # namespace. + self.expect("expr A::f()", substrs=['$0 = 3']) + # But we should still find the function when we pretend the inline + # namespace is not inline. + self.expect("expr A::B::f()", substrs=['$1 = 3']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/inline-namespace/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/inline-namespace/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/inline-namespace/main.cpp @@ -0,0 +1,10 @@ +namespace A { + inline namespace B { + int f() { return 3; } + }; +} + +int main(int argc, char **argv) { + // Set break point at this line. + return A::f(); +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/ir-interpreter-phi-nodes/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/ir-interpreter-phi-nodes/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/ir-interpreter-phi-nodes/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/ir-interpreter-phi-nodes/TestIRInterpreterPHINodes.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/ir-interpreter-phi-nodes/TestIRInterpreterPHINodes.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/ir-interpreter-phi-nodes/TestIRInterpreterPHINodes.py @@ -0,0 +1,41 @@ +""" +Test PHI nodes work in the IR interpreter. +""" + + +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 = self.getBuildArtifact("a.out") + self.runCmd('file ' + exe, CURRENT_EXECUTABLE_SET) + + # Break on the first assignment to i + line = line_number('main.cpp', 'i = 5') + lldbutil.run_break_set_by_file_and_line( + self, 'main.cpp', line, num_expected_locations=1, loc_exact=True) + + self.runCmd('run', RUN_SUCCEEDED) + + # The stop reason of the thread should be breakpoint + self.expect('thread list', STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', 'stop reason = breakpoint']) + + self.runCmd('s') + + # The logical 'or' causes a PHI node to be generated. Execute without JIT + # to test that the interpreter can handle this + self.expect('expr -j 0 -- i == 3 || i == 5', substrs=['true']) + + self.runCmd('s') + self.expect('expr -j 0 -- i == 3 || i == 5', substrs=['false']) + self.runCmd('s') + self.expect('expr -j 0 -- i == 3 || i == 5', substrs=['true']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/ir-interpreter-phi-nodes/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/ir-interpreter-phi-nodes/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/ir-interpreter-phi-nodes/main.cpp @@ -0,0 +1,16 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +int main() +{ + int i; + i = 5; + i = 2; + i = 3; + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/ir-interpreter/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/ir-interpreter/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/ir-interpreter/Makefile @@ -0,0 +1,7 @@ +LEVEL = ../../make + +default: a.out + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/ir-interpreter/TestIRInterpreter.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/ir-interpreter/TestIRInterpreter.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/ir-interpreter/TestIRInterpreter.py @@ -0,0 +1,94 @@ +""" +Test the IR interpreter +""" + +from __future__ import print_function + +import unittest2 + +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__) + NO_DEBUG_INFO_TESTCASE = True + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break for main.c. + self.line = line_number('main.c', + '// Set breakpoint here') + + # Disable confirmation prompt to avoid infinite wait + self.runCmd("settings set auto-confirm true") + self.addTearDownHook( + lambda: self.runCmd("settings clear auto-confirm")) + + def build_and_run(self): + """Test the IR interpreter""" + self.build() + + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, "main.c", self.line, num_expected_locations=1, loc_exact=False) + + self.runCmd("run", RUN_SUCCEEDED) + + @add_test_categories(['pyapi']) + # getpid() is POSIX, among other problems, see bug + @expectedFailureAll( + oslist=['windows'], + bugnumber="http://llvm.org/pr21765") + @expectedFailureNetBSD + @expectedFailureAll( + oslist=['linux'], + archs=['arm'], + bugnumber="llvm.org/pr27868") + def test_ir_interpreter(self): + self.build_and_run() + + options = lldb.SBExpressionOptions() + options.SetLanguage(lldb.eLanguageTypeC_plus_plus) + + set_up_expressions = ["int $i = 9", "int $j = 3", "int $k = 5"] + + expressions = ["$i + $j", + "$i - $j", + "$i * $j", + "$i / $j", + "$i % $k", + "$i << $j", + "$i & $j", + "$i | $j", + "$i ^ $j"] + + for expression in set_up_expressions: + self.frame().EvaluateExpression(expression, options) + + for expression in expressions: + interp_expression = expression + jit_expression = "(int)getpid(); " + expression + + interp_result = self.frame().EvaluateExpression( + interp_expression, options).GetValueAsSigned() + jit_result = self.frame().EvaluateExpression( + jit_expression, options).GetValueAsSigned() + + self.assertEqual( + interp_result, + jit_result, + "While evaluating " + + expression) + + def test_type_conversions(self): + target = self.dbg.GetDummyTarget() + short_val = target.EvaluateExpression("(short)-1") + self.assertEqual(short_val.GetValueAsSigned(), -1) + long_val = target.EvaluateExpression("(long) "+ short_val.GetName()) + self.assertEqual(long_val.GetValueAsSigned(), -1) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/ir-interpreter/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/ir-interpreter/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/ir-interpreter/main.c @@ -0,0 +1,7 @@ +#include + +int main() +{ + printf("This is a dummy\n"); // Set breakpoint here + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/issue_11588/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/issue_11588/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/issue_11588/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/issue_11588/Test11588.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/issue_11588/Test11588.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/issue_11588/Test11588.py @@ -0,0 +1,67 @@ +""" +Test the solution to issue 11581. +valobj.AddressOf() returns None when an address is +expected in a SyntheticChildrenProvider +""" + +from __future__ import print_function + + +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__) + + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24778") + def test_11581_commands(self): + # This is the function to remove the custom commands in order to have a + # clean slate for the next test case. + 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() + + (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, + 'Set breakpoint here.', + lldb.SBFileSpec("main.cpp", False)) + self.runCmd("command script import --allow-reload s11588.py") + 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 = "]) + + # 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 = self.dbg.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)]) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/issue_11588/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/issue_11588/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/issue_11588/main.cpp @@ -0,0 +1,54 @@ +// +// 11588.cpp +// + +#include + +class StgInfoTable {}; + +class StgHeader +{ +private: + StgInfoTable* info; +public: + StgHeader() + { + info = new StgInfoTable(); + } + ~StgHeader() + { + delete info; + } +}; + +class StgClosure +{ +private: + StgHeader header; + StgClosure* payload[1]; +public: + StgClosure(bool make_payload = true) + { + if (make_payload) + payload[0] = new StgClosure(false); + else + payload[0] = NULL; + } + ~StgClosure() + { + if (payload[0]) + delete payload[0]; + } +}; + +typedef unsigned long long int ptr_type; + +int main() +{ + StgClosure* r14_ = new StgClosure(); + r14_ = (StgClosure*)(((ptr_type)r14_ | 0x01)); // set the LSB to 1 for tagging + ptr_type r14 = (ptr_type)r14_; + int x = 0; + x = 3; + return (x-1); // Set breakpoint here. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/issue_11588/s11588.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/issue_11588/s11588.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/issue_11588/s11588.py @@ -0,0 +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 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 Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/macros/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/macros/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/macros/Makefile @@ -0,0 +1,8 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +DEBUG_INFO_FLAG = -g3 + + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/macros/TestMacros.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/macros/TestMacros.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/macros/TestMacros.py @@ -0,0 +1,131 @@ +from __future__ import print_function + + +import lldb +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') + def test_expr_with_macros(self): + self.build() + + # Get main source file + src_file = "main.cpp" + hdr_file = "macro1.h" + src_file_spec = lldb.SBFileSpec(src_file) + self.assertTrue(src_file_spec.IsValid(), "Main source file") + + (target, process, thread, bp1) = lldbutil.run_to_source_breakpoint( + self, "Break here", src_file_spec) + + # Get frame for current thread + frame = thread.GetSelectedFrame() + + result = frame.EvaluateExpression("MACRO_1") + 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") + + result = frame.EvaluateExpression("ONE") + self.assertTrue( + result.IsValid() and result.GetValue() == "1", + "ONE = 1") + + result = frame.EvaluateExpression("TWO") + self.assertTrue( + result.IsValid() and result.GetValue() == "2", + "TWO = 2") + + result = frame.EvaluateExpression("THREE") + self.assertTrue( + result.IsValid() and result.GetValue() == "3", + "THREE = 3") + + result = frame.EvaluateExpression("FOUR") + self.assertTrue( + result.IsValid() and result.GetValue() == "4", + "FOUR = 4") + + result = frame.EvaluateExpression("HUNDRED") + self.assertTrue( + result.IsValid() and result.GetValue() == "100", + "HUNDRED = 100") + + result = frame.EvaluateExpression("THOUSAND") + self.assertTrue( + result.IsValid() and result.GetValue() == "1000", + "THOUSAND = 1000") + + result = frame.EvaluateExpression("MILLION") + 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") + + result = frame.EvaluateExpression("MAX(THREE, TWO)") + self.assertTrue( + result.IsValid() and result.GetValue() == "3", + "MAX(THREE, TWO) = 3") + + # Get the thread of the process + thread.StepOver() + + # Get frame for current thread + frame = thread.GetSelectedFrame() + + result = frame.EvaluateExpression("MACRO_2") + 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") + + thread.StepInto() + + # Get frame for current thread + frame = thread.GetSelectedFrame() + + result = frame.EvaluateExpression("ONE") + 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") + + # 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") + + result = frame.EvaluateExpression("MACRO_2") + self.assertTrue(result.GetError().Fail(), + "Printing MACRO_2 fails in the header file") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/macros/macro1.h =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/macros/macro1.h +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/macros/macro1.h @@ -0,0 +1,17 @@ + +#include "macro2.h" + +#define ONE 1 +#define TWO 2 +#define THREE 3 +#define FOUR 4 + +class Simple +{ +public: + int + Method() + { + return ONE + TWO; + }; +}; Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/macros/macro2.h =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/macros/macro2.h +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/macros/macro2.h @@ -0,0 +1,8 @@ +#define HUNDRED 100 +#define THOUSAND 1000 +#define MILLION 1000000 + +#define MAX(a, b)\ +((a) > (b) ?\ + (a):\ + (b)) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/macros/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/macros/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/macros/main.cpp @@ -0,0 +1,15 @@ +#include "macro1.h" + +#define MACRO_1 100 +#define MACRO_2 200 + +int +main () +{ + int a = ONE + TWO; // Break here + + #undef MACRO_2 + #undef FOUR + + return Simple().Method(); +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/multiline-completion/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/multiline-completion/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/multiline-completion/Makefile @@ -0,0 +1,3 @@ +LEVEL = ../../make +C_SOURCES := main.c +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/multiline-completion/TestMultilineCompletion.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/multiline-completion/TestMultilineCompletion.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/multiline-completion/TestMultilineCompletion.py @@ -0,0 +1,30 @@ +""" +Test completion for multiline expressions. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test.lldbpexpect import PExpectTest + +class MultilineCompletionTest(PExpectTest): + + mydir = TestBase.compute_mydir(__file__) + + def test_basic_completion(self): + """Test that we can complete a simple multiline expression""" + self.build() + + self.launch(executable=self.getBuildArtifact("a.out")) + self.expect("b main", substrs=["Breakpoint 1", "address ="]) + self.expect("run", substrs=["stop reason ="]) + + self.child.sendline("expr") + self.child.expect_exact("terminate with an empty line to evaluate") + self.child.send("to_\t") + self.child.expect_exact("to_complete") + + self.child.send("\n\n") + self.expect_prompt() + + self.quit() Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/multiline-completion/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/multiline-completion/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/multiline-completion/main.c @@ -0,0 +1,5 @@ +int main(int argc, char **argv) { + lldb_enable_attach(); + int to_complete = 0; + return to_complete; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/namespace_local_var_same_name_cpp_and_c/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/namespace_local_var_same_name_cpp_and_c/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/namespace_local_var_same_name_cpp_and_c/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/namespace_local_var_same_name_cpp_and_c/TestNamespaceLocalVarSameNameCppAndC.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/namespace_local_var_same_name_cpp_and_c/TestNamespaceLocalVarSameNameCppAndC.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/namespace_local_var_same_name_cpp_and_c/TestNamespaceLocalVarSameNameCppAndC.py @@ -0,0 +1,24 @@ +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestNamespaceLocalVarSameNameCppAndC(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + @add_test_categories(["gmodules"]) + def test_namespace_local_var_same_name_cpp_and_c(self): + self.build() + + (self.target, self.process, _, bkpt) = lldbutil.run_to_source_breakpoint(self, '// break here', + lldb.SBFileSpec("main.cpp", False)) + + self.expect("expr error", + substrs=['(int) $0 = 1']) + + lldbutil.continue_to_breakpoint(self.process, bkpt) + + self.expect("expr error", + substrs=['(int) $1 = 1']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/namespace_local_var_same_name_cpp_and_c/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/namespace_local_var_same_name_cpp_and_c/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/namespace_local_var_same_name_cpp_and_c/main.cpp @@ -0,0 +1,21 @@ +namespace error { +int x; +} + +struct A { + void foo() { + int error = 1; + + return; // break here + } +}; + +int main() { + int error = 1; + + A a; + + a.foo(); + + return 0; // break here +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/namespace_local_var_same_name_obj_c/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/namespace_local_var_same_name_obj_c/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/namespace_local_var_same_name_obj_c/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make +OBJCXX_SOURCES := main.mm util.mm +include $(LEVEL)/Makefile.rules + +LDFLAGS += -framework Foundation Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/namespace_local_var_same_name_obj_c/TestNamespaceLocalVarSameNameObjC.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/namespace_local_var_same_name_obj_c/TestNamespaceLocalVarSameNameObjC.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/namespace_local_var_same_name_obj_c/TestNamespaceLocalVarSameNameObjC.py @@ -0,0 +1,24 @@ +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestNamespaceLocalVarSameNameObjC(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + @add_test_categories(["gmodules"]) + def test_namespace_local_var_same_name_obj_c(self): + self.build() + + (self.target, self.process, _, bkpt) = lldbutil.run_to_source_breakpoint(self, '// break here', + lldb.SBFileSpec("util.mm", False)) + + self.expect("expr error", + substrs=['(NSError *) $0 =']) + + lldbutil.continue_to_breakpoint(self.process, bkpt) + + self.expect("expr error", + substrs=['(NSError *) $1 =']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/namespace_local_var_same_name_obj_c/main.mm =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/namespace_local_var_same_name_obj_c/main.mm +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/namespace_local_var_same_name_obj_c/main.mm @@ -0,0 +1,16 @@ +#import +@interface Util : NSObject ++ (void)debugPrintErrorStatic; +- (void)debugPrintError; +@end + +int main(int argc, const char * argv[]) { + [Util debugPrintErrorStatic]; + + Util *u = [[Util alloc] init]; + + [u debugPrintError]; + + return 0; +} + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/namespace_local_var_same_name_obj_c/util.mm =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/namespace_local_var_same_name_obj_c/util.mm +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/namespace_local_var_same_name_obj_c/util.mm @@ -0,0 +1,22 @@ +#import + +namespace error { +int blah; +} + +@interface Util : NSObject ++ (void)debugPrintErrorStatic; +- (void)debugPrintError; +@end + +@implementation Util ++ (void)debugPrintErrorStatic { + NSError* error = [NSError errorWithDomain:NSURLErrorDomain code:-1 userInfo:nil]; + NSLog(@"xxx, error = %@", error); // break here +} + +- (void)debugPrintError { + NSError* error = [NSError errorWithDomain:NSURLErrorDomain code:-1 userInfo:nil]; + NSLog(@"xxx, error = %@", error); // break here +} +@end Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/no-deadlock/.categories =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/no-deadlock/.categories +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/no-deadlock/.categories @@ -0,0 +1 @@ +expression Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/no-deadlock/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/no-deadlock/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/no-deadlock/Makefile @@ -0,0 +1,6 @@ +LEVEL = ../../make + +C_SOURCES := locking.c +ENABLE_THREADS := YES + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/no-deadlock/TestExprDoesntBlock.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/no-deadlock/TestExprDoesntBlock.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/no-deadlock/TestExprDoesntBlock.py @@ -0,0 +1,60 @@ +""" +Test that expr will time out and allow other threads to run if it blocks. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class ExprDoesntDeadlockTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr17946') + @expectedFailureAll( + oslist=["windows"], + bugnumber="Windows doesn't have pthreads, test needs to be ported") + @add_test_categories(["basic_process"]) + def test_with_run_command(self): + """Test that expr will time out and allow other threads to run if it blocks.""" + self.build() + exe = self.getBuildArtifact("a.out") + + # Create a target by the debugger. + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + # Now create a breakpoint at source line before call_me_to_get_lock + # gets called. + + main_file_spec = lldb.SBFileSpec("locking.c") + breakpoint = target.BreakpointCreateBySourceRegex( + 'Break here', main_file_spec) + if self.TraceOn(): + print("breakpoint:", breakpoint) + self.assertTrue(breakpoint and + breakpoint.GetNumLocations() == 1, + VALID_BREAKPOINT) + + # Now launch the process, and do not stop at entry point. + process = target.LaunchSimple( + None, None, self.get_process_working_directory()) + self.assertTrue(process, PROCESS_IS_VALID) + + # Frame #0 should be on self.line1 and the break condition should hold. + from lldbsuite.test.lldbutil import get_stopped_thread + thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertTrue( + thread.IsValid(), + "There should be a thread stopped due to breakpoint condition") + + frame0 = thread.GetFrameAtIndex(0) + + var = frame0.EvaluateExpression("call_me_to_get_lock()") + self.assertTrue(var.IsValid()) + self.assertTrue(var.GetValueAsSigned(0) == 567) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/no-deadlock/locking.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/no-deadlock/locking.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/no-deadlock/locking.c @@ -0,0 +1,80 @@ +#include +#include +#include +#include + +pthread_mutex_t contended_mutex = PTHREAD_MUTEX_INITIALIZER; + +pthread_mutex_t control_mutex = PTHREAD_MUTEX_INITIALIZER; +pthread_cond_t control_condition; + +pthread_mutex_t thread_started_mutex = PTHREAD_MUTEX_INITIALIZER; +pthread_cond_t thread_started_condition; + +// This function runs in a thread. The locking dance is to make sure that +// by the time the main thread reaches the pthread_join below, this thread +// has for sure acquired the contended_mutex. So then the call_me_to_get_lock +// function will block trying to get the mutex, and only succeed once it +// signals this thread, then lets it run to wake up from the cond_wait and +// release the mutex. + +void * +lock_acquirer_1 (void *input) +{ + pthread_mutex_lock (&contended_mutex); + + // Grab this mutex, that will ensure that the main thread + // is in its cond_wait for it (since that's when it drops the mutex. + + pthread_mutex_lock (&thread_started_mutex); + pthread_mutex_unlock(&thread_started_mutex); + + // Now signal the main thread that it can continue, we have the contended lock + // so the call to call_me_to_get_lock won't make any progress till this + // thread gets a chance to run. + + pthread_mutex_lock (&control_mutex); + + pthread_cond_signal (&thread_started_condition); + + pthread_cond_wait (&control_condition, &control_mutex); + + pthread_mutex_unlock (&contended_mutex); + return NULL; +} + +int +call_me_to_get_lock () +{ + pthread_cond_signal (&control_condition); + pthread_mutex_lock (&contended_mutex); + return 567; +} + +int main () +{ + pthread_t thread_1; + + pthread_cond_init (&control_condition, NULL); + pthread_cond_init (&thread_started_condition, NULL); + + pthread_mutex_lock (&thread_started_mutex); + + pthread_create (&thread_1, NULL, lock_acquirer_1, NULL); + + pthread_cond_wait (&thread_started_condition, &thread_started_mutex); + + pthread_mutex_lock (&control_mutex); + pthread_mutex_unlock (&control_mutex); + + // Break here. At this point the other thread will have the contended_mutex, + // and be sitting in its cond_wait for the control condition. So there is + // no way that our by-hand calling of call_me_to_get_lock will proceed + // without running the first thread at least somewhat. + + call_me_to_get_lock(); + pthread_join (thread_1, NULL); + + return 0; + +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/options/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/options/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/options/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp foo.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/options/TestExprOptions.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/options/TestExprOptions.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/options/TestExprOptions.py @@ -0,0 +1,91 @@ +""" +Test expression command options. + +Test cases: + +o test_expr_options: + Test expression command options. +""" + +from __future__ import print_function + + +import lldb +import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * + + +class ExprOptionsTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + self.main_source = "main.cpp" + self.main_source_spec = lldb.SBFileSpec(self.main_source) + self.line = line_number('main.cpp', '// breakpoint_in_main') + self.exe = self.getBuildArtifact("a.out") + + def test_expr_options(self): + """These expression command options should work as expected.""" + self.build() + + # Set debugger into synchronous mode + self.dbg.SetAsync(False) + + (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( + self, '// breakpoint_in_main', self.main_source_spec) + + frame = thread.GetFrameAtIndex(0) + options = lldb.SBExpressionOptions() + + # test --language on C++ expression using the SB API's + + # Make sure we can evaluate a C++11 expression. + val = frame.EvaluateExpression('foo != nullptr') + self.assertTrue(val.IsValid()) + self.assertTrue(val.GetError().Success()) + self.DebugSBValue(val) + + # Make sure it still works if language is set to C++11: + options.SetLanguage(lldb.eLanguageTypeC_plus_plus_11) + val = frame.EvaluateExpression('foo != nullptr', options) + self.assertTrue(val.IsValid()) + self.assertTrue(val.GetError().Success()) + self.DebugSBValue(val) + + # Make sure it fails if language is set to C: + options.SetLanguage(lldb.eLanguageTypeC) + val = frame.EvaluateExpression('foo != nullptr', options) + self.assertTrue(val.IsValid()) + self.assertFalse(val.GetError().Success()) + + @skipIfDarwin + def test_expr_options_lang(self): + """These expression language options should work as expected.""" + self.build() + + # Set debugger into synchronous mode + self.dbg.SetAsync(False) + + (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( + self, '// breakpoint_in_main', self.main_source_spec) + + frame = thread.GetFrameAtIndex(0) + options = lldb.SBExpressionOptions() + + # Make sure we can retrieve `id` variable if language is set to C++11: + options.SetLanguage(lldb.eLanguageTypeC_plus_plus_11) + val = frame.EvaluateExpression('id == 0', options) + self.assertTrue(val.IsValid()) + self.assertTrue(val.GetError().Success()) + self.DebugSBValue(val) + + # Make sure we can't retrieve `id` variable if language is set to ObjC: + options.SetLanguage(lldb.eLanguageTypeObjC) + val = frame.EvaluateExpression('id == 0', options) + self.assertTrue(val.IsValid()) + self.assertFalse(val.GetError().Success()) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/options/foo.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/options/foo.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/options/foo.cpp @@ -0,0 +1,11 @@ +namespace ns { + int func(void) + { + return 0; + } +} + +extern "C" int foo(void) +{ + return ns::func(); +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/options/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/options/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/options/main.cpp @@ -0,0 +1,17 @@ +extern "C" int foo(void); +static int static_value = 0; +static int id = 1234; + +int +bar() +{ + static_value++; + id++; + return static_value + id; +} + +int main (int argc, char const *argv[]) +{ + bar(); // breakpoint_in_main + return foo(); +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persist_objc_pointeetype/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persist_objc_pointeetype/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persist_objc_pointeetype/Makefile @@ -0,0 +1,7 @@ +LEVEL = ../../make + +OBJC_SOURCES := main.m + +include $(LEVEL)/Makefile.rules +LDFLAGS += -framework Foundation -framework CloudKit + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persist_objc_pointeetype/TestPersistObjCPointeeType.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persist_objc_pointeetype/TestPersistObjCPointeeType.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persist_objc_pointeetype/TestPersistObjCPointeeType.py @@ -0,0 +1,51 @@ +""" +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__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break for main.cpp. + self.line = line_number('main.m', '// break here') + + @skipUnlessDarwin + @skipIf(archs=["i386", "i686"]) + @skipIf(debug_info="gmodules", archs=['arm64', 'armv7', 'armv7k']) # compile error with gmodules for iOS + def test_with(self): + """Test that we can p *objcObject""" + self.build() + + def cleanup(): + pass + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + 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']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persist_objc_pointeetype/main.m =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persist_objc_pointeetype/main.m +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persist_objc_pointeetype/main.m @@ -0,0 +1,80 @@ +/* +clang -g ExtendSuperclass.m -o ExtendSuperclass -framework Foundation -framework ProtectedCloudStorage -F/System/Library/PrivateFrameworks/ -framework CloudKit && ./ExtendSuperclass +*/ +#include +#import +#import + +#define SuperClass CKDatabase + +@interface SubClass : SuperClass +@end + +// class extension +@interface SuperClass () +@property (nonatomic, strong) NSString *_sc_name; +@property (nonatomic, strong) NSString *_sc_name2; +@property (nonatomic, strong) NSString *_sc_name3; +@property (nonatomic, strong) NSString *_sc_name4; +@property (nonatomic, strong) NSString *_sc_name5; +@property (nonatomic, strong) NSString *_sc_name6; +@property (nonatomic, strong) NSString *_sc_name7; +@property (nonatomic, strong) NSString *_sc_name8; +@end + +@implementation SuperClass (MySuperClass) +- (id)initThatDoesNotAssert +{ + return [super init]; +} +@end + +@implementation SubClass +- (id)initThatDoesNotAssert +{ + assert(_sc_name == nil); + assert(_sc_name2 == nil); + assert(_sc_name3 == nil); + assert(_sc_name4 == nil); + assert(_sc_name5 == nil); + assert(_sc_name6 == nil); + assert(_sc_name7 == nil); + assert(_sc_name8 == nil); // break here + + if ((self = [super _initWithContainer:(CKContainer*)@"foo" scope:0xff])) { + assert(_sc_name == nil); + assert(_sc_name2 == nil); + assert(_sc_name3 == nil); + assert(_sc_name4 == nil); + assert(_sc_name5 == nil); + assert(_sc_name6 == nil); + assert(_sc_name7 == nil); + assert(_sc_name8 == nil); + + _sc_name = @"empty"; + } + return self; +} +@synthesize _sc_name; +@synthesize _sc_name2; +@synthesize _sc_name3; +@synthesize _sc_name4; +@synthesize _sc_name5; +@synthesize _sc_name6; +@synthesize _sc_name7; +@synthesize _sc_name8; +- (void)foo:(NSString*)bar { self._sc_name = bar; } +- (NSString*)description { return [NSString stringWithFormat:@"%p: %@", self, self._sc_name]; } +@end + +int main() +{ + SubClass *sc = [[SubClass alloc] initThatDoesNotAssert]; + NSLog(@"%@", sc); + [sc foo:@"bar"]; + NSLog(@"%@", sc); + sc._sc_name = @"bar2"; + NSLog(@"%@", sc); + NSLog(@"%@", sc._sc_name); + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_ptr_update/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_ptr_update/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_ptr_update/Makefile @@ -0,0 +1,7 @@ +LEVEL = ../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules + + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_ptr_update/TestPersistentPtrUpdate.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_ptr_update/TestPersistentPtrUpdate.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_ptr_update/TestPersistentPtrUpdate.py @@ -0,0 +1,41 @@ +""" +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__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + def test(self): + """Test that we can have persistent pointer variables""" + self.build() + + def cleanup(): + pass + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.runCmd("file " + self.getBuildArtifact("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']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_ptr_update/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_ptr_update/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_ptr_update/main.c @@ -0,0 +1,11 @@ +void* foo(void *p) +{ + return p; // break here +} + +int main() { + while (1) { + foo(0); + } + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_types/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_types/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_types/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_types/TestNestedPersistentTypes.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_types/TestNestedPersistentTypes.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_types/TestNestedPersistentTypes.py @@ -0,0 +1,42 @@ +""" +Test that nested persistent types work. +""" + +from __future__ import print_function + + +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__) + + def test_persistent_types(self): + """Test that nested persistent types work.""" + self.build() + + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + self.runCmd("breakpoint set --name main") + + self.runCmd("run", RUN_SUCCEEDED) + + 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 $my_bar = {{ 2, 3 }, { 4, 5 }};") + + self.expect("expression $my_bar", + substrs=['a = 2', 'b = 3', 'a = 4', 'b = 5']) + + self.expect("expression $my_bar.start.b", + substrs=['(int)', '3']) + + self.expect("expression $my_bar.end.b", + substrs=['(int)', '5']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_types/TestPersistentTypes.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_types/TestPersistentTypes.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_types/TestPersistentTypes.py @@ -0,0 +1,93 @@ +""" +Test that lldb persistent types works correctly. +""" + +from __future__ import print_function + + +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__) + + def test_persistent_types(self): + """Test that lldb persistent types works correctly.""" + self.build() + + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + self.runCmd("breakpoint set --name main") + + self.runCmd("run", RUN_SUCCEEDED) + + 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 $my_foo", + substrs=['a = 2', 'b = 3']) + + self.runCmd("expression typedef int $bar") + + self.expect("expression $bar i = 5; i", + startstr="($bar) $1 = 5") + + 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 -x c", + 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']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_types/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_types/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_types/main.c @@ -0,0 +1,13 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +int main (int argc, char const *argv[]) +{ + const char* foo = "Hello world"; + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_variables/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_variables/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_variables/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_variables/TestPersistentVariables.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_variables/TestPersistentVariables.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_variables/TestPersistentVariables.py @@ -0,0 +1,53 @@ +""" +Test that lldb persistent variables works correctly. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.lldbtest import * + + +class PersistentVariablesTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def test_persistent_variables(self): + """Test that lldb persistent variables works correctly.""" + self.build() + + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + self.runCmd("breakpoint set --source-pattern-regexp break") + + self.runCmd("run", RUN_SUCCEEDED) + + self.runCmd("expression int $i = i") + + self.expect("expression $i == i", + startstr="(bool) $0 = true") + + self.expect("expression $i + 1", + startstr="(int) $1 = 6") + + self.expect("expression $i + 3", + startstr="(int) $2 = 8") + + self.expect("expression $2 + $1", + startstr="(int) $3 = 14") + + self.expect("expression $3", + startstr="(int) $3 = 14") + + self.expect("expression $2", + startstr="(int) $2 = 8") + + self.expect("expression (int)-2", + startstr="(int) $4 = -2") + + self.expect("expression $4 > (int)31", + startstr="(bool) $5 = false") + + self.expect("expression (long)$4", + startstr="(long) $6 = -2") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_variables/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_variables/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/persistent_variables/main.c @@ -0,0 +1,13 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +int main (int argc, char const *argv[]) +{ + int i = 5; + return 0; // Set breakpoint here +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/po_verbosity/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/po_verbosity/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/po_verbosity/Makefile @@ -0,0 +1,6 @@ +LEVEL = ../../make + +OBJC_SOURCES := main.m + +include $(LEVEL)/Makefile.rules +LDFLAGS += -framework Foundation Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/po_verbosity/TestPoVerbosity.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/po_verbosity/TestPoVerbosity.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/po_verbosity/TestPoVerbosity.py @@ -0,0 +1,63 @@ +""" +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__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break for main.cpp. + self.line = line_number('main.m', + '// Stop here') + + @skipUnlessDarwin + 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 " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + 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;']) + self.expect("expr -O -vfull -- foo", + 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", + substrs=['22']) + + self.expect("expr -O -vfull -- 22", + substrs=['(int) $', ' = 22']) + + self.expect("expr -O -v -- 22", + substrs=['(int) $', ' = 22']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/po_verbosity/main.m =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/po_verbosity/main.m +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/po_verbosity/main.m @@ -0,0 +1,9 @@ +#import + +int main() +{ + [NSString initialize]; + id foo = @{@1 : @2, @2 : @3}; + int x = 34; + return 0; // Stop here +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/pr35310/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/pr35310/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/pr35310/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/pr35310/TestExprsBug35310.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/pr35310/TestExprsBug35310.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/pr35310/TestExprsBug35310.py @@ -0,0 +1,39 @@ +from __future__ import print_function + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class ExprBug35310(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + self.main_source = "main.cpp" + self.main_source_spec = lldb.SBFileSpec(self.main_source) + + def test_issue35310(self): + """Test invoking functions with non-standard linkage names. + + The GNU abi_tag extension used by libstdc++ is a common source + of these, but they could originate from other reasons as well. + """ + self.build() + + (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, + '// Break here', self.main_source_spec) + frame = thread.GetFrameAtIndex(0) + + value = frame.EvaluateExpression("a.test_abi_tag()") + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertEqual(value.GetValueAsSigned(0), 1) + + value = frame.EvaluateExpression("a.test_asm_name()") + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertEqual(value.GetValueAsSigned(0), 2) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/pr35310/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/pr35310/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/pr35310/main.cpp @@ -0,0 +1,19 @@ +#include + +class A { +public: + int __attribute__((abi_tag("cxx11"))) test_abi_tag() { + return 1; + } + int test_asm_name() asm("A_test_asm") { + return 2; + } +}; + +int main(int argc, char **argv) { + A a; + // Break here + a.test_abi_tag(); + a.test_asm_name(); + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_8638051/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_8638051/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_8638051/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_8638051/Test8638051.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_8638051/Test8638051.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_8638051/Test8638051.py @@ -0,0 +1,38 @@ +""" +Test the robustness of lldb expression parser. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.lldbtest import * + + +class Radar8638051TestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def test_expr_commands(self): + """The following expression commands should not crash.""" + self.build() + + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + self.runCmd("breakpoint set -n c") + + self.runCmd("run", RUN_SUCCEEDED) + + self.expect("expression val", + startstr="(int) $0 = 1") + # (int) $0 = 1 + + self.expect("expression *(&val)", + 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 = ") + # (int *) $2 = 0x.... Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_8638051/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_8638051/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_8638051/main.c @@ -0,0 +1,53 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#include + +// This simple program is to demonstrate the capability of the lldb command +// "breakpoint command add" to add a set of commands to a breakpoint to be +// executed when the breakpoint is hit. +// +// In particular, we want to break within c(), but only if the immediate caller +// is a(). + +int a(int); +int b(int); +int c(int); + +int a(int val) +{ + if (val <= 1) + return b(val); + else if (val >= 3) + return c(val); // Find the line number where c's parent frame is a here. + + return val; +} + +int b(int val) +{ + return c(val); +} + +int c(int val) +{ + return val + 3; +} + +int main (int argc, char const *argv[]) +{ + int A1 = a(1); // a(1) -> b(1) -> c(1) + printf("a(1) returns %d\n", A1); + + int B2 = b(2); // b(2) -> c(2) + printf("b(2) returns %d\n", B2); + + int A3 = a(3); // a(3) -> c(3) + printf("a(3) returns %d\n", A3); + + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_9531204/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_9531204/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_9531204/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_9531204/TestPrintfAfterUp.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_9531204/TestPrintfAfterUp.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_9531204/TestPrintfAfterUp.py @@ -0,0 +1,43 @@ +""" +The evaluating printf(...) after break stop and then up a stack frame. +""" + +from __future__ import print_function + + +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__) + + # rdar://problem/9531204 + @expectedFailureNetBSD + def test_expr_commands(self): + """The evaluating printf(...) after break stop and then up a stack frame.""" + self.build() + + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_symbol( + self, 'foo', sym_exact=True, num_expected_locations=1) + + self.runCmd("run", RUN_SUCCEEDED) + + self.runCmd("frame variable") + + # This works fine. + self.runCmd('expression (int)printf("value is: %d.\\n", value);') + + # rdar://problem/9531204 + # "Error dematerializing struct" error when evaluating expressions "up" on the stack + self.runCmd('up') # frame select -r 1 + + self.runCmd("frame variable") + + # This does not currently. + self.runCmd('expression (int)printf("argc is: %d.\\n", argc)') Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_9531204/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_9531204/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_9531204/main.c @@ -0,0 +1,24 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#include + +// breakpoint set -n foo +// +// +int foo (int value) +{ + printf ("I got the value: %d.\n", value); + return 0; +} + +int main (int argc, char **argv) +{ + foo (argc); + printf ("Hello there: %d.\n", argc); + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_9673664/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_9673664/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_9673664/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_9673664/TestExprHelpExamples.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_9673664/TestExprHelpExamples.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_9673664/TestExprHelpExamples.py @@ -0,0 +1,45 @@ +""" +Test example snippets from the lldb 'help expression' output. +""" + +from __future__ import print_function + + +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__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break inside main(). + self.main_source = "main.c" + self.line = line_number(self.main_source, '// Set breakpoint here.') + + def test_expr_commands(self): + """The following expression commands should just work.""" + self.build() + + self.runCmd("file " + self.getBuildArtifact("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) + + self.runCmd("run", RUN_SUCCEEDED) + + # rdar://problem/9673664 lldb expression evaluation problem + + self.expect('expr char str[] = "foo"; str[0]', + substrs=["'f'"]) + # runCmd: expr char c[] = "foo"; c[0] + # output: (char) $0 = 'f' Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_9673664/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_9673664/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/radar_9673664/main.c @@ -0,0 +1,15 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#include + +int main (int argc, char const *argv[]) +{ + printf("Hello, world.\n"); // Set breakpoint here. + + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/rdar42038760/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/rdar42038760/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/rdar42038760/Makefile @@ -0,0 +1,3 @@ +LEVEL = ../../make +C_SOURCES := main.c +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/rdar42038760/TestScalarURem.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/rdar42038760/TestScalarURem.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/rdar42038760/TestScalarURem.py @@ -0,0 +1,4 @@ +from lldbsuite.test import lldbinline +from lldbsuite.test import decorators + +lldbinline.MakeInlineTest(__file__, globals(), None) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/rdar42038760/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/rdar42038760/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/rdar42038760/main.c @@ -0,0 +1,19 @@ +// Make sure we IR-interpret the expression correctly. + +typedef unsigned int uint32_t; +struct S0 { + signed f2; +}; +static g_463 = 0x1561983AL; +void func_1(void) +{ + struct S0 l_19; + l_19.f2 = 419; + uint32_t l_4037 = 4294967295UL; + l_19.f2 = g_463; //%self.expect("expr ((l_4037 % (-(g_463))) | l_19.f2)", substrs=['(unsigned int) $0 = 358717883']) +} +int main() +{ + func_1(); + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/rdar44436068/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/rdar44436068/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/rdar44436068/Makefile @@ -0,0 +1,3 @@ +LEVEL = ../../make +C_SOURCES := main.c +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/rdar44436068/Test128BitsInteger.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/rdar44436068/Test128BitsInteger.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/rdar44436068/Test128BitsInteger.py @@ -0,0 +1,6 @@ +from lldbsuite.test import lldbinline +from lldbsuite.test import decorators + +lldbinline.MakeInlineTest(__file__, globals(), + decorators.skipIf(archs=["armv7k"])) + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/rdar44436068/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/rdar44436068/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/rdar44436068/main.c @@ -0,0 +1,8 @@ +int main(void) +{ + __int128_t n = 1; + n = n + n; + return n; //%self.expect("p n", substrs=['(__int128_t) $0 = 2']) + //%self.expect("p n + 6", substrs=['(__int128) $1 = 8']) + //%self.expect("p n + n", substrs=['(__int128) $2 = 4']) +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/save_jit_objects/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/save_jit_objects/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/save_jit_objects/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/save_jit_objects/TestSaveJITObjects.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/save_jit_objects/TestSaveJITObjects.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/save_jit_objects/TestSaveJITObjects.py @@ -0,0 +1,53 @@ +""" +Test that LLDB can emit JIT objects when the appropriate setting is enabled +""" + +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 SaveJITObjectsTestCase(TestBase): + mydir = TestBase.compute_mydir(__file__) + + def enumerateJITFiles(self): + return [f for f in os.listdir(self.getBuildDir()) if f.startswith("jit")] + + def countJITFiles(self): + return len(self.enumerateJITFiles()) + + def cleanJITFiles(self): + for j in self.enumerateJITFiles(): + os.remove(j) + return + + @expectedFailureAll(oslist=["windows"]) + @expectedFailureNetBSD + def test_save_jit_objects(self): + self.build() + os.chdir(self.getBuildDir()) + src_file = "main.c" + src_file_spec = lldb.SBFileSpec(src_file) + + (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( + self, "break", src_file_spec) + + frame = thread.frames[0] + + self.cleanJITFiles() + frame.EvaluateExpression("(void*)malloc(0x1)") + self.assertTrue(self.countJITFiles() == 0, + "No files emitted with save-jit-objects=false") + + self.runCmd("settings set target.save-jit-objects true") + frame.EvaluateExpression("(void*)malloc(0x1)") + jit_files_count = self.countJITFiles() + self.cleanJITFiles() + self.assertTrue(jit_files_count != 0, + "At least one file emitted with save-jit-objects=true") + + process.Kill() + os.chdir(self.getSourceDir()) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/save_jit_objects/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/save_jit_objects/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/save_jit_objects/main.c @@ -0,0 +1,13 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +int main (int argc, char const *argv[]) +{ + const char* foo = "Hello world"; // break here + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/scoped_enums/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/scoped_enums/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/scoped_enums/Makefile @@ -0,0 +1,6 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp +CXXFLAGS += -std=c++11 + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/scoped_enums/TestScopedEnumType.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/scoped_enums/TestScopedEnumType.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/scoped_enums/TestScopedEnumType.py @@ -0,0 +1,45 @@ +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class ScopedEnumType(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @skipIf(dwarf_version=['<', '4']) + def test(self): + self.build() + + self.main_source = "main.cpp" + self.main_source_spec = lldb.SBFileSpec(self.main_source) + (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, + '// Set break point at this line.', self.main_source_spec) + frame = thread.GetFrameAtIndex(0) + + self.expect("expr f == Foo::FooBar", + substrs=['(bool) $0 = true']) + + value = frame.EvaluateExpression("f == Foo::FooBar") + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertEqual(value.GetValueAsUnsigned(), 1) + + value = frame.EvaluateExpression("b == BarBar") + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertEqual(value.GetValueAsUnsigned(), 1) + + ## b is not a Foo + value = frame.EvaluateExpression("b == Foo::FooBar") + self.assertTrue(value.IsValid()) + self.assertFalse(value.GetError().Success()) + + ## integral is not implicitly convertible to a scoped enum + value = frame.EvaluateExpression("1 == Foo::FooBar") + self.assertTrue(value.IsValid()) + self.assertFalse(value.GetError().Success()) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/scoped_enums/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/scoped_enums/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/scoped_enums/main.cpp @@ -0,0 +1,16 @@ +enum class Foo { + FooBar = 42 +}; + +enum Bar { + BarBar = 3, + BarBarBar = 42 +}; + +int main(int argc, const char **argv) { + Foo f = Foo::FooBar; + Bar b = BarBar; + bool b1 = f == Foo::FooBar; + bool b2 = b == BarBar; + return 0; // Set break point at this line. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/test/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/test/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/test/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/test/TestExprs.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/test/TestExprs.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/test/TestExprs.py @@ -0,0 +1,253 @@ +""" +Test many basic expression commands and SBFrame.EvaluateExpression() API. + +Test cases: + +o test_many_expr_commands: + Test many basic expression commands. +o test_evaluate_expression_python: + Use Python APIs (SBFrame.EvaluateExpression()) to evaluate expressions. +o test_expr_commands_can_handle_quotes: + Throw some expression commands with quotes at lldb. +""" + +from __future__ import print_function + + +import unittest2 + +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__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break for main.c. + self.line = line_number( + 'main.cpp', + '// 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")) + + def build_and_run(self): + """These basic expression commands should work as expected.""" + self.build() + + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, "main.cpp", self.line, num_expected_locations=1, loc_exact=False) + + self.runCmd("run", RUN_SUCCEEDED) + + @unittest2.expectedFailure( + "llvm.org/pr17135 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"]) + # (float) $2 = 2.234 + + def test_many_expr_commands(self): + self.build_and_run() + + self.expect("expression 2", + patterns=["\(int\) \$.* = 2"]) + # (int) $0 = 1 + + self.expect("expression 2ull", + patterns=["\(unsigned long long\) \$.* = 2"]) + # (unsigned long long) $1 = 2 + + self.expect("expression 0.5f", + patterns=["\(float\) \$.* = 0\.5"]) + # (float) $2 = 0.5 + + self.expect("expression 2.234", + patterns=["\(double\) \$.* = 2\.234"]) + # (double) $3 = 2.234 + + self.expect("expression 2+3", + patterns=["\(int\) \$.* = 5"]) + # (int) $4 = 5 + + self.expect("expression argc", + patterns=["\(int\) \$.* = 1"]) + # (int) $5 = 1 + + self.expect("expression argc + 22", + patterns=["\(int\) \$.* = 23"]) + # (int) $6 = 23 + + self.expect("expression argv", + patterns=["\(const char \*\*\) \$.* = 0x"]) + # (const char *) $7 = ... + + self.expect("expression argv[0]", + substrs=["(const char *)", + "a.out"]) + # (const char *) $8 = 0x... "/Volumes/data/lldb/svn/trunk/test/expression_command/test/a.out" + + @add_test_categories(['pyapi']) + @expectedFlakeyNetBSD + def test_evaluate_expression_python(self): + """Test SBFrame.EvaluateExpression() API for evaluating an expression.""" + self.build() + + exe = self.getBuildArtifact("a.out") + + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + # Create the breakpoint. + filespec = lldb.SBFileSpec("main.cpp", False) + breakpoint = target.BreakpointCreateByLocation(filespec, self.line) + self.assertTrue(breakpoint, VALID_BREAKPOINT) + + # Verify the breakpoint just created. + self.expect(str(breakpoint), BREAKPOINT_CREATED, exe=False, + 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()) + + if not process: + self.fail("SBTarget.LaunchProcess() failed") + + if process.GetState() != lldb.eStateStopped: + self.fail("Process should be in the 'stopped' state, " + "instead the actual state is: '%s'" % + lldbutil.state_type_to_str(process.GetState())) + + thread = lldbutil.get_one_thread_stopped_at_breakpoint( + process, breakpoint) + self.assertIsNotNone( + thread, "Expected one thread to be stopped at the breakpoint") + + # 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") + self.expect(lldbutil.get_function_names(thread)[0], + "Break correctly at main()", exe=False, + startstr="main") + + # We should be stopped on the breakpoint with a hit count of 1. + self.assertTrue(breakpoint.GetHitCount() == 1, BREAKPOINT_HIT_ONCE) + + # + # Use Python API to evaluate expressions while stopped in a stack frame. + # + frame = thread.GetFrameAtIndex(0) + + val = frame.EvaluateExpression("2.234") + self.expect(val.GetValue(), "2.345 evaluated correctly", exe=False, + startstr="2.234") + self.expect(val.GetTypeName(), "2.345 evaluated correctly", exe=False, + startstr="double") + self.DebugSBValue(val) + + val = frame.EvaluateExpression("argc") + self.expect(val.GetValue(), "Argc evaluated correctly", exe=False, + startstr="4") + self.DebugSBValue(val) + + val = frame.EvaluateExpression("*argv[1]") + self.expect(val.GetValue(), "Argv[1] evaluated correctly", exe=False, + startstr="'X'") + self.DebugSBValue(val) + + val = frame.EvaluateExpression("*argv[2]") + self.expect(val.GetValue(), "Argv[2] evaluated correctly", exe=False, + startstr="'Y'") + self.DebugSBValue(val) + + val = frame.EvaluateExpression("*argv[3]") + self.expect(val.GetValue(), "Argv[3] evaluated correctly", exe=False, + startstr="'Z'") + self.DebugSBValue(val) + + 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) + + # 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) + + # rdar://problem/8686536 + # CommandInterpreter::HandleCommand is stripping \'s from input for + # WantsRawCommand commands + @expectedFailureNetBSD + def test_expr_commands_can_handle_quotes(self): + """Throw some expression commands with quotes at lldb.""" + self.build() + + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, "main.cpp", self.line, num_expected_locations=1, loc_exact=False) + + self.runCmd("run", RUN_SUCCEEDED) + + # runCmd: expression 'a' + # output: (char) $0 = 'a' + self.expect("expression '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']) + + # runCmd: expression (int) printf("\t\x68\n") + # output: (int) $2 = 3 + self.expect(r'''expression (int) printf("\t\x68\n")''', + substrs=['(int) $', + '3']) + + # runCmd: expression (int) printf("\"\n") + # output: (int) $3 = 2 + self.expect(r'''expression (int) printf("\"\n")''', + substrs=['(int) $', + '2']) + + # runCmd: expression (int) printf("'\n") + # output: (int) $4 = 2 + self.expect(r'''expression (int) printf("'\n")''', + 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")''') + # This fails currently. + self.expect('print_hi', + substrs=['(int) $', + '6']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/test/TestExprs2.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/test/TestExprs2.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/test/TestExprs2.py @@ -0,0 +1,74 @@ +""" +Test some more expression commands. +""" + +from __future__ import print_function + + +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__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break for main.c. + self.line = line_number( + 'main.cpp', + '// Please test many expressions while stopped at this line:') + + def test_more_expr_commands(self): + """Test some more expression commands.""" + self.build() + + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, "main.cpp", self.line, num_expected_locations=1, loc_exact=False) + + self.runCmd("run", RUN_SUCCEEDED) + + # Does static casting work? + self.expect("expression (int*)argv", + startstr="(int *) $0 = 0x") + # (int *) $0 = 0x00007fff5fbff258 + + # Do return values containing the contents of expression locals work? + self.expect("expression int i = 5; i", + startstr="(int) $1 = 5") + # (int) $2 = 5 + self.expect("expression $1 + 1", + startstr="(int) $2 = 6") + # (int) $3 = 6 + + # Do return values containing the results of static expressions work? + self.expect("expression 20 + 3", + startstr="(int) $3 = 23") + # (int) $4 = 5 + self.expect("expression $3 + 1", + startstr="(int) $4 = 24") + # (int) $5 = 6 + + @skipIfLinux + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24489") + def test_expr_symbols(self): + """Test symbols.""" + self.build() + + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, "main.cpp", self.line, num_expected_locations=1, loc_exact=False) + + self.runCmd("run", RUN_SUCCEEDED) + + # Do anonymous symbols work? + self.expect("expression ((char**)environ)[0]", + startstr="(char *) $0 = 0x") + # (char *) $1 = 0x00007fff5fbff298 "Apple_PubSub_Socket_Render=/tmp/launch-7AEsUD/Render" Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/test/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/test/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/test/main.cpp @@ -0,0 +1,44 @@ +#include + +static int static_value = 0; + +int +a_function_to_call() +{ + static_value++; + return static_value; +} + +int main (int argc, char const *argv[]) +{ + printf ("Hello world!\n"); + puts ("hello"); + // Please test many expressions while stopped at this line: +#if 0 + expression 'a' // make sure character constant makes it down (this is broken: ) + expression 2 // Test int + expression 2ull // Test unsigned long long + expression 2.234f // Test float constants + expression 2.234 // Test double constants + expression 2+3 + expression argc + expression argc + 22 + expression argv + expression argv[0] + expression argv[1] + expression argv[-1] + expression puts("bonjour") // Test constant strings... + expression printf("\t\x68\n") // Test constant strings that contain the \xXX (TAB, 'h', '\n' should be printed) (this is broken: ) + expression printf("\"\n") // Test constant strings that contains an escaped double quote char (this is broken: ) + expression printf("\'\n") // Test constant strings that contains an escaped single quote char (this is broken: ) + expression printf ("one: %i\n", 1) + expression printf ("1.234 as float: %f\n", 1.234f) + expression printf ("1.234 as double: %g\n", 1.234) + expression printf ("one: %i, two: %llu\n", 1, 2ull) + expression printf ("two: %llu, one: %i\n", 2ull, 1) + expression random() % 255l +#endif + + a_function_to_call(); + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/timeout/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/timeout/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/timeout/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := wait-a-while.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/timeout/TestCallWithTimeout.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/timeout/TestCallWithTimeout.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/timeout/TestCallWithTimeout.py @@ -0,0 +1,80 @@ +""" +Test calling a function that waits a while, and make sure the timeout option to expr works. +""" + +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__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + self.main_source = "wait-a-while.cpp" + self.main_source_spec = lldb.SBFileSpec(self.main_source) + + @expectedFlakeyFreeBSD("llvm.org/pr19605") + @expectedFailureAll( + oslist=[ + "windows"], + bugnumber="llvm.org/pr21765") + def test(self): + """Test calling std::String member function.""" + self.build() + + (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( + self, 'stop here in main.', self.main_source_spec) + + # 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()) + + # 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) + + # Okay, now do it again with long enough time outs: + + options.SetTimeoutInMicroSeconds(1000000) + value = frame.EvaluateExpression("wait_a_while (1000)", options) + self.assertTrue(value.IsValid()) + 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) + self.assertTrue(return_value == lldb.eReturnStatusSuccessFinishResult) + + # 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) + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/timeout/wait-a-while.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/timeout/wait-a-while.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/timeout/wait-a-while.cpp @@ -0,0 +1,35 @@ +#include +#include + +#include +#include + + +int +wait_a_while (int microseconds) +{ + int num_times = 0; + auto end_time = std::chrono::system_clock::now() + std::chrono::microseconds(microseconds); + + while (1) + { + num_times++; + auto wait_time = end_time - std::chrono::system_clock::now(); + + std::this_thread::sleep_for(wait_time); + if (std::chrono::system_clock::now() > end_time) + break; + } + return num_times; +} + +int +main (int argc, char **argv) +{ + printf ("stop here in main.\n"); + int num_times = wait_a_while (argc * 1000); + printf ("Done, took %d times.\n", num_times); + + return 0; + +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/top-level/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/top-level/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/top-level/Makefile @@ -0,0 +1,13 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp test.cpp + +include $(LEVEL)/Makefile.rules + +a.out: dummy + +dummy: + $(MAKE) VPATH=$(VPATH) -I $(SRCDIR) -f $(SRCDIR)/dummy.mk + +clean:: + $(MAKE) VPATH=$(VPATH) -I $(SRCDIR) -f $(SRCDIR)/dummy.mk clean Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/top-level/TestTopLevelExprs.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/top-level/TestTopLevelExprs.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/top-level/TestTopLevelExprs.py @@ -0,0 +1,94 @@ +""" +Test top-level expressions. +""" + +from __future__ import print_function + + +import unittest2 + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TopLevelExpressionsTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break for main.c. + self.line = line_number('main.cpp', + '// Set breakpoint here') + self.dummy_line = line_number('dummy.cpp', + '// Set breakpoint here') + + # Disable confirmation prompt to avoid infinite wait + self.runCmd("settings set auto-confirm true") + self.addTearDownHook( + lambda: self.runCmd("settings clear auto-confirm")) + + def build_and_run(self): + """Test top-level expressions.""" + self.build() + + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, "main.cpp", self.line, num_expected_locations=1, loc_exact=False) + + self.runCmd("run", RUN_SUCCEEDED) + + def run_dummy(self): + self.runCmd("file " + self.getBuildArtifact("dummy"), + CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, + "dummy.cpp", + self.dummy_line, + num_expected_locations=1, + loc_exact=False) + + self.runCmd("run", RUN_SUCCEEDED) + + @add_test_categories(['pyapi']) + @skipIf(debug_info="gmodules") # not relevant + @skipIf(oslist=["windows"]) # Error in record layout on Windows + def test_top_level_expressions(self): + self.build_and_run() + + resultFromCode = self.frame().EvaluateExpression("doTest()").GetValueAsUnsigned() + + self.runCmd("kill") + + self.run_dummy() + + codeFile = open('test.cpp', 'r') + + expressions = [] + current_expression = "" + + for line in codeFile: + if line.startswith("// --"): + expressions.append(current_expression) + current_expression = "" + else: + current_expression += line + + options = lldb.SBExpressionOptions() + options.SetLanguage(lldb.eLanguageTypeC_plus_plus) + options.SetTopLevel(True) + + for expression in expressions: + self.frame().EvaluateExpression(expression, options) + + resultFromTopLevel = self.frame().EvaluateExpression("doTest()") + + self.assertTrue(resultFromTopLevel.IsValid()) + self.assertEqual( + resultFromCode, + resultFromTopLevel.GetValueAsUnsigned()) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/top-level/dummy.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/top-level/dummy.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/top-level/dummy.cpp @@ -0,0 +1,15 @@ +#include + +// These are needed to make sure that the linker does not strip the parts of the +// C++ abi library that are necessary to execute the expressions in the +// debugger. It would be great if we did not need to do this, but the fact that +// LLDB cannot conjure up the abi library on demand is not relevant for testing +// top level expressions. +struct DummyA {}; +struct DummyB : public virtual DummyA {}; + +int main() { + DummyB b; + printf("This is a dummy\n"); // Set breakpoint here + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/top-level/dummy.mk =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/top-level/dummy.mk +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/top-level/dummy.mk @@ -0,0 +1,6 @@ +LEVEL = ../../make + +CXX_SOURCES := dummy.cpp +EXE := dummy + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/top-level/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/top-level/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/top-level/main.cpp @@ -0,0 +1,9 @@ +#include + +extern int doTest(); + +int main() +{ + printf("%d\n", doTest()); // Set breakpoint here + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/top-level/test.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/top-level/test.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/top-level/test.cpp @@ -0,0 +1,107 @@ +class MyClass +{ +public: + int memberResult() + { + return 1; + } + static int staticResult() + { + return 1; + } + int externResult(); +}; + +// -- + +int MyClass::externResult() +{ + return 1; +} + +// -- + +MyClass m; + +// -- + +enum MyEnum { + myEnumOne = 1, + myEnumTwo, + myEnumThree +}; + +// -- + +class AnotherClass +{ +public: + __attribute__ ((always_inline)) int complicatedFunction() + { + struct { + int i; + } s = { 15 }; + + int numbers[4] = { 2, 3, 4, 5 }; + + for (signed char number: numbers) + { + s.i -= number; + } + + return s.i; + } +}; + +// -- + +class DiamondA +{ +private: + struct { + int m_i; + }; +public: + DiamondA(int i) : m_i(i) { } + int accessor() { return m_i; } +}; + +// -- + +class DiamondB : public virtual DiamondA +{ +public: + DiamondB(int i) : DiamondA(i) { } +}; + +// -- + +class DiamondC : public virtual DiamondA +{ +public: + DiamondC(int i) : DiamondA(i) { } +}; + +// -- + +class DiamondD : public DiamondB, public DiamondC +{ +public: + DiamondD(int i) : DiamondA(i), DiamondB(i), DiamondC(i) { } +}; + +// -- + +int doTest() +{ + int accumulator = m.memberResult(); + accumulator += MyClass::staticResult(); + accumulator += m.externResult(); + accumulator += MyEnum::myEnumThree; + accumulator += myEnumOne; + accumulator += AnotherClass().complicatedFunction(); + accumulator += DiamondD(3).accessor(); + return accumulator; +} + +// -- Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/two-files/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/two-files/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/two-files/Makefile @@ -0,0 +1,7 @@ +LEVEL = ../../make + +OBJC_SOURCES := main.m foo.m + +include $(LEVEL)/Makefile.rules + +LDFLAGS += -framework Foundation \ No newline at end of file Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/two-files/TestObjCTypeQueryFromOtherCompileUnit.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/two-files/TestObjCTypeQueryFromOtherCompileUnit.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/two-files/TestObjCTypeQueryFromOtherCompileUnit.py @@ -0,0 +1,41 @@ +""" +Regression test for : + +The expression parser's type search only looks in the current compilation unit for types. +""" + +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__) + + def setUp(self): + # 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'.") + + @skipUnlessDarwin + def test(self): + """The expression parser's type search should be wider than the current compilation unit.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("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) + + 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']) + # (NSArray *) $0 = 0x00007fff70118398 Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/two-files/foo.m =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/two-files/foo.m +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/two-files/foo.m @@ -0,0 +1,28 @@ +#import + +NSMutableArray * +GetArray () +{ + static NSMutableArray *the_array = NULL; + if (the_array == NULL) + the_array = [[NSMutableArray alloc] init]; + return the_array; +} + +int +AddElement (char *value) +{ + NSString *element = [NSString stringWithUTF8String: value]; + int cur_elem = [GetArray() count]; + [GetArray() addObject: element]; + return cur_elem; +} + +const char * +GetElement (int idx) +{ + if (idx >= [GetArray() count]) + return NULL; + else + return [[GetArray() objectAtIndex: idx] UTF8String]; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/two-files/main.m =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/two-files/main.m +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/two-files/main.m @@ -0,0 +1,22 @@ +#import +#include + +extern int AddElement (char *value); +extern char *GetElement (int idx); +extern void *GetArray(); + +int +main () +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + int idx = AddElement ("some string"); + void *array_token = GetArray(); + + char *string = GetElement (0); // Set breakpoint here, then do 'expr (NSArray*)array_token'. + if (string) + printf ("This: %s.\n", string); + + [pool release]; + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/unicode-in-variable/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/unicode-in-variable/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/unicode-in-variable/Makefile @@ -0,0 +1,4 @@ +LEVEL = ../../make +CXX_SOURCES := main.cpp +CXX_FLAGS_EXTRA := -finput-charset=UTF-8 -fextended-identifiers +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/unicode-in-variable/TestUnicodeInVariable.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/unicode-in-variable/TestUnicodeInVariable.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/unicode-in-variable/TestUnicodeInVariable.py @@ -0,0 +1,4 @@ +from lldbsuite.test import lldbinline +from lldbsuite.test import decorators + +lldbinline.MakeInlineTest(__file__, globals(), None) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/unicode-in-variable/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/unicode-in-variable/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/unicode-in-variable/main.cpp @@ -0,0 +1,17 @@ +// Make sure we correctly handle unicode in variable names. + +struct A { + // We need a member variable in the context that could shadow our local + // variable. If our optimization code fails to handle this, then we won't + // correctly inject our local variable so that it won't get shadowed. + int foob\u00E1r = 2; + int foo() { + int foob\u00E1r = 3; + return foob\u00E1r; //%self.expect("expr foobár", substrs=['(int)', ' = 3']) + } +}; + +int main() { + A a; + return a.foo(); +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/unwind_expression/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/unwind_expression/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/unwind_expression/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/unwind_expression/TestUnwindExpression.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/unwind_expression/TestUnwindExpression.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/unwind_expression/TestUnwindExpression.py @@ -0,0 +1,101 @@ +""" +Test stopping at a breakpoint in an expression, and unwinding from there. +""" + +from __future__ import print_function + + +import unittest2 + +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__) + main_spec = lldb.SBFileSpec("main.cpp", False) + + def build_and_run_to_bkpt(self): + self.build() + + (target, process, self.thread, bkpt) = lldbutil.run_to_source_breakpoint(self, + "// Set a breakpoint here to get started", self.main_spec) + + # Next set a breakpoint in this function, set up Expression options to stop on + # breakpoint hits, and call the function. + self.fun_bkpt = self.target().BreakpointCreateBySourceRegex( + "// Stop inside the function here.", self.main_spec) + self.assertTrue(self.fun_bkpt, VALID_BREAKPOINT) + + + @no_debug_info_test + @expectedFailureAll(bugnumber="llvm.org/pr33164") + def test_conditional_bktp(self): + """ + Test conditional breakpoint handling in the IgnoreBreakpoints = False case + """ + self.build_and_run_to_bkpt() + + self.fun_bkpt.SetCondition("0") # Should not get hit + options = lldb.SBExpressionOptions() + options.SetIgnoreBreakpoints(False) + options.SetUnwindOnError(False) + + main_frame = self.thread.GetFrameAtIndex(0) + val = main_frame.EvaluateExpression("second_function(47)", options) + self.assertTrue( + val.GetError().Success(), + "We did complete the execution.") + self.assertEquals(47, val.GetValueAsSigned()) + + + @add_test_categories(['pyapi']) + @expectedFlakeyNetBSD + def test_unwind_expression(self): + """Test unwinding from an expression.""" + self.build_and_run_to_bkpt() + + # Run test with varying one thread timeouts to also test the halting + # logic in the IgnoreBreakpoints = False case + self.do_unwind_test(self.thread, self.fun_bkpt, 1000) + self.do_unwind_test(self.thread, self.fun_bkpt, 100000) + + def do_unwind_test(self, thread, bkpt, timeout): + # + # Use Python API to evaluate expressions while stopped in a stack frame. + # + main_frame = thread.GetFrameAtIndex(0) + + options = lldb.SBExpressionOptions() + options.SetIgnoreBreakpoints(False) + options.SetUnwindOnError(False) + options.SetOneThreadTimeoutInMicroSeconds(timeout) + + val = main_frame.EvaluateExpression("a_function_to_call()", options) + + self.assertTrue( + val.GetError().Fail(), + "We did not complete the execution.") + error_str = val.GetError().GetCString() + self.assertTrue( + "Execution was interrupted, reason: breakpoint" in error_str, + "And the reason was right.") + + thread = lldbutil.get_one_thread_stopped_at_breakpoint( + self.process(), 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.") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/unwind_expression/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/unwind_expression/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/unwind_expression/main.cpp @@ -0,0 +1,22 @@ +static int static_value = 0; + +int +a_function_to_call() +{ + static_value++; // Stop inside the function here. + return static_value; +} + +int second_function(int x){ + for(int i=0; i<10; ++i) { + a_function_to_call(); + } + return x; +} + +int main (int argc, char const *argv[]) +{ + a_function_to_call(); // Set a breakpoint here to get started + second_function(1); + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/vector_of_enums/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/vector_of_enums/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/vector_of_enums/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/vector_of_enums/TestVectorOfEnums.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/vector_of_enums/TestVectorOfEnums.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/vector_of_enums/TestVectorOfEnums.py @@ -0,0 +1,29 @@ +""" +Test Expression Parser regression test to ensure that we handle enums +correctly, in this case specifically std::vector of enums. +""" + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestVectorOfEnums(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @add_test_categories(["libc++"]) + def test_vector_of_enums(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, '// break here', + lldb.SBFileSpec("main.cpp", False)) + + self.expect("expr v", substrs=[ + 'size=3', + '[0] = a', + '[1] = b', + '[2] = c', + '}' + ]) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/vector_of_enums/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/vector_of_enums/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/vector_of_enums/main.cpp @@ -0,0 +1,14 @@ +#include + +enum E { +a, +b, +c, +d +} ; + +int main() { + std::vector v = {E::a, E::b, E::c}; + + return v.size(); // break here +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/weak_symbols/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/weak_symbols/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/weak_symbols/Makefile @@ -0,0 +1,26 @@ +LEVEL = ../../make +CFLAGS_EXTRAS += -std=c99 +LD_FLAGS := -dynamiclib +include $(LEVEL)/Makefile.rules + +all: a.out dylib missing + +dylib: dylib.o + $(CC) $(LD_FLAGS) -o libdylib.dylib dylib.o + +missing: dylib2.o + mkdir hidden + $(CC) $(LD_FLAGS) -o hidden/libdylib.dylib dylib2.o + +a.out: main.o dylib missing + $(CC) $(CFLAGS) -L. -ldylib main.o + +dylib.o: dylib.h $(SRCDIR)/dylib.c + $(CC) -DHAS_THEM $(CFLAGS) -c $(SRCDIR)/dylib.c + +dylib2.o: dylib.h $(SRCDIR)/dylib.c + $(CC) $(CFLAGS) -c $(SRCDIR)/dylib.c -o dylib2.o + +main.o: dylib.h $(SRCDIR)/main.c + $(CC) $(CFLAGS) -c $(SRCDIR)/main.c -fmodules -fmodules-cache-path=$(CLANG_MODULE_CACHE_DIR) + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/weak_symbols/TestWeakSymbols.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/weak_symbols/TestWeakSymbols.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/weak_symbols/TestWeakSymbols.py @@ -0,0 +1,81 @@ +""" +Test that we can compile expressions referring to +absent weak symbols from a dylib. +""" + +from __future__ import print_function + + +import os +import lldb +from lldbsuite.test import decorators +import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.lldbtest import * + + +class TestWeakSymbolsInExpressions(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + NO_DEBUG_INFO_TESTCASE = True + + @decorators.skipUnlessDarwin + def test_weak_symbol_in_expr(self): + """Tests that we can refer to weak symbols in expressions.""" + self.build() + self.main_source_file = lldb.SBFileSpec("main.c") + self.do_test() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + def run_weak_var_check (self, weak_varname, present): + # The expression will modify present_weak_int to signify which branch + # was taken. Set it to so we don't get confused by a previous run. + value = self.target.FindFirstGlobalVariable("present_weak_int") + value.SetValueFromCString("0") + if present: + correct_value = 10 + else: + correct_value = 20 + + # Note, I'm adding the "; 10" at the end of the expression to work around + # the bug that expressions with no result currently return False for Success()... + expr = "if (&" + weak_varname + " != NULL) { present_weak_int = 10; } else { present_weak_int = 20;}; 10" + result = self.frame.EvaluateExpression(expr) + self.assertTrue(result.GetError().Success(), "absent_weak_int expr failed: %s"%(result.GetError().GetCString())) + self.assertEqual(value.GetValueAsSigned(), correct_value, "Didn't change present_weak_int correctly.") + + def do_test(self): + hidden_dir = os.path.join(self.getBuildDir(), "hidden") + + launch_info = lldb.SBLaunchInfo(None) + launch_info.SetWorkingDirectory(self.getBuildDir()) + # We have to point to the hidden directory to pick up the + # version of the dylib without the weak symbols: + env_expr = self.platformContext.shlib_environment_var + "=" + hidden_dir + launch_info.SetEnvironmentEntries([env_expr], True) + + (self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, + "Set a breakpoint here", self.main_source_file, + launch_info = launch_info) + # First we have to import the Dylib module so we get the type info + # for the weak symbol. We need to add the source dir to the module + # search paths, and then run @import to introduce it into the expression + # context: + self.dbg.HandleCommand("settings set target.clang-module-search-paths " + self.getSourceDir()) + + self.frame = thread.frames[0] + self.assertTrue(self.frame.IsValid(), "Got a good frame") + options = lldb.SBExpressionOptions() + options.SetLanguage(lldb.eLanguageTypeObjC) + result = self.frame.EvaluateExpression("@import Dylib", options) + + # Now run an expression that references an absent weak symbol: + self.run_weak_var_check("absent_weak_int", False) + self.run_weak_var_check("absent_weak_function", False) + + # Make sure we can do the same thing with present weak symbols + self.run_weak_var_check("present_weak_int", True) + self.run_weak_var_check("present_weak_function", True) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/weak_symbols/dylib.h =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/weak_symbols/dylib.h +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/weak_symbols/dylib.h @@ -0,0 +1,8 @@ +extern int absent_weak_int __attribute__((weak_import)); + +extern int present_weak_int __attribute__((weak_import)); + +extern int absent_weak_function() __attribute__((weak_import)); + +extern int present_weak_function() __attribute__((weak_import)); + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/weak_symbols/dylib.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/weak_symbols/dylib.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/weak_symbols/dylib.c @@ -0,0 +1,14 @@ +#include "dylib.h" + +int present_weak_int = 10; +int present_weak_function() +{ + return present_weak_int; +} + +#if defined HAS_THEM +int absent_weak_int = 10; +int absent_weak_function() { + return absent_weak_int; +} +#endif Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/weak_symbols/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/weak_symbols/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/weak_symbols/main.c @@ -0,0 +1,23 @@ +#include "dylib.h" +#include + +int +doSomething() +{ + // Set a breakpoint here. + if (&absent_weak_int != NULL) + printf("In absent_weak_int: %d\n", absent_weak_int); + if (absent_weak_function != NULL) + printf("In absent_weak_func: %p\n", absent_weak_function); + if (&present_weak_int != NULL) + printf("In present_weak_int: %d\n", present_weak_int); + if (present_weak_function != NULL) + printf("In present_weak_func: %p\n", present_weak_function); + +} + +int +main() +{ + return doSomething(); +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/weak_symbols/module.modulemap =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/weak_symbols/module.modulemap +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/weak_symbols/module.modulemap @@ -0,0 +1,3 @@ +module Dylib { + header "dylib.h" +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/xvalue/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/xvalue/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/xvalue/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/xvalue/TestXValuePrinting.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/xvalue/TestXValuePrinting.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/xvalue/TestXValuePrinting.py @@ -0,0 +1,37 @@ +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class ExprXValuePrintingTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + self.main_source = "main.cpp" + self.main_source_spec = lldb.SBFileSpec(self.main_source) + + def do_test(self, dictionary=None): + """Printing an xvalue should work.""" + self.build(dictionary=dictionary) + + (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, + '// Break here', self.main_source_spec) + frame = thread.GetFrameAtIndex(0) + + value = frame.EvaluateExpression("foo().data") + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertEqual(value.GetValueAsSigned(), 1234) + + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765") + def test(self): + self.do_test() + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/expression/xvalue/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/expression/xvalue/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/expression/xvalue/main.cpp @@ -0,0 +1,12 @@ +struct Tmp +{ + int data = 1234; +}; + +Tmp foo() { return Tmp(); } + +int main(int argc, char const *argv[]) +{ + int something = foo().data; + return 0; // Break here +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/array/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/array/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/array/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/array/TestArray.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/array/TestArray.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/array/TestArray.py @@ -0,0 +1,31 @@ +""" +Test the output of `frame diagnose` for an array access +""" + +from __future__ import print_function + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestArray(TestBase): + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + TestBase.setUp(self) + + @skipUnlessDarwin + @skipIfDarwinEmbedded # frame diagnose doesn't work for armv7 or arm64 + def test_array(self): + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + self.runCmd("run", RUN_SUCCEEDED) + self.expect("thread list", "Thread should be stopped", + substrs=['stopped']) + self.expect( + "frame diagnose", + "Crash diagnosis was accurate", + substrs=["a[10]"]) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/array/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/array/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/array/main.c @@ -0,0 +1,9 @@ +struct Foo { + int b; + int c; +}; + +int main() { + struct Foo *a = 0; + return a[10].c; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/bad-reference/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/bad-reference/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/bad-reference/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/bad-reference/TestBadReference.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/bad-reference/TestBadReference.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/bad-reference/TestBadReference.py @@ -0,0 +1,26 @@ +""" +Test the output of `frame diagnose` for dereferencing a bad reference +""" + +from __future__ import print_function + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestBadReference(TestBase): + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + @skipIfDarwinEmbedded # frame diagnose doesn't work for armv7 or arm64 + def test_bad_reference(self): + TestBase.setUp(self) + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + self.runCmd("run", RUN_SUCCEEDED) + self.expect("thread list", "Thread should be stopped", + substrs=['stopped']) + self.expect("frame diagnose", "Crash diagnosis was accurate", "f->b") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/bad-reference/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/bad-reference/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/bad-reference/main.cpp @@ -0,0 +1,22 @@ +struct Bar { + int c; + int d; +}; + +struct Foo { + int a; + struct Bar &b; +}; + +struct Foo *GetAFoo() { + static struct Foo f = { 0, *((Bar*)0) }; + return &f; +} + +int GetSum(struct Foo *f) { + return f->a + f->b.d; +} + +int main() { + return GetSum(GetAFoo()); +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/complicated-expression/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/complicated-expression/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/complicated-expression/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/complicated-expression/TestComplicatedExpression.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/complicated-expression/TestComplicatedExpression.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/complicated-expression/TestComplicatedExpression.py @@ -0,0 +1,29 @@ +""" +Test the output of `frame diagnose` for a subexpression of a complicated expression +""" + +from __future__ import print_function + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestDiagnoseDereferenceArgument(TestBase): + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + @skipIfDarwinEmbedded # frame diagnose doesn't work for armv7 or arm64 + def test_diagnose_dereference_argument(self): + TestBase.setUp(self) + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + self.runCmd("run", RUN_SUCCEEDED) + self.expect("thread list", "Thread should be stopped", + substrs=['stopped']) + self.expect( + "frame diagnose", + "Crash diagnosis was accurate", + "f->b->d") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/complicated-expression/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/complicated-expression/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/complicated-expression/main.c @@ -0,0 +1,26 @@ +struct Bar { + int c; + int d; +}; + +struct Foo { + int a; + struct Bar *b; +}; + +struct Foo *GetAFoo() { + static struct Foo f = { 0, 0 }; + return &f; +} + +int SumTwoIntegers(int x, int y) { + return x + y; +} + +int GetSum(struct Foo *f) { + return SumTwoIntegers(f->a, f->b->d ? 0 : 1); +} + +int main() { + return GetSum(GetAFoo()); +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-argument/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-argument/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-argument/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-argument/TestDiagnoseDereferenceArgument.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-argument/TestDiagnoseDereferenceArgument.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-argument/TestDiagnoseDereferenceArgument.py @@ -0,0 +1,29 @@ +""" +Test the output of `frame diagnose` for dereferencing a function argument +""" + +from __future__ import print_function + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestDiagnoseDereferenceArgument(TestBase): + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + @skipIfDarwinEmbedded # frame diagnose doesn't work for armv7 or arm64 + def test_diagnose_dereference_argument(self): + TestBase.setUp(self) + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + self.runCmd("run", RUN_SUCCEEDED) + self.expect("thread list", "Thread should be stopped", + substrs=['stopped']) + self.expect( + "frame diagnose", + "Crash diagnosis was accurate", + "f->b->d") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-argument/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-argument/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-argument/main.c @@ -0,0 +1,22 @@ +struct Bar { + int c; + int d; +}; + +struct Foo { + int a; + struct Bar *b; +}; + +struct Foo *GetAFoo() { + static struct Foo f = { 0, 0 }; + return &f; +} + +int GetSum(struct Foo *f) { + return f->a + f->b->d; +} + +int main() { + return GetSum(GetAFoo()); +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-function-return/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-function-return/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-function-return/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-function-return/TestDiagnoseDereferenceFunctionReturn.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-function-return/TestDiagnoseDereferenceFunctionReturn.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-function-return/TestDiagnoseDereferenceFunctionReturn.py @@ -0,0 +1,32 @@ +""" +Test the output of `frame diagnose` for dereferencing a function's return value +""" + +from __future__ import print_function + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestDiagnoseDereferenceFunctionReturn(TestBase): + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + @skipIfDarwinEmbedded # frame diagnose doesn't work for armv7 or arm64 + @expectedFailureAll(oslist=['macosx'], archs=['i386'], bugnumber="rdar://28656408") + def test_diagnose_dereference_function_return(self): + TestBase.setUp(self) + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + self.runCmd("run", RUN_SUCCEEDED) + self.expect("thread list", "Thread should be stopped", + substrs=['stopped']) + self.expect( + "frame diagnose", + "Crash diagnosis was accurate", + substrs=[ + "GetAFoo", + "->b"]) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-function-return/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-function-return/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-function-return/main.c @@ -0,0 +1,12 @@ +struct Foo { + int a; + int b; +}; + +struct Foo *GetAFoo() { + return 0; +} + +int main() { + return GetAFoo()->b; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-this/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-this/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-this/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-this/TestDiagnoseDereferenceThis.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-this/TestDiagnoseDereferenceThis.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-this/TestDiagnoseDereferenceThis.py @@ -0,0 +1,29 @@ +""" +Test the output of `frame diagnose` for dereferencing `this` +""" + +from __future__ import print_function + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestDiagnoseDereferenceThis(TestBase): + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + @skipIfDarwinEmbedded # frame diagnose doesn't work for armv7 or arm64 + def test_diagnose_dereference_this(self): + TestBase.setUp(self) + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + self.runCmd("run", RUN_SUCCEEDED) + self.expect("thread list", "Thread should be stopped", + substrs=['stopped']) + self.expect( + "frame diagnose", + "Crash diagnosis was accurate", + "this->a") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-this/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-this/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-this/main.cpp @@ -0,0 +1,15 @@ +struct Foo { + int a; + int b; + int Sum() { return a + b; } +}; + +struct Foo *GetAFoo() { + return (struct Foo*)0; +} + +int main() { + struct Foo *foo = GetAFoo(); + return foo->Sum(); +} + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/inheritance/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/inheritance/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/inheritance/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/inheritance/TestDiagnoseInheritance.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/inheritance/TestDiagnoseInheritance.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/inheritance/TestDiagnoseInheritance.py @@ -0,0 +1,26 @@ +""" +Test the output of `frame diagnose` for calling virtual methods +""" + +from __future__ import print_function + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestDiagnoseInheritance(TestBase): + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + @skipIfDarwinEmbedded # frame diagnose doesn't work for armv7 or arm64 + def test_diagnose_inheritance(self): + TestBase.setUp(self) + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + self.runCmd("run", RUN_SUCCEEDED) + self.expect("thread list", "Thread should be stopped", + substrs=['stopped']) + self.expect("frame diagnose", "Crash diagnosis was accurate", "d") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/inheritance/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/inheritance/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/inheritance/main.cpp @@ -0,0 +1,69 @@ +#include +#include + +class A +{ +public: + A(int a) : + m_a(a) + { + } + virtual ~A(){} + virtual int get2() const { return m_a; } + virtual int get() const { return m_a; } +protected: + int m_a; +}; + +class B : public A +{ +public: + B(int a, int b) : + A(a), + m_b(b) + { + } + + ~B() override + { + } + + int get2() const override + { + return m_b; + } + int get() const override + { + return m_b; + } + +protected: + int m_b; +}; + +struct C +{ + C(int c) : m_c(c){} + virtual ~C(){} + int m_c; +}; + +class D : public C, public B +{ +public: + D(int a, int b, int c, int d) : + C(c), + B(a, b), + m_d(d) + { + } +protected: + int m_d; +}; +int main (int argc, char const *argv[], char const *envp[]) +{ + D *good_d = new D(1, 2, 3, 4); + D *d = nullptr; + return d->get(); +} + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/local-variable/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/local-variable/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/local-variable/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/local-variable/TestLocalVariable.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/local-variable/TestLocalVariable.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/local-variable/TestLocalVariable.py @@ -0,0 +1,26 @@ +""" +Test the output of `frame diagnose` for dereferencing a local variable +""" + +from __future__ import print_function + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestLocalVariable(TestBase): + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + @skipIfDarwinEmbedded # frame diagnose doesn't work for armv7 or arm64 + def test_local_variable(self): + TestBase.setUp(self) + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + self.runCmd("run", RUN_SUCCEEDED) + self.expect("thread list", "Thread should be stopped", + substrs=['stopped']) + self.expect("frame diagnose", "Crash diagnosis was accurate", "myInt") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/local-variable/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/local-variable/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/local-variable/main.c @@ -0,0 +1,4 @@ +int main() { + int *myInt = 0; + return *myInt; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/virtual-method-call/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/virtual-method-call/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/virtual-method-call/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/virtual-method-call/TestDiagnoseDereferenceVirtualMethodCall.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/virtual-method-call/TestDiagnoseDereferenceVirtualMethodCall.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/virtual-method-call/TestDiagnoseDereferenceVirtualMethodCall.py @@ -0,0 +1,26 @@ +""" +Test the output of `frame diagnose` for calling virtual methods +""" + +from __future__ import print_function + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestDiagnoseVirtualMethodCall(TestBase): + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + @skipIfDarwinEmbedded # frame diagnose doesn't work for armv7 or arm64 + def test_diagnose_virtual_method_call(self): + TestBase.setUp(self) + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + self.runCmd("run", RUN_SUCCEEDED) + self.expect("thread list", "Thread should be stopped", + substrs=['stopped']) + self.expect("frame diagnose", "Crash diagnosis was accurate", "foo") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/virtual-method-call/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/virtual-method-call/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/diagnose/virtual-method-call/main.cpp @@ -0,0 +1,16 @@ +class Foo { +public: + int a; + int b; + virtual int Sum() { return a + b; } +}; + +struct Foo *GetAFoo() { + return (struct Foo*)0; +} + +int main() { + struct Foo *foo = GetAFoo(); + return foo->Sum(); +} + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/language/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/language/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/language/Makefile @@ -0,0 +1,12 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp other.cpp other-2.cpp +C_SOURCES := somefunc.c + +include $(LEVEL)/Makefile.rules + +other-2.o: other-2.cpp + $(CXX) $(CFLAGS_NO_DEBUG) -c $(SRCDIR)/other-2.cpp + +somefunc.o: somefunc.c + $(CC) $(CFLAGS) -std=c99 -c $(SRCDIR)/somefunc.c Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/language/TestGuessLanguage.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/language/TestGuessLanguage.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/language/TestGuessLanguage.py @@ -0,0 +1,86 @@ +""" +Test the SB API SBFrame::GuessLanguage. +""" + +from __future__ import print_function + + +import lldb +import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * + + +class TestFrameGuessLanguage(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # If your test case doesn't stress debug info, the + # set this to true. That way it won't be run once for + # each debug info format. + NO_DEBUG_INFO_TESTCASE = True + + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr37658") + def test_guess_language(self): + """Test GuessLanguage for C and C++.""" + self.build() + self.do_test() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + def check_language(self, thread, frame_no, test_lang): + frame = thread.frames[frame_no] + self.assertTrue(frame.IsValid(), "Frame %d was not valid."%(frame_no)) + lang = frame.GuessLanguage() + self.assertEqual(lang, test_lang) + + def do_test(self): + """Test GuessLanguage for C & C++.""" + exe = self.getBuildArtifact("a.out") + + # Create a target by the debugger. + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + # Now create a breakpoint in main.c at the source matching + # "Set a breakpoint here" + breakpoint = target.BreakpointCreateBySourceRegex( + "Set breakpoint here", lldb.SBFileSpec("somefunc.c")) + self.assertTrue(breakpoint and + breakpoint.GetNumLocations() >= 1, + VALID_BREAKPOINT) + + error = lldb.SBError() + # This is the launch info. If you want to launch with arguments or + # environment variables, add them using SetArguments or + # SetEnvironmentEntries + + launch_info = lldb.SBLaunchInfo(None) + process = target.Launch(launch_info, error) + self.assertTrue(process, PROCESS_IS_VALID) + + # Did we hit our breakpoint? + from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint + threads = get_threads_stopped_at_breakpoint(process, breakpoint) + self.assertTrue( + len(threads) == 1, + "There should be a thread stopped at our breakpoint") + + # The hit count for the breakpoint should be 1. + self.assertTrue(breakpoint.GetHitCount() == 1) + + thread = threads[0] + + c_frame_language = lldb.eLanguageTypeC99 + # gcc emits DW_LANG_C89 even if -std=c99 was specified + if "gcc" in self.getCompiler(): + c_frame_language = lldb.eLanguageTypeC89 + + self.check_language(thread, 0, c_frame_language) + self.check_language(thread, 1, lldb.eLanguageTypeC_plus_plus) + self.check_language(thread, 2, lldb.eLanguageTypeC_plus_plus) + + + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/language/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/language/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/language/main.cpp @@ -0,0 +1,10 @@ +#include +#include "other.h" + +int +main() +{ + int test_var = 10; + Other::DoSomethingElse(); + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/language/other-2.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/language/other-2.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/language/other-2.cpp @@ -0,0 +1,7 @@ +#include "other.h" + +void +Other::DoSomethingElse() +{ + DoSomething(); +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/language/other.h =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/language/other.h +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/language/other.h @@ -0,0 +1,7 @@ +class Other +{ + public: + static void DoSomething(); + static void DoSomethingElse(); +}; + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/language/other.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/language/other.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/language/other.cpp @@ -0,0 +1,10 @@ +#include "other.h" + +extern "C" void some_func(); + +void +Other::DoSomething() +{ + some_func(); +} + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/language/somefunc.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/language/somefunc.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/language/somefunc.c @@ -0,0 +1,7 @@ +#include + +void +some_func() +{ + printf("Set breakpoint here."); +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/recognizer/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/recognizer/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/recognizer/Makefile @@ -0,0 +1,10 @@ +LEVEL = ../../make + +OBJC_SOURCES := main.m + +CFLAGS_EXTRAS += -g0 # No debug info. +MAKE_DSYM := NO + +include $(LEVEL)/Makefile.rules + +LDFLAGS += -framework Foundation Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/recognizer/TestFrameRecognizer.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/recognizer/TestFrameRecognizer.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/recognizer/TestFrameRecognizer.py @@ -0,0 +1,119 @@ +# encoding: utf-8 +""" +Test lldb's frame recognizers. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +import recognizer + +class FrameRecognizerTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True + + @skipUnlessDarwin + def test_frame_recognizer_1(self): + self.build() + + target = self.dbg.CreateTarget(self.getBuildArtifact("a.out")) + self.assertTrue(target, VALID_TARGET) + + self.runCmd("command script import " + os.path.join(self.getSourceDir(), "recognizer.py")) + + self.expect("frame recognizer list", + substrs=['no matching results found.']) + + self.runCmd("frame recognizer add -l recognizer.MyFrameRecognizer -s a.out -n foo") + + self.expect("frame recognizer list", + substrs=['0: recognizer.MyFrameRecognizer, module a.out, function foo']) + + self.runCmd("frame recognizer add -l recognizer.MyOtherFrameRecognizer -s a.out -n bar -x") + + self.expect("frame recognizer list", + substrs=['0: recognizer.MyFrameRecognizer, module a.out, function foo', + '1: recognizer.MyOtherFrameRecognizer, module a.out, function bar (regexp)' + ]) + + self.runCmd("frame recognizer delete 0") + + self.expect("frame recognizer list", + substrs=['1: recognizer.MyOtherFrameRecognizer, module a.out, function bar (regexp)']) + + self.runCmd("frame recognizer clear") + + self.expect("frame recognizer list", + substrs=['no matching results found.']) + + self.runCmd("frame recognizer add -l recognizer.MyFrameRecognizer -s a.out -n foo") + + lldbutil.run_break_set_by_symbol(self, "foo") + self.runCmd("r") + + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', 'stop reason = breakpoint']) + + process = target.GetProcess() + thread = process.GetSelectedThread() + frame = thread.GetSelectedFrame() + + self.assertEqual(frame.GetSymbol().GetName(), "foo") + self.assertFalse(frame.GetLineEntry().IsValid()) + + self.expect("frame variable", + substrs=['(int) a = 42', '(int) b = 56']) + + # Recognized arguments don't show up by default... + variables = frame.GetVariables(lldb.SBVariablesOptions()) + self.assertEqual(variables.GetSize(), 0) + + # ...unless you set target.display-recognized-arguments to 1... + self.runCmd("settings set target.display-recognized-arguments 1") + variables = frame.GetVariables(lldb.SBVariablesOptions()) + self.assertEqual(variables.GetSize(), 2) + + # ...and you can reset it back to 0 to hide them again... + self.runCmd("settings set target.display-recognized-arguments 0") + variables = frame.GetVariables(lldb.SBVariablesOptions()) + self.assertEqual(variables.GetSize(), 0) + + # ... or explicitly ask for them with SetIncludeRecognizedArguments(True). + opts = lldb.SBVariablesOptions() + opts.SetIncludeRecognizedArguments(True) + variables = frame.GetVariables(opts) + + self.assertEqual(variables.GetSize(), 2) + self.assertEqual(variables.GetValueAtIndex(0).name, "a") + self.assertEqual(variables.GetValueAtIndex(0).signed, 42) + self.assertEqual(variables.GetValueAtIndex(0).GetValueType(), lldb.eValueTypeVariableArgument) + self.assertEqual(variables.GetValueAtIndex(1).name, "b") + self.assertEqual(variables.GetValueAtIndex(1).signed, 56) + self.assertEqual(variables.GetValueAtIndex(1).GetValueType(), lldb.eValueTypeVariableArgument) + + self.expect("frame recognizer info 0", + substrs=['frame 0 is recognized by recognizer.MyFrameRecognizer']) + + self.expect("frame recognizer info 999", error=True, + substrs=['no frame with index 999']) + + self.expect("frame recognizer info 1", + substrs=['frame 1 not recognized by any recognizer']) + + # FIXME: The following doesn't work yet, but should be fixed. + """ + lldbutil.run_break_set_by_symbol(self, "bar") + self.runCmd("c") + + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', 'stop reason = breakpoint']) + + self.expect("frame variable -t", + substrs=['(int *) a = ']) + + self.expect("frame variable -t *a", + substrs=['*a = 78']) + """ Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/recognizer/main.m =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/recognizer/main.m +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/recognizer/main.m @@ -0,0 +1,27 @@ +//===-- main.m ------------------------------------------------*- ObjC -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#import + +void foo(int a, int b) +{ + printf("%d %d\n", a, b); +} + +void bar(int *ptr) +{ + printf("%d\n", *ptr); +} + +int main (int argc, const char * argv[]) +{ + foo(42, 56); + int i = 78; + bar(&i); + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/recognizer/recognizer.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/recognizer/recognizer.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/recognizer/recognizer.py @@ -0,0 +1,21 @@ +# encoding: utf-8 + +import lldb + +class MyFrameRecognizer(object): + def get_recognized_arguments(self, frame): + if frame.name == "foo": + arg1 = frame.EvaluateExpression("$arg1").signed + arg2 = frame.EvaluateExpression("$arg2").signed + val1 = lldb.target.CreateValueFromExpression("a", "%d" % arg1) + val2 = lldb.target.CreateValueFromExpression("b", "%d" % arg2) + return [val1, val2] + elif frame.name == "bar": + arg1 = frame.EvaluateExpression("$arg1").signed + val1 = lldb.target.CreateValueFromExpression("a", "(int *)%d" % arg1) + return [val1] + return [] + +class MyOtherFrameRecognizer(object): + def get_recognized_arguments(self, frame): + return [] Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/var-scope/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/var-scope/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/var-scope/Makefile @@ -0,0 +1,3 @@ +LEVEL = ../../make +C_SOURCES := main.c +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/var-scope/TestFrameVariableScope.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/var-scope/TestFrameVariableScope.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/var-scope/TestFrameVariableScope.py @@ -0,0 +1,5 @@ +from lldbsuite.test import lldbinline +from lldbsuite.test import decorators + +lldbinline.MakeInlineTest( + __file__, globals(), []) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/var-scope/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/var-scope/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/var-scope/main.c @@ -0,0 +1,20 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +int foo(int x, int y) { + int z = 3 + x; + return z + y; //% self.expect("frame variable -s", substrs=['ARG: (int) x = -3','ARG: (int) y = 0']) + //% self.expect("frame variable -s x", substrs=['ARG: (int) x = -3']) + //% self.expect("frame variable -s y", substrs=['ARG: (int) y = 0']) + //% self.expect("frame variable -s z", substrs=['LOCAL: (int) z = 0']) +} + +int main (int argc, char const *argv[]) +{ + return foo(-3,0); //% self.expect("frame variable -s argc argv", substrs=['ARG: (int) argc =']) +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/var/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/var/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/var/Makefile @@ -0,0 +1,6 @@ +LEVEL = ../../make + +C_SOURCES := main.c +CFLAGS_EXTRAS += -std=c99 + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/var/TestFrameVar.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/var/TestFrameVar.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/var/TestFrameVar.py @@ -0,0 +1,96 @@ +""" +Make sure the frame variable -g, -a, and -l flags work. +""" + +from __future__ import print_function + + +import lldb +import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.lldbtest import * + + +class TestFrameVar(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # If your test case doesn't stress debug info, the + # set this to true. That way it won't be run once for + # each debug info format. + NO_DEBUG_INFO_TESTCASE = True + + def test_frame_var(self): + self.build() + self.do_test() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + def do_test(self): + exe = self.getBuildArtifact("a.out") + + # Create a target by the debugger. + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + # Now create a breakpoint in main.c at the source matching + # "Set a breakpoint here" + breakpoint = target.BreakpointCreateBySourceRegex( + "Set a breakpoint here", lldb.SBFileSpec("main.c")) + self.assertTrue(breakpoint and + breakpoint.GetNumLocations() >= 1, + VALID_BREAKPOINT) + + error = lldb.SBError() + # This is the launch info. If you want to launch with arguments or + # environment variables, add them using SetArguments or + # SetEnvironmentEntries + + launch_info = lldb.SBLaunchInfo(None) + process = target.Launch(launch_info, error) + self.assertTrue(process, PROCESS_IS_VALID) + + # Did we hit our breakpoint? + from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint + threads = get_threads_stopped_at_breakpoint(process, breakpoint) + self.assertTrue( + len(threads) == 1, + "There should be a thread stopped at our breakpoint") + + # The hit count for the breakpoint should be 1. + self.assertTrue(breakpoint.GetHitCount() == 1) + + frame = threads[0].GetFrameAtIndex(0) + command_result = lldb.SBCommandReturnObject() + interp = self.dbg.GetCommandInterpreter() + + # Just get args: + result = interp.HandleCommand("frame var -l", command_result) + self.assertEqual(result, lldb.eReturnStatusSuccessFinishResult, "frame var -a didn't succeed") + output = command_result.GetOutput() + self.assertTrue("argc" in output, "Args didn't find argc") + self.assertTrue("argv" in output, "Args didn't find argv") + self.assertTrue("test_var" not in output, "Args found a local") + self.assertTrue("g_var" not in output, "Args found a global") + + # Just get locals: + result = interp.HandleCommand("frame var -a", command_result) + self.assertEqual(result, lldb.eReturnStatusSuccessFinishResult, "frame var -a didn't succeed") + output = command_result.GetOutput() + self.assertTrue("argc" not in output, "Locals found argc") + self.assertTrue("argv" not in output, "Locals found argv") + self.assertTrue("test_var" in output, "Locals didn't find test_var") + self.assertTrue("g_var" not in output, "Locals found a global") + + # Get the file statics: + result = interp.HandleCommand("frame var -l -a -g", command_result) + self.assertEqual(result, lldb.eReturnStatusSuccessFinishResult, "frame var -a didn't succeed") + output = command_result.GetOutput() + self.assertTrue("argc" not in output, "Globals found argc") + self.assertTrue("argv" not in output, "Globals found argv") + self.assertTrue("test_var" not in output, "Globals found test_var") + self.assertTrue("g_var" in output, "Globals didn't find g_var") + + + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/var/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/var/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/var/main.c @@ -0,0 +1,11 @@ +#include + +int g_var = 200; + +int +main(int argc, char **argv) +{ + int test_var = 10; + printf ("Set a breakpoint here: %d %d.\n", test_var, g_var); + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/help/TestHelp.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/help/TestHelp.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/help/TestHelp.py @@ -0,0 +1,266 @@ +""" +Test some lldb help commands. + +See also CommandInterpreter::OutputFormattedHelpText(). +""" + +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 HelpCommandTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @no_debug_info_test + def test_simplehelp(self): + """A simple test of 'help' command and its output.""" + self.expect("help", + startstr='Debugger commands:') + + self.expect("help -a", matching=False, + substrs=['next']) + + self.expect("help", matching=True, + substrs=['next']) + + @no_debug_info_test + def test_help_on_help(self): + """Testing the help on the help facility.""" + self.expect("help help", matching=True, + substrs=['--hide-aliases', + '--hide-user-commands']) + + @no_debug_info_test + def version_number_string(self): + """Helper function to find the version number string of lldb.""" + plist = os.path.join( + os.environ["LLDB_SRC"], + "resources", + "LLDB-Info.plist") + try: + CFBundleVersionSegFound = False + with open(plist, 'r') as f: + for line in f: + if CFBundleVersionSegFound: + version_line = line.strip() + import re + m = re.match("(.*)", version_line) + if m: + version = m.group(1) + return version + else: + # Unsuccessful, let's juts break out of the for + # loop. + break + + if line.find("CFBundleVersion") != -1: + # Found our match. The next line contains our version + # string, for example: + # + # 38 + CFBundleVersionSegFound = True + + except: + # Just fallthrough... + import traceback + traceback.print_exc() + + # Use None to signify that we are not able to grok the version number. + return None + + @no_debug_info_test + def test_help_arch(self): + """Test 'help arch' which should list of supported architectures.""" + self.expect("help arch", + substrs=['arm', 'x86_64', 'i386']) + + @no_debug_info_test + def test_help_version(self): + """Test 'help version' and 'version' commands.""" + self.expect("help version", + substrs=['Show the LLDB debugger version.']) + import re + version_str = self.version_number_string() + match = re.match('[0-9]+', version_str) + search_regexp = ['lldb( version|-' + (version_str if match else '[0-9]+') + ').*\n'] + + self.expect("version", + patterns=search_regexp) + + @no_debug_info_test + def test_help_should_not_crash_lldb(self): + """Command 'help disasm' should not crash lldb.""" + self.runCmd("help disasm", check=False) + self.runCmd("help unsigned-integer") + + @no_debug_info_test + def test_help_should_not_hang_emacsshell(self): + """Command 'settings set term-width 0' should not hang the help command.""" + self.expect( + "settings set term-width 0", + COMMAND_FAILED_AS_EXPECTED, + error=True, + substrs=['error: 0 is out of range, valid values must be between']) + # self.runCmd("settings set term-width 0") + self.expect("help", + startstr='Debugger commands:') + + @no_debug_info_test + def test_help_breakpoint_set(self): + """Test that 'help breakpoint set' does not print out redundant lines of: + 'breakpoint set [-s ] ...'.""" + self.expect("help breakpoint set", matching=False, + substrs=['breakpoint set [-s ]']) + + @no_debug_info_test + def test_help_image_dump_symtab_should_not_crash(self): + """Command 'help image dump symtab' should not crash lldb.""" + # 'image' is an alias for 'target modules'. + self.expect("help image dump symtab", + substrs=['dump symtab', + 'sort-order']) + + @no_debug_info_test + def test_help_image_du_sym_is_ambiguous(self): + """Command 'help image du sym' is ambiguous and spits out the list of candidates.""" + self.expect("help image du sym", + COMMAND_FAILED_AS_EXPECTED, error=True, + substrs=['error: ambiguous command image du sym', + 'symfile', + 'symtab']) + + @no_debug_info_test + def test_help_image_du_line_should_work(self): + """Command 'help image du line-table' is not ambiguous and should work.""" + # 'image' is an alias for 'target modules'. + self.expect("help image du line", substrs=[ + 'Dump the line table for one or more compilation units']) + + @no_debug_info_test + def test_help_target_variable_syntax(self): + """Command 'help target variable' should display ...""" + self.expect("help target variable", + substrs=[' [ [...]]']) + + @no_debug_info_test + def test_help_watchpoint_and_its_args(self): + """Command 'help watchpoint', 'help watchpt-id', and 'help watchpt-id-list' should work.""" + self.expect("help watchpoint", + substrs=['delete', 'disable', 'enable', 'list']) + self.expect("help watchpt-id", + substrs=['']) + self.expect("help watchpt-id-list", + substrs=['']) + + @no_debug_info_test + def test_help_watchpoint_set(self): + """Test that 'help watchpoint set' prints out 'expression' and 'variable' + as the possible subcommands.""" + self.expect("help watchpoint set", + substrs=['The following subcommands are supported:'], + patterns=['expression +--', + 'variable +--']) + + @no_debug_info_test + def test_help_po_hides_options(self): + """Test that 'help po' does not show all the options for expression""" + self.expect( + "help po", + substrs=[ + '--show-all-children', + '--object-description'], + matching=False) + + @no_debug_info_test + def test_help_run_hides_options(self): + """Test that 'help run' does not show all the options for process launch""" + self.expect("help run", + substrs=['--arch', '--environment'], matching=False) + + @no_debug_info_test + def test_help_next_shows_options(self): + """Test that 'help next' shows all the options for thread step-over""" + self.expect("help next", + substrs=['--python-class', '--run-mode'], matching=True) + + @no_debug_info_test + def test_help_provides_alternatives(self): + """Test that help on commands that don't exist provides information on additional help avenues""" + self.expect( + "help thisisnotadebuggercommand", + substrs=[ + "'thisisnotadebuggercommand' is not a known command.", + "Try 'help' to see a current list of commands.", + "Try 'apropos thisisnotadebuggercommand' for a list of related commands.", + "Try 'type lookup thisisnotadebuggercommand' for information on types, methods, functions, modules, etc."], + error=True) + + self.expect( + "help process thisisnotadebuggercommand", + substrs=[ + "'process thisisnotadebuggercommand' is not a known command.", + "Try 'help' to see a current list of commands.", + "Try 'apropos thisisnotadebuggercommand' for a list of related commands.", + "Try 'type lookup thisisnotadebuggercommand' for information on types, methods, functions, modules, etc."]) + + @no_debug_info_test + def test_custom_help_alias(self): + """Test that aliases pick up custom help text.""" + def cleanup(): + self.runCmd('command unalias afriendlyalias', check=False) + self.runCmd('command unalias averyfriendlyalias', check=False) + + self.addTearDownHook(cleanup) + self.runCmd( + 'command alias --help "I am a friendly alias" -- afriendlyalias help') + self.expect( + "help afriendlyalias", + matching=True, + substrs=['I am a friendly alias']) + self.runCmd( + 'command alias --long-help "I am a very friendly alias" -- averyfriendlyalias help') + self.expect("help averyfriendlyalias", matching=True, + substrs=['I am a very friendly alias']) + @no_debug_info_test + def test_alias_prints_origin(self): + """Test that 'help ' prints the alias origin.""" + def cleanup(): + self.runCmd('command unalias alongaliasname', check=False) + + self.addTearDownHook(cleanup) + self.runCmd('command alias alongaliasname help') + self.expect("help alongaliasna", matching=True, + substrs=["'alongaliasna' is an abbreviation for 'help'"]) + + @no_debug_info_test + def test_hidden_help(self): + self.expect("help -h", + substrs=["_regexp-bt"]) + + @no_debug_info_test + def test_help_ambiguous(self): + self.expect("help g", + substrs=["Help requested with ambiguous command name, possible completions:", + "gdb-remote", "gui"]) + + @no_debug_info_test + def test_help_unknown_flag(self): + self.expect("help -z", error=True, + substrs=["unknown or ambiguous option"]) + + @no_debug_info_test + def test_help_format_output(self): + """Test that help output reaches TerminalWidth.""" + self.runCmd( + 'settings set term-width 108') + self.expect( + "help format", + matching=True, + substrs=[' -- One of the format names']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/log/basic/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/log/basic/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/log/basic/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/log/basic/TestLogging.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/log/basic/TestLogging.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/log/basic/TestLogging.py @@ -0,0 +1,93 @@ +""" +Test lldb logging. This test just makes sure logging doesn't crash, and produces some output. +""" + +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 LogTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True + + def setUp(self): + super(LogTestCase, self).setUp() + self.log_file = self.getBuildArtifact("log-file.txt") + + def test(self): + self.build() + exe = self.getBuildArtifact("a.out") + self.expect("file " + exe, + patterns=["Current executable set to .*a.out"]) + + log_file = os.path.join(self.getBuildDir(), "lldb-commands-log.txt") + + if (os.path.exists(log_file)): + os.remove(log_file) + + # By default, Debugger::EnableLog() will set log options to + # PREPEND_THREAD_NAME + OPTION_THREADSAFE. We don't want the + # threadnames here, so we enable just threadsafe (-t). + self.runCmd("log enable -t -f '%s' lldb commands" % (log_file)) + + self.runCmd("command alias bp breakpoint") + + self.runCmd("bp set -n main") + + self.runCmd("bp l") + + self.runCmd("log disable lldb") + + self.assertTrue(os.path.isfile(log_file)) + + f = open(log_file) + log_lines = f.readlines() + f.close() + os.remove(log_file) + + self.assertGreater( + len(log_lines), + 0, + "Something was written to the log file.") + + # Check that lldb truncates its log files + def test_log_truncate(self): + # put something in our log file + with open(self.log_file, "w") as f: + for i in range(1, 1000): + f.write("bacon\n") + + self.runCmd("log enable -t -f '%s' lldb commands" % self.log_file) + self.runCmd("help log") + self.runCmd("log disable lldb") + + self.assertTrue(os.path.isfile(self.log_file)) + with open(self.log_file, "r") as f: + contents = f.read() + + # check that it got removed + self.assertEquals(contents.find("bacon"), -1) + + # Check that lldb can append to a log file + def test_log_append(self): + # put something in our log file + with open(self.log_file, "w") as f: + f.write("bacon\n") + + self.runCmd( "log enable -t -a -f '%s' lldb commands" % self.log_file) + self.runCmd("help log") + self.runCmd("log disable lldb") + + self.assertTrue(os.path.isfile(self.log_file)) + with open(self.log_file, "r") as f: + contents = f.read() + + # check that it is still there + self.assertEquals(contents.find("bacon"), 0) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/log/basic/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/log/basic/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/log/basic/main.cpp @@ -0,0 +1,61 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include +#include +#include +#include + +int +product (int x, int y) +{ + int result = x * y; + return result; +} + +int +sum (int a, int b) +{ + int result = a + b; + return result; +} + +int +strange_max (int m, int n) +{ + if (m > n) + return m; + else if (n > m) + return n; + else + return 0; +} + +int +foo (int i, int j) +{ + if (strange_max (i, j) == i) + return product (i, j); + else if (strange_max (i, j) == j) + return sum (i, j); + else + return product (sum (i, i), sum (j, j)); +} + +int +main(int argc, char const *argv[]) +{ + + int array[3]; + + array[0] = foo (1238, 78392); + array[1] = foo (379265, 23674); + array[2] = foo (872934, 234); + + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/platform/basic/TestPlatformCommand.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/platform/basic/TestPlatformCommand.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/platform/basic/TestPlatformCommand.py @@ -0,0 +1,80 @@ +""" +Test some lldb platform commands. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class PlatformCommandTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @no_debug_info_test + def test_help_platform(self): + self.runCmd("help platform") + + @no_debug_info_test + def test_list(self): + self.expect("platform list", + patterns=['^Available platforms:']) + + @no_debug_info_test + def test_process_list(self): + self.expect("platform process list", + substrs=['PID', 'TRIPLE', 'NAME']) + + @no_debug_info_test + def test_process_info_with_no_arg(self): + """This is expected to fail and to return a proper error message.""" + self.expect("platform process info", error=True, + substrs=['one or more process id(s) must be specified']) + + @no_debug_info_test + def test_status(self): + self.expect( + "platform status", + substrs=[ + 'Platform', + 'Triple', + 'OS Version', + 'Kernel', + 'Hostname']) + + @expectedFailureAll(oslist=["windows"]) + @no_debug_info_test + def test_shell(self): + """ Test that the platform shell command can invoke ls. """ + triple = self.dbg.GetSelectedPlatform().GetTriple() + if re.match(".*-.*-windows", triple): + self.expect( + "platform shell dir c:\\", substrs=[ + "Windows", "Program Files"]) + elif re.match(".*-.*-.*-android", triple): + self.expect( + "platform shell ls /", + substrs=[ + "cache", + "dev", + "system"]) + else: + self.expect("platform shell ls /", substrs=["dev", "tmp", "usr"]) + + @no_debug_info_test + def test_shell_builtin(self): + """ Test a shell built-in command (echo) """ + self.expect("platform shell echo hello lldb", + substrs=["hello lldb"]) + + # FIXME: re-enable once platform shell -t can specify the desired timeout + @no_debug_info_test + def test_shell_timeout(self): + """ Test a shell built-in command (sleep) that times out """ + self.skipTest("due to taking too long to complete.") + self.expect("platform shell sleep 15", error=True, substrs=[ + "error: timed out waiting for shell command to complete"]) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/platform/basic/TestPlatformPython.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/platform/basic/TestPlatformPython.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/platform/basic/TestPlatformPython.py @@ -0,0 +1,82 @@ +""" +Test the lldb platform Python API. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class PlatformPythonTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @add_test_categories(['pyapi']) + @no_debug_info_test + def test_platform_list(self): + """Test SBDebugger::GetNumPlatforms() & GetPlatformAtIndex() API""" + # Verify the host platform is present by default. + initial_num_platforms = self.dbg.GetNumPlatforms() + self.assertGreater(initial_num_platforms, 0) + host_platform = self.dbg.GetPlatformAtIndex(0) + self.assertTrue(host_platform.IsValid() and + host_platform.GetName() == 'host', + 'The host platform is present') + # Select another platform and verify that the platform is added to + # the platform list. + platform_idx = self.dbg.GetNumAvailablePlatforms() - 1 + if platform_idx < 1: + self.fail('No platforms other than host are available') + platform_data = self.dbg.GetAvailablePlatformInfoAtIndex(platform_idx) + platform_name = platform_data.GetValueForKey('name').GetStringValue(100) + self.assertNotEqual(platform_name, 'host') + self.dbg.SetCurrentPlatform(platform_name) + selected_platform = self.dbg.GetSelectedPlatform() + self.assertTrue(selected_platform.IsValid()) + self.assertEqual(selected_platform.GetName(), platform_name) + self.assertEqual(self.dbg.GetNumPlatforms(), initial_num_platforms + 1) + platform_found = False + for platform_idx in range(self.dbg.GetNumPlatforms()): + platform = self.dbg.GetPlatformAtIndex(platform_idx) + if platform.GetName() == platform_name: + platform_found = True + break + self.assertTrue(platform_found) + + @add_test_categories(['pyapi']) + @no_debug_info_test + def test_host_is_connected(self): + # We've already tested that this one IS the host platform. + host_platform = self.dbg.GetPlatformAtIndex(0) + self.assertTrue(host_platform.IsConnected(), "The host platform is always connected") + + + @add_test_categories(['pyapi']) + @no_debug_info_test + def test_available_platform_list(self): + """Test SBDebugger::GetNumAvailablePlatforms() and GetAvailablePlatformInfoAtIndex() API""" + num_platforms = self.dbg.GetNumAvailablePlatforms() + self.assertGreater( + num_platforms, 0, + 'There should be at least one platform available') + + for i in range(num_platforms): + platform_data = self.dbg.GetAvailablePlatformInfoAtIndex(i) + name_data = platform_data.GetValueForKey('name') + desc_data = platform_data.GetValueForKey('description') + self.assertTrue( + name_data and name_data.IsValid(), + 'Platform has a name') + self.assertEqual( + name_data.GetType(), lldb.eStructuredDataTypeString, + 'Platform name is a string') + self.assertTrue( + desc_data and desc_data.IsValid(), + 'Platform has a description') + self.assertEqual( + desc_data.GetType(), lldb.eStructuredDataTypeString, + 'Platform description is a string') Index: lldb/trunk/packages/Python/lldbsuite/test/commands/process/attach-resume/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/process/attach-resume/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/process/attach-resume/Makefile @@ -0,0 +1,7 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp +ENABLE_THREADS := YES +EXE := AttachResume + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/process/attach-resume/TestAttachResume.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/process/attach-resume/TestAttachResume.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/process/attach-resume/TestAttachResume.py @@ -0,0 +1,93 @@ +""" +Test process attach/resume. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +exe_name = "AttachResume" # Must match Makefile + + +class AttachResumeTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @skipIfRemote + @expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr19310') + @expectedFailureNetBSD + @skipIfWindows # llvm.org/pr24778, llvm.org/pr21753 + def test_attach_continue_interrupt_detach(self): + """Test attach/continue/interrupt/detach""" + self.build() + self.process_attach_continue_interrupt_detach() + + def process_attach_continue_interrupt_detach(self): + """Test attach/continue/interrupt/detach""" + + exe = self.getBuildArtifact(exe_name) + + popen = self.spawnSubprocess(exe) + self.addTearDownHook(self.cleanupSubprocesses) + + self.runCmd("process attach -p " + str(popen.pid)) + + self.setAsync(True) + listener = self.dbg.GetListener() + process = self.dbg.GetSelectedTarget().GetProcess() + + self.runCmd("c") + lldbutil.expect_state_changes( + self, listener, process, [ + lldb.eStateRunning]) + + self.runCmd("process interrupt") + lldbutil.expect_state_changes( + self, listener, process, [ + lldb.eStateStopped]) + + # be sure to continue/interrupt/continue (r204504) + self.runCmd("c") + lldbutil.expect_state_changes( + self, listener, process, [ + lldb.eStateRunning]) + + self.runCmd("process interrupt") + lldbutil.expect_state_changes( + self, listener, process, [ + lldb.eStateStopped]) + + # Second interrupt should have no effect. + self.expect( + "process interrupt", + patterns=["Process is not running"], + error=True) + + # check that this breakpoint is auto-cleared on detach (r204752) + self.runCmd("br set -f main.cpp -l %u" % + (line_number('main.cpp', '// Set breakpoint here'))) + + self.runCmd("c") + lldbutil.expect_state_changes( + self, listener, process, [ + lldb.eStateRunning, lldb.eStateStopped]) + self.expect('br list', 'Breakpoint not hit', + substrs=['hit count = 1']) + + # Make sure the breakpoint is not hit again. + self.expect("expr debugger_flag = false", substrs=[" = false"]) + + self.runCmd("c") + lldbutil.expect_state_changes( + self, listener, process, [ + lldb.eStateRunning]) + + # make sure to detach while in running state (r204759) + self.runCmd("detach") + lldbutil.expect_state_changes( + self, listener, process, [ + lldb.eStateDetached]) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/process/attach-resume/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/process/attach-resume/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/process/attach-resume/main.cpp @@ -0,0 +1,35 @@ +#include +#include + +#include +#include + +volatile bool debugger_flag = true; // The debugger will flip this to false + +void *start(void *data) +{ + int i; + size_t idx = (size_t)data; + for (i=0; i<30; i++) + { + if ( idx == 0 && debugger_flag) + std::this_thread::sleep_for(std::chrono::microseconds(1)); // Set breakpoint here + std::this_thread::sleep_for(std::chrono::seconds(1)); + } + return 0; +} + +int main(int argc, char const *argv[]) +{ + lldb_enable_attach(); + + static const size_t nthreads = 16; + std::thread threads[nthreads]; + size_t i; + + for (i=0; i + + + + com.apple.security.cs.debugger + + + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/process/attach/attach_denied/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/process/attach/attach_denied/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/process/attach/attach_denied/main.cpp @@ -0,0 +1,108 @@ +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#if defined(PTRACE_ATTACH) +#define ATTACH_REQUEST PTRACE_ATTACH +#define DETACH_REQUEST PTRACE_DETACH +#elif defined(PT_ATTACH) +#define ATTACH_REQUEST PT_ATTACH +#define DETACH_REQUEST PT_DETACH +#else +#error "Unsupported platform" +#endif + +bool writePid (const char* file_name, const pid_t pid) +{ + char *tmp_file_name = (char *)malloc(strlen(file_name) + 16); + strcpy(tmp_file_name, file_name); + strcat(tmp_file_name, "_tmp"); + int fd = open (tmp_file_name, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR); + if (fd == -1) + { + fprintf (stderr, "open(%s) failed: %s\n", tmp_file_name, strerror (errno)); + free(tmp_file_name); + return false; + } + char buffer[64]; + snprintf (buffer, sizeof(buffer), "%ld", (long)pid); + + bool res = true; + if (write (fd, buffer, strlen (buffer)) == -1) + { + fprintf (stderr, "write(%s) failed: %s\n", buffer, strerror (errno)); + res = false; + } + close (fd); + + if (rename (tmp_file_name, file_name) == -1) + { + fprintf (stderr, "rename(%s, %s) failed: %s\n", tmp_file_name, file_name, strerror (errno)); + res = false; + } + free(tmp_file_name); + + return res; +} + +void signal_handler (int) +{ +} + +int main (int argc, char const *argv[]) +{ + if (argc < 2) + { + fprintf (stderr, "invalid number of command line arguments\n"); + return 1; + } + + const pid_t pid = fork (); + if (pid == -1) + { + fprintf (stderr, "fork failed: %s\n", strerror (errno)); + return 1; + } + + if (pid > 0) + { + // Make pause call to return when a signal is received. Normally this happens when the + // test runner tries to terminate us. + signal (SIGHUP, signal_handler); + signal (SIGTERM, signal_handler); + if (ptrace (ATTACH_REQUEST, pid, NULL, 0) == -1) + { + fprintf (stderr, "ptrace(ATTACH) failed: %s\n", strerror (errno)); + } + else + { + if (writePid (argv[1], pid)) + pause (); // Waiting for the debugger trying attach to the child. + + if (ptrace (DETACH_REQUEST, pid, NULL, 0) != 0) + fprintf (stderr, "ptrace(DETACH) failed: %s\n", strerror (errno)); + } + + kill (pid, SIGTERM); + int status = 0; + if (waitpid (pid, &status, 0) == -1) + fprintf (stderr, "waitpid failed: %s\n", strerror (errno)); + } + else + { + // child inferior. + pause (); + } + + printf ("Exiting now\n"); + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/process/attach/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/process/attach/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/process/attach/main.cpp @@ -0,0 +1,20 @@ +#include + +#include +#include + +int main(int argc, char const *argv[]) { + int temp; + lldb_enable_attach(); + + // Waiting to be attached by the debugger. + temp = 0; + + while (temp < 30) // Waiting to be attached... + { + std::this_thread::sleep_for(std::chrono::seconds(2)); + temp++; + } + + printf("Exiting now\n"); +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/TestLaunchWithShellExpand.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/TestLaunchWithShellExpand.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/TestLaunchWithShellExpand.py @@ -0,0 +1,120 @@ +""" +Test that argdumper is a viable launching strategy. +""" +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class LaunchWithShellExpandTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @expectedFailureAll( + oslist=[ + "windows", + "linux", + "freebsd"], + bugnumber="llvm.org/pr24778 llvm.org/pr22627") + @skipIfDarwinEmbedded # iOS etc don't launch the binary via a shell, so arg expansion won't happen + @expectedFailureNetBSD + def test(self): + self.build() + exe = self.getBuildArtifact("a.out") + + self.runCmd("target create %s" % exe) + + # Create the target + target = self.dbg.CreateTarget(exe) + + # Create any breakpoints we need + breakpoint = target.BreakpointCreateBySourceRegex( + 'break here', lldb.SBFileSpec("main.cpp", False)) + self.assertTrue(breakpoint, VALID_BREAKPOINT) + + self.runCmd( + "process launch -X true -w %s -- fi*.tx? () > <" % + (self.getSourceDir())) + + process = self.process() + + self.assertTrue(process.GetState() == lldb.eStateStopped, + STOPPED_DUE_TO_BREAKPOINT) + + thread = process.GetThreadAtIndex(0) + + self.assertTrue(thread.IsValid(), + "Process stopped at 'main' should have a valid thread") + + stop_reason = thread.GetStopReason() + + self.assertTrue( + stop_reason == lldb.eStopReasonBreakpoint, + "Thread in process stopped in 'main' should have a stop reason of eStopReasonBreakpoint") + + self.expect("frame variable argv[1]", substrs=['file1.txt']) + self.expect("frame variable argv[2]", substrs=['file2.txt']) + self.expect("frame variable argv[3]", substrs=['file3.txt']) + self.expect("frame variable argv[4]", substrs=['file4.txy']) + self.expect("frame variable argv[5]", substrs=['()']) + self.expect("frame variable argv[6]", substrs=['>']) + self.expect("frame variable argv[7]", substrs=['<']) + self.expect( + "frame variable argv[5]", + substrs=['file5.tyx'], + matching=False) + self.expect( + "frame variable argv[8]", + substrs=['file5.tyx'], + matching=False) + + self.runCmd("process kill") + + self.runCmd( + 'process launch -X true -w %s -- "foo bar"' % + (self.getSourceDir())) + + process = self.process() + + self.assertTrue(process.GetState() == lldb.eStateStopped, + STOPPED_DUE_TO_BREAKPOINT) + + thread = process.GetThreadAtIndex(0) + + self.assertTrue(thread.IsValid(), + "Process stopped at 'main' should have a valid thread") + + stop_reason = thread.GetStopReason() + + self.assertTrue( + stop_reason == lldb.eStopReasonBreakpoint, + "Thread in process stopped in 'main' should have a stop reason of eStopReasonBreakpoint") + + self.expect("frame variable argv[1]", substrs=['foo bar']) + + self.runCmd("process kill") + + self.runCmd('process launch -X true -w %s -- foo\ bar' + % (self.getBuildDir())) + + process = self.process() + + self.assertTrue(process.GetState() == lldb.eStateStopped, + STOPPED_DUE_TO_BREAKPOINT) + + thread = process.GetThreadAtIndex(0) + + self.assertTrue(thread.IsValid(), + "Process stopped at 'main' should have a valid thread") + + stop_reason = thread.GetStopReason() + + self.assertTrue( + stop_reason == lldb.eStopReasonBreakpoint, + "Thread in process stopped in 'main' should have a stop reason of eStopReasonBreakpoint") + + self.expect("frame variable argv[1]", substrs=['foo bar']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/main.cpp @@ -0,0 +1,5 @@ +int +main (int argc, char const **argv) +{ + return 0; // break here +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch/Makefile @@ -0,0 +1,7 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp +#CXX_SOURCES := print-cwd.cpp + +include $(LEVEL)/Makefile.rules + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch/TestProcessLaunch.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch/TestProcessLaunch.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch/TestProcessLaunch.py @@ -0,0 +1,205 @@ +""" +Test lldb process launch flags. +""" + +from __future__ import print_function + +import os + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +import six + + +class ProcessLaunchTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + self.runCmd("settings set auto-confirm true") + + def tearDown(self): + self.runCmd("settings clear auto-confirm") + TestBase.tearDown(self) + + @not_remote_testsuite_ready + def test_io(self): + """Test that process launch I/O redirection flags work properly.""" + self.build() + exe = self.getBuildArtifact("a.out") + self.expect("file " + exe, + patterns=["Current executable set to .*a.out"]) + + in_file = os.path.join(self.getSourceDir(), "input-file.txt") + out_file = lldbutil.append_to_process_working_directory(self, "output-test.out") + err_file = lldbutil.append_to_process_working_directory(self, "output-test.err") + + # Make sure the output files do not exist before launching the process + try: + os.remove(out_file) + except OSError: + pass + + try: + os.remove(err_file) + except OSError: + pass + + launch_command = "process launch -i '{0}' -o '{1}' -e '{2}' -w '{3}'".format( + in_file, out_file, err_file, self.get_process_working_directory()) + + if lldb.remote_platform: + self.runCmd('platform put-file "{local}" "{remote}"'.format( + local=in_file, remote=in_file)) + + self.expect(launch_command, + patterns=["Process .* launched: .*a.out"]) + + success = True + err_msg = "" + + out = lldbutil.read_file_on_target(self, out_file) + if out != "This should go to stdout.\n": + success = False + err_msg = err_msg + " ERROR: stdout file does not contain correct output.\n" + + + err = lldbutil.read_file_on_target(self, err_file) + if err != "This should go to stderr.\n": + success = False + err_msg = err_msg + " ERROR: stderr file does not contain correct output.\n" + + if not success: + self.fail(err_msg) + + # rdar://problem/9056462 + # The process launch flag '-w' for setting the current working directory + # not working? + @not_remote_testsuite_ready + @expectedFailureAll(oslist=["linux"], bugnumber="llvm.org/pr20265") + @expectedFailureNetBSD + def test_set_working_dir_nonexisting(self): + """Test that '-w dir' fails to set the working dir when running the inferior with a dir which doesn't exist.""" + d = {'CXX_SOURCES': 'print_cwd.cpp'} + self.build(dictionary=d) + self.setTearDownCleanup(d) + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe) + + mywd = 'my_working_dir' + out_file_name = "my_working_dir_test.out" + err_file_name = "my_working_dir_test.err" + + my_working_dir_path = self.getBuildArtifact(mywd) + out_file_path = os.path.join(my_working_dir_path, out_file_name) + err_file_path = os.path.join(my_working_dir_path, err_file_name) + + # Check that we get an error when we have a nonexisting path + invalid_dir_path = mywd + 'z' + launch_command = "process launch -w %s -o %s -e %s" % ( + invalid_dir_path, out_file_path, err_file_path) + + self.expect( + launch_command, error=True, patterns=[ + "error:.* No such file or directory: %s" % + invalid_dir_path]) + + @not_remote_testsuite_ready + def test_set_working_dir_existing(self): + """Test that '-w dir' sets the working dir when running the inferior.""" + d = {'CXX_SOURCES': 'print_cwd.cpp'} + self.build(dictionary=d) + self.setTearDownCleanup(d) + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe) + + mywd = 'my_working_dir' + out_file_name = "my_working_dir_test.out" + err_file_name = "my_working_dir_test.err" + + my_working_dir_path = self.getBuildArtifact(mywd) + lldbutil.mkdir_p(my_working_dir_path) + out_file_path = os.path.join(my_working_dir_path, out_file_name) + err_file_path = os.path.join(my_working_dir_path, err_file_name) + + # Make sure the output files do not exist before launching the process + try: + os.remove(out_file_path) + os.remove(err_file_path) + except OSError: + pass + + launch_command = "process launch -w %s -o %s -e %s" % ( + my_working_dir_path, out_file_path, err_file_path) + + self.expect(launch_command, + patterns=["Process .* launched: .*a.out"]) + + success = True + err_msg = "" + + # Check to see if the 'stdout' file was created + try: + out_f = open(out_file_path) + except IOError: + success = False + err_msg = err_msg + "ERROR: stdout file was not created.\n" + else: + # Check to see if the 'stdout' file contains the right output + line = out_f.readline() + if self.TraceOn(): + print("line:", line) + if not re.search(mywd, line): + success = False + err_msg = err_msg + "The current working directory was not set correctly.\n" + out_f.close() + + # Try to delete the 'stdout' and 'stderr' files + try: + os.remove(out_file_path) + os.remove(err_file_path) + except OSError: + pass + + if not success: + self.fail(err_msg) + + def test_environment_with_special_char(self): + """Test that environment variables containing '*' and '}' are handled correctly by the inferior.""" + source = 'print_env.cpp' + d = {'CXX_SOURCES': source} + self.build(dictionary=d) + self.setTearDownCleanup(d) + exe = self.getBuildArtifact("a.out") + + evil_var = 'INIT*MIDDLE}TAIL' + + target = self.dbg.CreateTarget(exe) + main_source_spec = lldb.SBFileSpec(source) + breakpoint = target.BreakpointCreateBySourceRegex( + '// Set breakpoint here.', main_source_spec) + + process = target.LaunchSimple(None, + ['EVIL=' + evil_var], + self.get_process_working_directory()) + self.assertEqual( + process.GetState(), + lldb.eStateStopped, + PROCESS_STOPPED) + + threads = lldbutil.get_threads_stopped_at_breakpoint( + process, breakpoint) + self.assertEqual(len(threads), 1) + frame = threads[0].GetFrameAtIndex(0) + sbvalue = frame.EvaluateExpression("evil") + value = sbvalue.GetSummary().strip('"') + + self.assertEqual(value, evil_var) + process.Continue() + self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch/input-file.txt =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch/input-file.txt +++ lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch/input-file.txt @@ -0,0 +1,2 @@ +This should go to stdout. +This should go to stderr. Index: lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch/main.cpp @@ -0,0 +1,17 @@ +#include +#include + +int +main (int argc, char **argv) +{ + char buffer[1024]; + + fgets (buffer, sizeof (buffer), stdin); + fprintf (stdout, "%s", buffer); + + + fgets (buffer, sizeof (buffer), stdin); + fprintf (stderr, "%s", buffer); + + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch/print_cwd.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch/print_cwd.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch/print_cwd.cpp @@ -0,0 +1,21 @@ +#include + +#ifdef _MSC_VER +#define _CRT_NONSTDC_NO_WARNINGS +#include +#undef getcwd +#define getcwd(buffer, length) _getcwd(buffer, length) +#else +#include +#endif + +int +main (int argc, char **argv) +{ + char buffer[1024]; + + fprintf(stdout, "stdout: %s\n", getcwd(buffer, 1024)); + fprintf(stderr, "stderr: %s\n", getcwd(buffer, 1024)); + + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch/print_env.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch/print_env.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/process/launch/print_env.cpp @@ -0,0 +1,10 @@ +#include +#include +#include + +int main (int argc, char **argv) +{ + char *evil = getenv("EVIL"); + + return 0; // Set breakpoint here. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/quit/TestQuit.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/quit/TestQuit.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/quit/TestQuit.py @@ -0,0 +1,32 @@ +""" +Test lldb's quit command. +""" + +from __future__ import print_function + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class QuitCommandTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @no_debug_info_test + def test_quit_exit_code_disallow(self): + self.ci.AllowExitCodeOnQuit(False) + self.expect( + "quit 20", + substrs=[ + "error: The current driver doesn't allow custom exit codes for the quit command"], + error=True) + self.assertFalse(self.ci.HasCustomQuitExitCode()) + + @no_debug_info_test + def test_quit_exit_code_allow(self): + self.ci.AllowExitCodeOnQuit(True) + self.runCmd("quit 10", check=False) + self.assertTrue(self.ci.HasCustomQuitExitCode()) + self.assertEqual(self.ci.GetQuitStatus(), 10) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/intel_xtended_registers/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/intel_xtended_registers/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/intel_xtended_registers/Makefile @@ -0,0 +1,7 @@ +LEVEL = ../../../make + +CXX_SOURCES := main.cpp + +CFLAGS_EXTRAS += -mmpx -fcheck-pointer-bounds -fuse-ld=bfd + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/intel_xtended_registers/TestMPXRegisters.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/intel_xtended_registers/TestMPXRegisters.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/intel_xtended_registers/TestMPXRegisters.py @@ -0,0 +1,65 @@ +""" +Test the Intel(R) MPX registers. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class RegisterCommandsTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + TestBase.setUp(self) + + @skipIf(compiler="clang") + @skipIf(oslist=no_match(['linux'])) + @skipIf(archs=no_match(['i386', 'x86_64'])) + @skipIf(oslist=["linux"], compiler="gcc", compiler_version=["<", "5"]) #GCC version >= 5 supports Intel(R) MPX. + def test_mpx_registers_with_example_code(self): + """Test Intel(R) MPX registers with example code.""" + self.build() + self.mpx_registers_with_example_code() + + def mpx_registers_with_example_code(self): + """Test Intel(R) MPX registers after running example code.""" + self.line = line_number('main.cpp', '// Set a break point here.') + + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.line, num_expected_locations=1) + self.runCmd("run", RUN_SUCCEEDED) + + target = self.dbg.GetSelectedTarget() + process = target.GetProcess() + + if (process.GetState() == lldb.eStateExited): + self.skipTest("Intel(R) MPX is not supported.") + else: + self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, + substrs = ["stop reason = breakpoint 1."]) + + if self.getArchitecture() == 'x86_64': + self.expect("register read -s 3", + substrs = ['bnd0 = {0x0000000000000010 0xffffffffffffffe6}', + 'bnd1 = {0x0000000000000020 0xffffffffffffffd6}', + 'bnd2 = {0x0000000000000030 0xffffffffffffffc6}', + 'bnd3 = {0x0000000000000040 0xffffffffffffffb6}', + 'bndcfgu = {0x01 0x80 0xb5 0x76 0xff 0x7f 0x00 0x00}', + 'bndstatus = {0x02 0x80 0xb5 0x76 0xff 0x7f 0x00 0x00}']) + if self.getArchitecture() == 'i386': + self.expect("register read -s 3", + substrs = ['bnd0 = {0x0000000000000010 0x00000000ffffffe6}', + 'bnd1 = {0x0000000000000020 0x00000000ffffffd6}', + 'bnd2 = {0x0000000000000030 0x00000000ffffffc6}', + 'bnd3 = {0x0000000000000040 0x00000000ffffffb6}', + 'bndcfgu = {0x01 0xd0 0x7d 0xf7 0x00 0x00 0x00 0x00}', + 'bndstatus = {0x02 0xd0 0x7d 0xf7 0x00 0x00 0x00 0x00}']) + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/intel_xtended_registers/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/intel_xtended_registers/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/intel_xtended_registers/main.cpp @@ -0,0 +1,61 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +//// +//// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +//// See https://llvm.org/LICENSE.txt for license information. +//// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +//// +////===----------------------------------------------------------------------===// +// + +#include +#include + +int +main(int argc, char const *argv[]) +{ +// PR_MPX_ENABLE_MANAGEMENT won't be defined on linux kernel versions below 3.19 +#ifndef PR_MPX_ENABLE_MANAGEMENT + return -1; +#endif + + // This call returns 0 only if the CPU and the kernel support Intel(R) MPX. + if (prctl(PR_MPX_ENABLE_MANAGEMENT, 0, 0, 0, 0) != 0) + return -1; + +// Run Intel(R) MPX test code. +#if defined(__x86_64__) + asm("mov $16, %rax\n\t" + "mov $9, %rdx\n\t" + "bndmk (%rax,%rdx), %bnd0\n\t" + "mov $32, %rax\n\t" + "mov $9, %rdx\n\t" + "bndmk (%rax,%rdx), %bnd1\n\t" + "mov $48, %rax\n\t" + "mov $9, %rdx\n\t" + "bndmk (%rax,%rdx), %bnd2\n\t" + "mov $64, %rax\n\t" + "mov $9, %rdx\n\t" + "bndmk (%rax,%rdx), %bnd3\n\t" + "bndstx %bnd3, (%rax) \n\t" + "nop\n\t"); +#endif +#if defined(__i386__) + asm("mov $16, %eax\n\t" + "mov $9, %edx\n\t" + "bndmk (%eax,%edx), %bnd0\n\t" + "mov $32, %eax\n\t" + "mov $9, %edx\n\t" + "bndmk (%eax,%edx), %bnd1\n\t" + "mov $48, %eax\n\t" + "mov $9, %edx\n\t" + "bndmk (%eax,%edx), %bnd2\n\t" + "mov $64, %eax\n\t" + "mov $9, %edx\n\t" + "bndmk (%eax,%edx), %bnd3\n\t" + "bndstx %bnd3, (%eax)\n\t" + "nop\n\t"); +#endif + asm("nop\n\t"); // Set a break point here. + + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/intel_xtended_registers/mpx_bound_violation/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/intel_xtended_registers/mpx_bound_violation/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/intel_xtended_registers/mpx_bound_violation/Makefile @@ -0,0 +1,7 @@ +LEVEL = ../../../../make + +CXX_SOURCES := main.cpp + +CFLAGS_EXTRAS += -mmpx -fcheck-pointer-bounds -fuse-ld=bfd + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/intel_xtended_registers/mpx_bound_violation/TestBoundViolation.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/intel_xtended_registers/mpx_bound_violation/TestBoundViolation.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/intel_xtended_registers/mpx_bound_violation/TestBoundViolation.py @@ -0,0 +1,53 @@ +""" +Test the Intel(R) MPX bound violation signal. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class RegisterCommandsTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @skipIf(compiler="clang") + @skipIf(oslist=no_match(['linux'])) + @skipIf(archs=no_match(['i386', 'x86_64'])) + @skipIf(oslist=["linux"], compiler="gcc", compiler_version=["<", "5"]) #GCC version >= 5 supports Intel(R) MPX. + def test_mpx_boundary_violation(self): + """Test Intel(R) MPX bound violation signal.""" + self.build() + self.mpx_boundary_violation() + + def mpx_boundary_violation(self): + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + self.runCmd("run", RUN_SUCCEEDED) + + target = self.dbg.GetSelectedTarget() + process = target.GetProcess() + + if (process.GetState() == lldb.eStateExited): + self.skipTest("Intel(R) MPX is not supported.") + + if (process.GetState() == lldb.eStateStopped): + self.expect("thread backtrace", STOPPED_DUE_TO_SIGNAL, + substrs = ['stop reason = signal SIGSEGV: upper bound violation', + 'fault address:', 'lower bound:', 'upper bound:']) + + self.runCmd("continue") + + if (process.GetState() == lldb.eStateStopped): + self.expect("thread backtrace", STOPPED_DUE_TO_SIGNAL, + substrs = ['stop reason = signal SIGSEGV: lower bound violation', + 'fault address:', 'lower bound:', 'upper bound:']) + + self.runCmd("continue") + self.assertTrue(process.GetState() == lldb.eStateExited, + PROCESS_EXITED) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/intel_xtended_registers/mpx_bound_violation/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/intel_xtended_registers/mpx_bound_violation/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/intel_xtended_registers/mpx_bound_violation/main.cpp @@ -0,0 +1,44 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +//// +//// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +//// See https://llvm.org/LICENSE.txt for license information. +//// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +//// +////===----------------------------------------------------------------------===// +// + +#include +#include + +static void violate_upper_bound(int *ptr, int size) +{ + int i; + i = *(ptr + size); +} + +static void violate_lower_bound (int *ptr, int size) +{ + int i; + i = *(ptr - size); +} + +int +main(int argc, char const *argv[]) +{ + unsigned int rax, rbx, rcx, rdx; + int array[5]; + +// PR_MPX_ENABLE_MANAGEMENT won't be defined on linux kernel versions below 3.19 +#ifndef PR_MPX_ENABLE_MANAGEMENT + return -1; +#endif + + // This call returns 0 only if the CPU and the kernel support Intel(R) MPX. + if (prctl(PR_MPX_ENABLE_MANAGEMENT, 0, 0, 0, 0) != 0) + return -1; + + violate_upper_bound(array, 5); + violate_lower_bound(array, 5); + + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/register_command/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/register_command/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/register_command/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +CXX_SOURCES := main.cpp a.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/register_command/TestRegisters.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/register_command/TestRegisters.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/register_command/TestRegisters.py @@ -0,0 +1,505 @@ +""" +Test the 'register' command. +""" + +from __future__ import print_function + + +import os +import sys +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class RegisterCommandsTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True + + def setUp(self): + TestBase.setUp(self) + self.has_teardown = False + + def tearDown(self): + self.dbg.GetSelectedTarget().GetProcess().Destroy() + TestBase.tearDown(self) + + @skipIfiOSSimulator + @skipIf(archs=no_match(['amd64', 'arm', 'i386', 'x86_64'])) + @expectedFailureNetBSD + def test_register_commands(self): + """Test commands related to registers, in particular vector registers.""" + self.build() + self.common_setup() + + # verify that logging does not assert + self.log_enable("registers") + + self.expect("register read -a", MISSING_EXPECTED_REGISTERS, + substrs=['registers were unavailable'], matching=False) + + if self.getArchitecture() in ['amd64', 'i386', 'x86_64']: + self.runCmd("register read xmm0") + self.runCmd("register read ymm15") # may be available + self.runCmd("register read bnd0") # may be available + elif self.getArchitecture() in ['arm', 'armv7', 'armv7k', 'arm64']: + self.runCmd("register read s0") + self.runCmd("register read q15") # may be available + + self.expect( + "register read -s 4", + substrs=['invalid register set index: 4'], + error=True) + + @skipIfiOSSimulator + # Writing of mxcsr register fails, presumably due to a kernel/hardware + # problem + @skipIfTargetAndroid(archs=["i386"]) + @skipIf(archs=no_match(['amd64', 'arm', 'i386', 'x86_64'])) + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr37995") + @expectedFailureNetBSD + def test_fp_register_write(self): + """Test commands that write to registers, in particular floating-point registers.""" + self.build() + self.fp_register_write() + + @skipIfiOSSimulator + # "register read fstat" always return 0xffff + @expectedFailureAndroid(archs=["i386"]) + @skipIfFreeBSD # llvm.org/pr25057 + @skipIf(archs=no_match(['amd64', 'i386', 'x86_64'])) + @skipIfOutOfTreeDebugserver + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr37995") + @expectedFailureNetBSD + def test_fp_special_purpose_register_read(self): + """Test commands that read fpu special purpose registers.""" + self.build() + self.fp_special_purpose_register_read() + + @skipIfiOSSimulator + @skipIf(archs=no_match(['amd64', 'arm', 'i386', 'x86_64'])) + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr37683") + def test_register_expressions(self): + """Test expression evaluation with commands related to registers.""" + self.build() + self.common_setup() + + if self.getArchitecture() in ['amd64', 'i386', 'x86_64']: + gpr = "eax" + vector = "xmm0" + elif self.getArchitecture() in ['arm64', 'aarch64']: + gpr = "w0" + vector = "v0" + elif self.getArchitecture() in ['arm', 'armv7', 'armv7k']: + gpr = "r0" + vector = "q0" + + self.expect("expr/x $%s" % gpr, substrs=['unsigned int', ' = 0x']) + self.expect("expr $%s" % vector, substrs=['vector_type']) + self.expect( + "expr (unsigned int)$%s[0]" % + vector, substrs=['unsigned int']) + + if self.getArchitecture() in ['amd64', 'x86_64']: + self.expect( + "expr -- ($rax & 0xffffffff) == $eax", + substrs=['true']) + + @skipIfiOSSimulator + @skipIf(archs=no_match(['amd64', 'x86_64'])) + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr37683") + def test_convenience_registers(self): + """Test convenience registers.""" + self.build() + self.convenience_registers() + + @skipIfiOSSimulator + @skipIf(archs=no_match(['amd64', 'x86_64'])) + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr37683") + @expectedFailureNetBSD + def test_convenience_registers_with_process_attach(self): + """Test convenience registers after a 'process attach'.""" + self.build() + self.convenience_registers_with_process_attach(test_16bit_regs=False) + + @skipIfiOSSimulator + @skipIf(archs=no_match(['amd64', 'x86_64'])) + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr37683") + @expectedFailureNetBSD + def test_convenience_registers_16bit_with_process_attach(self): + """Test convenience registers after a 'process attach'.""" + self.build() + self.convenience_registers_with_process_attach(test_16bit_regs=True) + + def common_setup(self): + exe = self.getBuildArtifact("a.out") + + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Break in main(). + lldbutil.run_break_set_by_symbol( + self, "main", num_expected_locations=-1) + + 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']) + + # platform specific logging of the specified category + def log_enable(self, category): + # This intentionally checks the host platform rather than the target + # platform as logging is host side. + self.platform = "" + if (sys.platform.startswith("freebsd") or + sys.platform.startswith("linux") or + sys.platform.startswith("netbsd")): + self.platform = "posix" + + if self.platform != "": + self.log_file = self.getBuildArtifact('TestRegisters.log') + self.runCmd( + "log enable " + + self.platform + + " " + + str(category) + + " registers -v -f " + + self.log_file, + RUN_SUCCEEDED) + if not self.has_teardown: + def remove_log(self): + if os.path.exists(self.log_file): + os.remove(self.log_file) + self.has_teardown = True + self.addTearDownHook(remove_log) + + def write_and_read(self, frame, register, new_value, must_exist=True): + value = frame.FindValue(register, lldb.eValueTypeRegister) + if must_exist: + self.assertTrue( + value.IsValid(), + "finding a value for register " + + register) + elif not value.IsValid(): + return # If register doesn't exist, skip this test + + # Also test the 're' alias. + self.runCmd("re write " + register + " \'" + new_value + "\'") + self.expect( + "register read " + + register, + substrs=[ + register + + ' = ', + new_value]) + + def fp_special_purpose_register_read(self): + exe = self.getBuildArtifact("a.out") + + # Create a target by the debugger. + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + # Launch the process and stop. + self.expect("run", PROCESS_STOPPED, substrs=['stopped']) + + # Check stop reason; Should be either signal SIGTRAP or EXC_BREAKPOINT + output = self.res.GetOutput() + matched = False + substrs = [ + 'stop reason = EXC_BREAKPOINT', + 'stop reason = signal SIGTRAP'] + for str1 in substrs: + matched = output.find(str1) != -1 + with recording(self, False) as sbuf: + print("%s sub string: %s" % ('Expecting', str1), file=sbuf) + print("Matched" if matched else "Not Matched", file=sbuf) + if matched: + break + self.assertTrue(matched, STOPPED_DUE_TO_SIGNAL) + + process = target.GetProcess() + self.assertTrue(process.GetState() == lldb.eStateStopped, + PROCESS_STOPPED) + + thread = process.GetThreadAtIndex(0) + self.assertTrue(thread.IsValid(), "current thread is valid") + + currentFrame = thread.GetFrameAtIndex(0) + self.assertTrue(currentFrame.IsValid(), "current frame is valid") + + # Extract the value of fstat and ftag flag at the point just before + # we start pushing floating point values on st% register stack + value = currentFrame.FindValue("fstat", lldb.eValueTypeRegister) + error = lldb.SBError() + reg_value_fstat_initial = value.GetValueAsUnsigned(error, 0) + + self.assertTrue(error.Success(), "reading a value for fstat") + value = currentFrame.FindValue("ftag", lldb.eValueTypeRegister) + error = lldb.SBError() + reg_value_ftag_initial = value.GetValueAsUnsigned(error, 0) + + self.assertTrue(error.Success(), "reading a value for ftag") + fstat_top_pointer_initial = (reg_value_fstat_initial & 0x3800) >> 11 + + # Execute 'si' aka 'thread step-inst' instruction 5 times and with + # every execution verify the value of fstat and ftag registers + for x in range(0, 5): + # step into the next instruction to push a value on 'st' register + # stack + self.runCmd("si", RUN_SUCCEEDED) + + # Verify fstat and save it to be used for verification in next + # execution of 'si' command + if not (reg_value_fstat_initial & 0x3800): + self.expect("register read fstat", substrs=[ + 'fstat' + ' = ', str("0x%0.4x" % ((reg_value_fstat_initial & ~(0x3800)) | 0x3800))]) + reg_value_fstat_initial = ( + (reg_value_fstat_initial & ~(0x3800)) | 0x3800) + fstat_top_pointer_initial = 7 + else: + self.expect("register read fstat", substrs=[ + 'fstat' + ' = ', str("0x%0.4x" % (reg_value_fstat_initial - 0x0800))]) + reg_value_fstat_initial = (reg_value_fstat_initial - 0x0800) + fstat_top_pointer_initial -= 1 + + # Verify ftag and save it to be used for verification in next + # execution of 'si' command + self.expect( + "register read ftag", substrs=[ + 'ftag' + ' = ', str( + "0x%0.4x" % + (reg_value_ftag_initial | ( + 1 << fstat_top_pointer_initial)))]) + reg_value_ftag_initial = reg_value_ftag_initial | ( + 1 << fstat_top_pointer_initial) + + def fp_register_write(self): + exe = self.getBuildArtifact("a.out") + + # Create a target by the debugger. + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + # Launch the process, stop at the entry point. + error = lldb.SBError() + process = target.Launch( + lldb.SBListener(), + None, None, # argv, envp + None, None, None, # stdin/out/err + self.get_process_working_directory(), + 0, # launch flags + True, # stop at entry + error) + self.assertTrue(error.Success(), "Launch succeeds. Error is :" + str(error)) + + self.assertTrue( + process.GetState() == lldb.eStateStopped, + PROCESS_STOPPED) + + thread = process.GetThreadAtIndex(0) + self.assertTrue(thread.IsValid(), "current thread is valid") + + currentFrame = thread.GetFrameAtIndex(0) + self.assertTrue(currentFrame.IsValid(), "current frame is valid") + + if self.getArchitecture() in ['amd64', 'i386', 'x86_64']: + reg_list = [ + # reg value must-have + ("fcw", "0x0000ff0e", False), + ("fsw", "0x0000ff0e", False), + ("ftw", "0x0000ff0e", False), + ("ip", "0x0000ff0e", False), + ("dp", "0x0000ff0e", False), + ("mxcsr", "0x0000ff0e", False), + ("mxcsrmask", "0x0000ff0e", False), + ] + + st0regname = None + if currentFrame.FindRegister("st0").IsValid(): + st0regname = "st0" + elif currentFrame.FindRegister("stmm0").IsValid(): + st0regname = "stmm0" + if st0regname is not None: + # reg value + # must-have + reg_list.append( + (st0regname, "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x00 0x00}", True)) + reg_list.append( + ("xmm0", + "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x2f 0x2f}", + True)) + reg_list.append( + ("xmm15", + "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x0e 0x0f}", + False)) + elif self.getArchitecture() in ['arm64', 'aarch64']: + reg_list = [ + # reg value + # must-have + ("fpsr", "0xfbf79f9f", True), + ("s0", "1.25", True), + ("s31", "0.75", True), + ("d1", "123", True), + ("d17", "987", False), + ("v1", "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x2f 0x2f}", True), + ("v14", + "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x0e 0x0f}", + False), + ] + elif self.getArchitecture() in ['armv7'] and self.platformIsDarwin(): + reg_list = [ + # reg value + # must-have + ("fpsr", "0xfbf79f9f", True), + ("s0", "1.25", True), + ("s31", "0.75", True), + ("d1", "123", True), + ("d17", "987", False), + ("q1", "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x2f 0x2f}", True), + ("q14", + "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x0e 0x0f}", + False), + ] + elif self.getArchitecture() in ['arm', 'armv7k']: + reg_list = [ + # reg value + # must-have + ("fpscr", "0xfbf79f9f", True), + ("s0", "1.25", True), + ("s31", "0.75", True), + ("d1", "123", True), + ("d17", "987", False), + ("q1", "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x2f 0x2f}", True), + ("q14", + "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x0e 0x0f}", + False), + ] + + for (reg, val, must) in reg_list: + self.write_and_read(currentFrame, reg, val, must) + + if self.getArchitecture() in ['amd64', 'i386', 'x86_64']: + if st0regname is None: + self.fail("st0regname could not be determined") + self.runCmd( + "register write " + + st0regname + + " \"{0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00}\"") + self.expect( + "register read " + + st0regname + + " --format f", + substrs=[ + st0regname + + ' = 0']) + + has_avx = False + has_mpx = False + # Returns an SBValueList. + registerSets = currentFrame.GetRegisters() + for registerSet in registerSets: + if 'advanced vector extensions' in registerSet.GetName().lower(): + has_avx = True + if 'memory protection extension' in registerSet.GetName().lower(): + has_mpx = True + + if has_avx: + new_value = "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x0e 0x0f 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x0c 0x0d 0x0e 0x0f}" + self.write_and_read(currentFrame, "ymm0", new_value) + self.write_and_read(currentFrame, "ymm7", new_value) + self.expect("expr $ymm0", substrs=['vector_type']) + else: + self.runCmd("register read ymm0") + + if has_mpx: + # Test write and read for bnd0. + new_value_w = "{0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f 0x10}" + self.runCmd("register write bnd0 \'" + new_value_w + "\'") + new_value_r = "{0x0807060504030201 0x100f0e0d0c0b0a09}" + self.expect("register read bnd0", substrs = ['bnd0 = ', new_value_r]) + self.expect("expr $bnd0", substrs = ['vector_type']) + + # Test write and for bndstatus. + new_value = "{0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08}" + self.write_and_read(currentFrame, "bndstatus", new_value) + self.expect("expr $bndstatus", substrs = ['vector_type']) + else: + self.runCmd("register read bnd0") + + def convenience_registers(self): + """Test convenience registers.""" + self.common_setup() + + # The command "register read -a" does output a derived register like + # eax... + self.expect("register read -a", matching=True, + substrs=['eax']) + + # ...however, the vanilla "register read" command should not output derived registers like eax. + self.expect("register read", matching=False, + substrs=['eax']) + + # Test reading of rax and eax. + self.expect("register read rax eax", + substrs=['rax = 0x', 'eax = 0x']) + + # Now write rax with a unique bit pattern and test that eax indeed + # represents the lower half of rax. + self.runCmd("register write rax 0x1234567887654321") + self.expect("register read rax 0x1234567887654321", + substrs=['0x1234567887654321']) + + def convenience_registers_with_process_attach(self, test_16bit_regs): + """Test convenience registers after a 'process attach'.""" + exe = self.getBuildArtifact("a.out") + + # Spawn a new process + pid = self.spawnSubprocess(exe, ['wait_for_attach']).pid + self.addTearDownHook(self.cleanupSubprocesses) + + if self.TraceOn(): + print("pid of spawned process: %d" % pid) + + self.runCmd("process attach -p %d" % pid) + + # Check that "register read eax" works. + self.runCmd("register read eax") + + if self.getArchitecture() in ['amd64', 'x86_64']: + self.expect("expr -- ($rax & 0xffffffff) == $eax", + substrs=['true']) + + if test_16bit_regs: + self.expect("expr -- $ax == (($ah << 8) | $al)", + substrs=['true']) + + @skipIfiOSSimulator + @skipIf(archs=no_match(['amd64', 'arm', 'i386', 'x86_64'])) + @expectedFailureNetBSD + def test_invalid_invocation(self): + self.build() + self.common_setup() + + self.expect("register read -a arg", error=True, + substrs=["the --all option can't be used when registers names are supplied as arguments"]) + + self.expect("register read --set 0 r", error=True, + substrs=["the --set option can't be used when registers names are supplied as arguments"]) + + self.expect("register write a", error=True, + substrs=["register write takes exactly 2 arguments: "]) + self.expect("register write a b c", error=True, + substrs=["register write takes exactly 2 arguments: "]) + + @skipIfiOSSimulator + @skipIf(archs=no_match(['amd64', 'arm', 'i386', 'x86_64'])) + @expectedFailureNetBSD + def test_write_unknown_register(self): + self.build() + self.common_setup() + + self.expect("register write blub 1", error=True, + substrs=["error: Register not found for 'blub'."]) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/register_command/a.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/register_command/a.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/register_command/a.cpp @@ -0,0 +1,43 @@ +//===-- a.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#include + +long double +return_long_double (long double value) +{ +#if defined (__i386__) || defined (__x86_64__) + float a=2, b=4,c=8, d=16, e=32, f=64, k=128, l=256, add=0; + __asm__ ( + "int3 ;" + "flds %1 ;" + "flds %2 ;" + "flds %3 ;" + "flds %4 ;" + "flds %5 ;" + "flds %6 ;" + "flds %7 ;" + "faddp ;" : "=g" (add) : "g" (a), "g" (b), "g" (c), "g" (d), "g" (e), "g" (f), "g" (k), "g" (l) ); // Set break point at this line. +#endif // #if defined (__i386__) || defined (__x86_64__) + return value; +} + +long double +outer_return_long_double (long double value) +{ + long double val = return_long_double(value); + val *= 2 ; + return val; +} + +long double +outermost_return_long_double (long double value) +{ + long double val = outer_return_long_double(value); + val *= 2 ; + return val; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/register_command/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/register_command/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/register/register/register_command/main.cpp @@ -0,0 +1,35 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#include + +#include +#include + +long double outermost_return_long_double (long double my_long_double); + +int main (int argc, char const *argv[]) +{ + lldb_enable_attach(); + + char my_string[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 0}; + double my_double = 1234.5678; + long double my_long_double = 1234.5678; + + // For simplicity assume that any cmdline argument means wait for attach. + if (argc > 1) + { + volatile int wait_for_attach=1; + while (wait_for_attach) + std::this_thread::sleep_for(std::chrono::microseconds(1)); + } + + printf("my_string=%s\n", my_string); + printf("my_double=%g\n", my_double); + outermost_return_long_double (my_long_double); + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/reproducer/invalid-args/TestInvalidArgsReproducer.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/reproducer/invalid-args/TestInvalidArgsReproducer.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/reproducer/invalid-args/TestInvalidArgsReproducer.py @@ -0,0 +1,20 @@ +import lldb +from lldbsuite.test.lldbtest import * +from lldbsuite.test.decorators import * + +class ReproducerTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + TestBase.setUp(self) + + @no_debug_info_test + def test_reproducer_generate_invalid_invocation(self): + self.expect("reproducer generate f", error=True, + substrs=["'reproducer generate' takes no arguments"]) + + @no_debug_info_test + def test_reproducer_status_invalid_invocation(self): + self.expect("reproducer status f", error=True, + substrs=["'reproducer status' takes no arguments"]) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/settings/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/settings/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/settings/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/settings/TestSettings.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/settings/TestSettings.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/settings/TestSettings.py @@ -0,0 +1,602 @@ +""" +Test lldb settings command. +""" + +from __future__ import print_function + + +import os +import re +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class SettingsCommandTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True + + def test_apropos_should_also_search_settings_description(self): + """Test that 'apropos' command should also search descriptions for the settings variables.""" + + self.expect("apropos 'environment variable'", + substrs=["target.env-vars", + "environment variables", + "executable's environment"]) + + def test_append_target_env_vars(self): + """Test that 'append target.run-args' works.""" + # Append the env-vars. + self.runCmd('settings append target.env-vars MY_ENV_VAR=YES') + # And add hooks to restore the settings during tearDown(). + self.addTearDownHook( + lambda: self.runCmd("settings clear target.env-vars")) + + # Check it immediately! + self.expect('settings show target.env-vars', + substrs=['MY_ENV_VAR=YES']) + + def test_insert_before_and_after_target_run_args(self): + """Test that 'insert-before/after target.run-args' works.""" + # Set the run-args first. + self.runCmd('settings set target.run-args a b c') + # And add hooks to restore the settings during tearDown(). + self.addTearDownHook( + lambda: self.runCmd("settings clear target.run-args")) + + # Now insert-before the index-0 element with '__a__'. + self.runCmd('settings insert-before target.run-args 0 __a__') + # And insert-after the index-1 element with '__A__'. + self.runCmd('settings insert-after target.run-args 1 __A__') + # Check it immediately! + self.expect('settings show target.run-args', + substrs=['target.run-args', + '[0]: "__a__"', + '[1]: "a"', + '[2]: "__A__"', + '[3]: "b"', + '[4]: "c"']) + + def test_replace_target_run_args(self): + """Test that 'replace target.run-args' works.""" + # Set the run-args and then replace the index-0 element. + self.runCmd('settings set target.run-args a b c') + # And add hooks to restore the settings during tearDown(). + self.addTearDownHook( + lambda: self.runCmd("settings clear target.run-args")) + + # Now replace the index-0 element with 'A', instead. + self.runCmd('settings replace target.run-args 0 A') + # Check it immediately! + self.expect('settings show target.run-args', + substrs=['target.run-args (arguments) =', + '[0]: "A"', + '[1]: "b"', + '[2]: "c"']) + + def test_set_prompt(self): + """Test that 'set prompt' actually changes the prompt.""" + + # Set prompt to 'lldb2'. + self.runCmd("settings set prompt 'lldb2 '") + + # Immediately test the setting. + self.expect("settings show prompt", SETTING_MSG("prompt"), + startstr='prompt (string) = "lldb2 "') + + # The overall display should also reflect the new setting. + self.expect("settings show", SETTING_MSG("prompt"), + substrs=['prompt (string) = "lldb2 "']) + + # Use '-r' option to reset to the original default prompt. + self.runCmd("settings clear prompt") + + def test_set_term_width(self): + """Test that 'set term-width' actually changes the term-width.""" + + self.runCmd("settings set term-width 70") + + # Immediately test the setting. + self.expect("settings show term-width", SETTING_MSG("term-width"), + startstr="term-width (int) = 70") + + # The overall display should also reflect the new setting. + self.expect("settings show", SETTING_MSG("term-width"), + substrs=["term-width (int) = 70"]) + + # rdar://problem/10712130 + def test_set_frame_format(self): + """Test that 'set frame-format' with a backtick char in the format string works as well as fullpath.""" + self.build() + + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + def cleanup(): + self.runCmd( + "settings set frame-format %s" % + self.format_string, check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.runCmd("settings show frame-format") + m = re.match( + '^frame-format \(format-string\) = "(.*)\"$', + self.res.GetOutput()) + self.assertTrue(m, "Bad settings string") + self.format_string = m.group(1) + + # Change the default format to print function.name rather than + # function.name-with-args + format_string = "frame #${frame.index}: ${frame.pc}{ ${module.file.basename}\`${function.name}{${function.pc-offset}}}{ at ${line.file.fullpath}:${line.number}}{, lang=${language}}\n" + self.runCmd("settings set frame-format %s" % format_string) + + # Immediately test the setting. + self.expect("settings show frame-format", SETTING_MSG("frame-format"), + substrs=[format_string]) + + self.runCmd("breakpoint set -n main") + self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()), + RUN_SUCCEEDED) + self.expect("thread backtrace", + substrs=["`main", self.getSourceDir()]) + + def test_set_auto_confirm(self): + """Test that after 'set auto-confirm true', manual confirmation should not kick in.""" + self.build() + + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + self.runCmd("settings set auto-confirm true") + + # Immediately test the setting. + self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"), + startstr="auto-confirm (boolean) = true") + + # Now 'breakpoint delete' should just work fine without confirmation + # prompt from the command interpreter. + self.runCmd("breakpoint set -n main") + self.expect("breakpoint delete", + startstr="All breakpoints removed") + + # Restore the original setting of auto-confirm. + self.runCmd("settings clear auto-confirm") + self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"), + startstr="auto-confirm (boolean) = false") + + @skipIf(archs=no_match(['x86_64', 'i386', 'i686'])) + def test_disassembler_settings(self): + """Test that user options for the disassembler take effect.""" + self.build() + + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # AT&T syntax + self.runCmd("settings set target.x86-disassembly-flavor att") + self.runCmd("settings set target.use-hex-immediates false") + self.expect("disassemble -n numberfn", + substrs=["$90"]) + self.runCmd("settings set target.use-hex-immediates true") + self.runCmd("settings set target.hex-immediate-style c") + self.expect("disassemble -n numberfn", + substrs=["$0x5a"]) + self.runCmd("settings set target.hex-immediate-style asm") + self.expect("disassemble -n numberfn", + substrs=["$5ah"]) + + # Intel syntax + self.runCmd("settings set target.x86-disassembly-flavor intel") + self.runCmd("settings set target.use-hex-immediates false") + self.expect("disassemble -n numberfn", + substrs=["90"]) + self.runCmd("settings set target.use-hex-immediates true") + self.runCmd("settings set target.hex-immediate-style c") + self.expect("disassemble -n numberfn", + substrs=["0x5a"]) + self.runCmd("settings set target.hex-immediate-style asm") + self.expect("disassemble -n numberfn", + substrs=["5ah"]) + + @skipIfDarwinEmbedded # debugserver on ios etc can't write files + def test_run_args_and_env_vars(self): + """Test that run-args and env-vars are passed to the launched process.""" + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Set the run-args and the env-vars. + # And add hooks to restore the settings during tearDown(). + self.runCmd('settings set target.run-args A B C') + self.addTearDownHook( + lambda: self.runCmd("settings clear target.run-args")) + self.runCmd('settings set target.env-vars ["MY_ENV_VAR"]=YES') + self.addTearDownHook( + lambda: self.runCmd("settings clear target.env-vars")) + + self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()), + RUN_SUCCEEDED) + + # Read the output file produced by running the program. + output = lldbutil.read_file_from_process_wd(self, "output2.txt") + + self.expect( + output, + exe=False, + substrs=[ + "argv[1] matches", + "argv[2] matches", + "argv[3] matches", + "Environment variable 'MY_ENV_VAR' successfully passed."]) + + @skipIfRemote # it doesn't make sense to send host env to remote target + def test_pass_host_env_vars(self): + """Test that the host env vars are passed to the launched process.""" + self.build() + + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # By default, inherit-env is 'true'. + self.expect( + 'settings show target.inherit-env', + "Default inherit-env is 'true'", + startstr="target.inherit-env (boolean) = true") + + # Set some host environment variables now. + os.environ["MY_HOST_ENV_VAR1"] = "VAR1" + os.environ["MY_HOST_ENV_VAR2"] = "VAR2" + + # This is the function to unset the two env variables set above. + def unset_env_variables(): + os.environ.pop("MY_HOST_ENV_VAR1") + os.environ.pop("MY_HOST_ENV_VAR2") + + self.addTearDownHook(unset_env_variables) + self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()), + RUN_SUCCEEDED) + + # Read the output file produced by running the program. + output = lldbutil.read_file_from_process_wd(self, "output1.txt") + + self.expect( + output, + exe=False, + substrs=[ + "The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.", + "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."]) + + @skipIfDarwinEmbedded # debugserver on ios etc can't write files + def test_set_error_output_path(self): + """Test that setting target.error/output-path for the launched process works.""" + self.build() + + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Set the error-path and output-path and verify both are set. + self.runCmd("settings set target.error-path '{0}'".format( + lldbutil.append_to_process_working_directory(self, "stderr.txt"))) + self.runCmd("settings set target.output-path '{0}".format( + lldbutil.append_to_process_working_directory(self, "stdout.txt"))) + # And add hooks to restore the original settings during tearDown(). + self.addTearDownHook( + lambda: self.runCmd("settings clear target.output-path")) + self.addTearDownHook( + lambda: self.runCmd("settings clear target.error-path")) + + self.expect("settings show target.error-path", + SETTING_MSG("target.error-path"), + substrs=['target.error-path (file)', 'stderr.txt"']) + + self.expect("settings show target.output-path", + SETTING_MSG("target.output-path"), + substrs=['target.output-path (file)', 'stdout.txt"']) + + self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()), + RUN_SUCCEEDED) + + output = lldbutil.read_file_from_process_wd(self, "stderr.txt") + message = "This message should go to standard error." + if lldbplatformutil.hasChattyStderr(self): + self.expect(output, exe=False, substrs=[message]) + else: + self.expect(output, exe=False, startstr=message) + + output = lldbutil.read_file_from_process_wd(self, "stdout.txt") + self.expect(output, exe=False, + startstr="This message should go to standard out.") + + def test_print_dictionary_setting(self): + self.runCmd("settings clear target.env-vars") + self.runCmd("settings set target.env-vars [\"MY_VAR\"]=some-value") + self.expect("settings show target.env-vars", + substrs=["MY_VAR=some-value"]) + self.runCmd("settings clear target.env-vars") + + def test_print_array_setting(self): + self.runCmd("settings clear target.run-args") + self.runCmd("settings set target.run-args gobbledy-gook") + self.expect("settings show target.run-args", + substrs=['[0]: "gobbledy-gook"']) + self.runCmd("settings clear target.run-args") + + def test_settings_with_quotes(self): + self.runCmd("settings clear target.run-args") + self.runCmd("settings set target.run-args a b c") + self.expect("settings show target.run-args", + substrs=['[0]: "a"', + '[1]: "b"', + '[2]: "c"']) + self.runCmd("settings set target.run-args 'a b c'") + self.expect("settings show target.run-args", + substrs=['[0]: "a b c"']) + self.runCmd("settings clear target.run-args") + self.runCmd("settings clear target.env-vars") + self.runCmd( + 'settings set target.env-vars ["MY_FILE"]="this is a file name with spaces.txt"') + self.expect("settings show target.env-vars", + substrs=['MY_FILE=this is a file name with spaces.txt']) + self.runCmd("settings clear target.env-vars") + # Test and make sure that setting "format-string" settings obeys quotes + # if they are provided + self.runCmd("settings set thread-format 'abc def' ") + self.expect("settings show thread-format", + 'thread-format (format-string) = "abc def"') + self.runCmd('settings set thread-format "abc def" ') + self.expect("settings show thread-format", + 'thread-format (format-string) = "abc def"') + # Make sure when no quotes are provided that we maintain any trailing + # spaces + self.runCmd('settings set thread-format abc def ') + self.expect("settings show thread-format", + 'thread-format (format-string) = "abc def "') + self.runCmd('settings clear thread-format') + + def test_settings_with_trailing_whitespace(self): + + # boolean + # Set to known value + self.runCmd("settings set target.skip-prologue true") + # Set to new value with trailing whitespace + self.runCmd("settings set target.skip-prologue false ") + # Make sure the setting was correctly set to "false" + self.expect( + "settings show target.skip-prologue", + SETTING_MSG("target.skip-prologue"), + startstr="target.skip-prologue (boolean) = false") + self.runCmd("settings clear target.skip-prologue", check=False) + # integer + self.runCmd("settings set term-width 70") # Set to known value + # Set to new value with trailing whitespaces + self.runCmd("settings set term-width 60 \t") + self.expect("settings show term-width", SETTING_MSG("term-width"), + startstr="term-width (int) = 60") + self.runCmd("settings clear term-width", check=False) + # string + self.runCmd("settings set target.arg0 abc") # Set to known value + # Set to new value with trailing whitespaces + self.runCmd("settings set target.arg0 cde\t ") + self.expect("settings show target.arg0", SETTING_MSG("target.arg0"), + startstr='target.arg0 (string) = "cde"') + self.runCmd("settings clear target.arg0", check=False) + # file + path1 = self.getBuildArtifact("path1.txt") + path2 = self.getBuildArtifact("path2.txt") + self.runCmd( + "settings set target.output-path %s" % + path1) # Set to known value + self.expect( + "settings show target.output-path", + SETTING_MSG("target.output-path"), + startstr='target.output-path (file) = ', + substrs=[path1]) + self.runCmd("settings set target.output-path %s " % + path2) # Set to new value with trailing whitespaces + self.expect( + "settings show target.output-path", + SETTING_MSG("target.output-path"), + startstr='target.output-path (file) = ', + substrs=[path2]) + self.runCmd("settings clear target.output-path", check=False) + # enum + # Set to known value + self.runCmd("settings set stop-disassembly-display never") + # Set to new value with trailing whitespaces + self.runCmd("settings set stop-disassembly-display always ") + self.expect( + "settings show stop-disassembly-display", + SETTING_MSG("stop-disassembly-display"), + startstr='stop-disassembly-display (enum) = always') + self.runCmd("settings clear stop-disassembly-display", check=False) + # language + # Set to known value + self.runCmd("settings set target.language c89") + # Set to new value with trailing whitespace + self.runCmd("settings set target.language c11 ") + self.expect( + "settings show target.language", + SETTING_MSG("target.language"), + startstr="target.language (language) = c11") + self.runCmd("settings clear target.language", check=False) + # arguments + self.runCmd("settings set target.run-args 1 2 3") # Set to known value + # Set to new value with trailing whitespaces + self.runCmd("settings set target.run-args 3 4 5 ") + self.expect( + "settings show target.run-args", + SETTING_MSG("target.run-args"), + substrs=[ + 'target.run-args (arguments) =', + '[0]: "3"', + '[1]: "4"', + '[2]: "5"']) + self.runCmd("settings set target.run-args 1 2 3") # Set to known value + # Set to new value with trailing whitespaces + self.runCmd("settings set target.run-args 3 \ \ ") + self.expect( + "settings show target.run-args", + SETTING_MSG("target.run-args"), + substrs=[ + 'target.run-args (arguments) =', + '[0]: "3"', + '[1]: " "', + '[2]: " "']) + self.runCmd("settings clear target.run-args", check=False) + # dictionaries + self.runCmd("settings clear target.env-vars") # Set to known value + # Set to new value with trailing whitespaces + self.runCmd("settings set target.env-vars A=B C=D\t ") + self.expect( + "settings show target.env-vars", + SETTING_MSG("target.env-vars"), + substrs=[ + 'target.env-vars (dictionary of strings) =', + 'A=B', + 'C=D']) + self.runCmd("settings clear target.env-vars", check=False) + # regex + # Set to known value + self.runCmd("settings clear target.process.thread.step-avoid-regexp") + # Set to new value with trailing whitespaces + self.runCmd( + "settings set target.process.thread.step-avoid-regexp foo\\ ") + self.expect( + "settings show target.process.thread.step-avoid-regexp", + SETTING_MSG("target.process.thread.step-avoid-regexp"), + substrs=['target.process.thread.step-avoid-regexp (regex) = foo\\ ']) + self.runCmd( + "settings clear target.process.thread.step-avoid-regexp", + check=False) + # format-string + self.runCmd("settings clear disassembly-format") # Set to known value + # Set to new value with trailing whitespaces + self.runCmd("settings set disassembly-format foo ") + self.expect("settings show disassembly-format", + SETTING_MSG("disassembly-format"), + substrs=['disassembly-format (format-string) = "foo "']) + self.runCmd("settings clear disassembly-format", check=False) + + def test_settings_list(self): + # List settings (and optionally test the filter to only show 'target' settings). + self.expect("settings list target", substrs=["language", "arg0", "detach-on-error"]) + self.expect("settings list target", matching=False, substrs=["packet-timeout"]) + self.expect("settings list", substrs=["language", "arg0", "detach-on-error", "packet-timeout"]) + + def test_settings_remove_single(self): + # Set some environment variables and use 'remove' to delete them. + self.runCmd("settings set target.env-vars a=b c=d") + self.expect("settings show target.env-vars", substrs=["a=b", "c=d"]) + self.runCmd("settings remove target.env-vars a") + self.expect("settings show target.env-vars", matching=False, substrs=["a=b"]) + self.expect("settings show target.env-vars", substrs=["c=d"]) + self.runCmd("settings remove target.env-vars c") + self.expect("settings show target.env-vars", matching=False, substrs=["a=b", "c=d"]) + + def test_settings_remove_multiple(self): + self.runCmd("settings set target.env-vars a=b c=d e=f") + self.expect("settings show target.env-vars", substrs=["a=b", "c=d", "e=f"]) + self.runCmd("settings remove target.env-vars a e") + self.expect("settings show target.env-vars", matching=False, substrs=["a=b", "e=f"]) + self.expect("settings show target.env-vars", substrs=["c=d"]) + + def test_settings_remove_nonexistent_value(self): + self.expect("settings remove target.env-vars doesntexist", error=True, + substrs=["no value found named 'doesntexist'"]) + + def test_settings_remove_nonexistent_settings(self): + self.expect("settings remove doesntexist alsodoesntexist", error=True, + substrs=["error: invalid value path 'doesntexist'"]) + + def test_settings_remove_missing_arg(self): + self.expect("settings remove", error=True, + substrs=["'settings remove' takes an array or dictionary item, or"]) + + def test_settings_remove_empty_arg(self): + self.expect("settings remove ''", error=True, + substrs=["'settings remove' command requires a valid variable name"]) + + def test_all_settings_exist(self): + self.expect("settings show", + substrs=["auto-confirm", + "frame-format", + "notify-void", + "prompt", + "script-lang", + "stop-disassembly-count", + "stop-disassembly-display", + "stop-line-count-after", + "stop-line-count-before", + "stop-show-column", + "term-width", + "thread-format", + "use-external-editor", + "target.default-arch", + "target.move-to-nearest-code", + "target.expr-prefix", + "target.language", + "target.prefer-dynamic-value", + "target.enable-synthetic-value", + "target.skip-prologue", + "target.source-map", + "target.exec-search-paths", + "target.max-children-count", + "target.max-string-summary-length", + "target.breakpoints-use-platform-avoid-list", + "target.run-args", + "target.env-vars", + "target.inherit-env", + "target.input-path", + "target.output-path", + "target.error-path", + "target.disable-aslr", + "target.disable-stdio", + "target.x86-disassembly-flavor", + "target.use-hex-immediates", + "target.hex-immediate-style", + "target.process.disable-memory-cache", + "target.process.extra-startup-command", + "target.process.thread.step-avoid-regexp", + "target.process.thread.trace-thread"]) + + # settings under an ".experimental" domain should have two properties: + # 1. If the name does not exist with "experimental" in the name path, + # the name lookup should try to find it without "experimental". So + # a previously-experimental setting that has been promoted to a + # "real" setting will still be set by the original name. + # 2. Changing a setting with .experimental., name, where the setting + # does not exist either with ".experimental." or without, should + # not generate an error. So if an experimental setting is removed, + # people who may have that in their ~/.lldbinit files should not see + # any errors. + def test_experimental_settings(self): + cmdinterp = self.dbg.GetCommandInterpreter() + result = lldb.SBCommandReturnObject() + + # Set target.arg0 to a known value, check that we can retrieve it via + # the actual name and via .experimental. + self.expect('settings set target.arg0 first-value') + self.expect('settings show target.arg0', substrs=['first-value']) + self.expect('settings show target.experimental.arg0', substrs=['first-value'], error=False) + + # Set target.arg0 to a new value via a target.experimental.arg0 name, + # verify that we can read it back via both .experimental., and not. + self.expect('settings set target.experimental.arg0 second-value', error=False) + self.expect('settings show target.arg0', substrs=['second-value']) + self.expect('settings show target.experimental.arg0', substrs=['second-value'], error=False) + + # showing & setting an undefined .experimental. setting should generate no errors. + self.expect('settings show target.experimental.setting-which-does-not-exist', patterns=['^\s$'], error=False) + self.expect('settings set target.experimental.setting-which-does-not-exist true', error=False) + + # A domain component before .experimental. which does not exist should give an error + # But the code does not yet do that. + # self.expect('settings set target.setting-which-does-not-exist.experimental.arg0 true', error=True) + + # finally, confirm that trying to set a setting that does not exist still fails. + # (SHOWING a setting that does not exist does not currently yield an error.) + self.expect('settings set target.setting-which-does-not-exist true', error=True) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/settings/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/settings/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/settings/main.cpp @@ -0,0 +1,74 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include +#include +#include +#include + +int numberfn() +{ + return 0x5a; +} + +int +main(int argc, char const *argv[]) +{ + // The program writes its output to the following file: + // + // o "output1.txt" for test_pass_host_env_vars() test case + // o "output2.txt" for test_run_args_and_env_vars_with_dsym() test case + // o "output2.txt" for test_run_args_and_env_vars_with_dwarf() test case + std::ofstream outfile; + if (argc == 1) + outfile.open("output1.txt"); + else + outfile.open("output2.txt"); + + for (unsigned i = 0; i < argc; ++i) { + std::string theArg(argv[i]); + if (i == 1 && "A" == theArg) + outfile << "argv[1] matches\n"; + + if (i == 2 && "B" == theArg) + outfile << "argv[2] matches\n"; + + if (i == 3 && "C" == theArg) + outfile << "argv[3] matches\n"; + } + + // For passing environment vars from the debugger to the launched process. + if (::getenv("MY_ENV_VAR")) { + std::string MY_ENV_VAR(getenv("MY_ENV_VAR")); + if ("YES" == MY_ENV_VAR) { + outfile << "Environment variable 'MY_ENV_VAR' successfully passed.\n"; + } + } + + + // For passing host environment vars to the launched process. + if (::getenv("MY_HOST_ENV_VAR1")) { + std::string MY_HOST_ENV_VAR1(getenv("MY_HOST_ENV_VAR1")); + if ("VAR1" == MY_HOST_ENV_VAR1) { + outfile << "The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.\n"; + } + } + + if (::getenv("MY_HOST_ENV_VAR2")) { + std::string MY_HOST_ENV_VAR2(getenv("MY_HOST_ENV_VAR2")); + if ("VAR2" == MY_HOST_ENV_VAR2) { + outfile << "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed.\n"; + } + } + + std::cerr << "This message should go to standard error.\n"; + std::cout << "This message should go to standard out.\n"; + + outfile.close(); + return numberfn(); +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/settings/quoting/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/settings/quoting/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/settings/quoting/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/settings/quoting/TestQuoting.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/settings/quoting/TestQuoting.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/settings/quoting/TestQuoting.py @@ -0,0 +1,94 @@ +""" +Test quoting of arguments to lldb commands +""" + +from __future__ import print_function + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class SettingsCommandTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @classmethod + def classCleanup(cls): + """Cleanup the test byproducts.""" + cls.RemoveTempFile("stdout.txt") + + @no_debug_info_test + def test_no_quote(self): + self.do_test_args("a b c", "a\0b\0c\0") + + @no_debug_info_test + def test_single_quote(self): + self.do_test_args("'a b c'", "a b c\0") + + @no_debug_info_test + def test_double_quote(self): + self.do_test_args('"a b c"', "a b c\0") + + @no_debug_info_test + def test_single_quote_escape(self): + self.do_test_args("'a b\\' c", "a b\\\0c\0") + + @no_debug_info_test + def test_double_quote_escape(self): + self.do_test_args('"a b\\" c"', 'a b" c\0') + + @no_debug_info_test + def test_double_quote_escape2(self): + self.do_test_args('"a b\\\\" c', 'a b\\\0c\0') + + @no_debug_info_test + def test_single_in_double(self): + self.do_test_args('"a\'b"', "a'b\0") + + @no_debug_info_test + def test_double_in_single(self): + self.do_test_args("'a\"b'", 'a"b\0') + + @no_debug_info_test + def test_combined(self): + self.do_test_args('"a b"c\'d e\'', 'a bcd e\0') + + @no_debug_info_test + def test_bare_single(self): + self.do_test_args("a\\'b", "a'b\0") + + @no_debug_info_test + def test_bare_double(self): + self.do_test_args('a\\"b', 'a"b\0') + + def do_test_args(self, args_in, args_out): + """Test argument parsing. Run the program with args_in. The program dumps its arguments + to stdout. Compare the stdout with args_out.""" + self.buildDefault() + + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + local_outfile = self.getBuildArtifact("output.txt") + if lldb.remote_platform: + remote_outfile = "output.txt" # Relative to platform's PWD + else: + remote_outfile = local_outfile + + self.runCmd("process launch -- %s %s" %(remote_outfile, args_in)) + + if lldb.remote_platform: + src_file_spec = lldb.SBFileSpec(remote_outfile, False) + dst_file_spec = lldb.SBFileSpec(local_outfile, True) + lldb.remote_platform.Get(src_file_spec, dst_file_spec) + + with open(local_outfile, 'r') as f: + output = f.read() + + self.RemoveTempFile(local_outfile) + + self.assertEqual(output, args_out) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/settings/quoting/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/settings/quoting/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/settings/quoting/main.c @@ -0,0 +1,21 @@ +#include +#include +#include + +/* This program writes its arguments (separated by '\0') to stdout. */ +int +main(int argc, char const *argv[]) +{ + int i; + + FILE *output = fopen (argv[1], "w"); + if (output == NULL) + exit (1); + + for (i = 2; i < argc; ++i) + fwrite(argv[i], strlen(argv[i])+1, 1, output); + + fclose (output); + + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/statistics/basic/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/statistics/basic/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/statistics/basic/Makefile @@ -0,0 +1,3 @@ +LEVEL = ../../make +C_SOURCES := main.c +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/statistics/basic/TestStats.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/statistics/basic/TestStats.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/statistics/basic/TestStats.py @@ -0,0 +1,5 @@ +from lldbsuite.test import lldbinline +from lldbsuite.test import decorators + +lldbinline.MakeInlineTest( + __file__, globals(), []) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/statistics/basic/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/statistics/basic/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/statistics/basic/main.c @@ -0,0 +1,18 @@ +// Test that the lldb command `statistics` works. + +int main(void) { + int patatino = 27; + //%self.expect("statistics disable", substrs=['need to enable statistics before disabling'], error=True) + //%self.expect("statistics enable") + //%self.expect("statistics enable", substrs=['already enabled'], error=True) + //%self.expect("expr patatino", substrs=['27']) + //%self.expect("statistics disable") + //%self.expect("statistics dump", substrs=['expr evaluation successes : 1', 'expr evaluation failures : 0']) + //%self.expect("frame var", substrs=['27']) + //%self.expect("statistics enable") + //%self.expect("frame var", substrs=['27']) + //%self.expect("statistics disable") + //%self.expect("statistics dump", substrs=['frame var successes : 1', 'frame var failures : 0']) + + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/target/basic/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/target/basic/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/target/basic/Makefile @@ -0,0 +1,8 @@ +LEVEL = ../../make + +# Example: +# +# C_SOURCES := b.c +# EXE := b.out + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/target/basic/TestTargetCommand.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/target/basic/TestTargetCommand.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/target/basic/TestTargetCommand.py @@ -0,0 +1,440 @@ +""" +Test some target commands: create, list, select, variable. +""" + +from __future__ import print_function +import os +import stat +import tempfile + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class targetCommandTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line numbers for our breakpoints. + self.line_b = line_number('b.c', '// Set break point at this line.') + self.line_c = line_number('c.c', '// Set break point at this line.') + + def buildB(self): + db = {'C_SOURCES': 'b.c', 'EXE': self.getBuildArtifact('b.out')} + self.build(dictionary=db) + self.addTearDownCleanup(dictionary=db) + + def buildAll(self): + da = {'C_SOURCES': 'a.c', 'EXE': self.getBuildArtifact('a.out')} + self.build(dictionary=da) + self.addTearDownCleanup(dictionary=da) + + self.buildB() + + dc = {'C_SOURCES': 'c.c', 'EXE': self.getBuildArtifact('c.out')} + self.build(dictionary=dc) + self.addTearDownCleanup(dictionary=dc) + + def test_target_command(self): + """Test some target commands: create, list, select.""" + self.buildAll() + self.do_target_command() + + def test_target_variable_command(self): + """Test 'target variable' command before and after starting the inferior.""" + d = {'C_SOURCES': 'globals.c', 'EXE': self.getBuildArtifact('globals')} + self.build(dictionary=d) + self.addTearDownCleanup(dictionary=d) + + self.do_target_variable_command('globals') + + def test_target_variable_command_no_fail(self): + """Test 'target variable' command before and after starting the inferior.""" + d = {'C_SOURCES': 'globals.c', 'EXE': self.getBuildArtifact('globals')} + self.build(dictionary=d) + self.addTearDownCleanup(dictionary=d) + + self.do_target_variable_command_no_fail('globals') + + def do_target_command(self): + """Exercise 'target create', 'target list', 'target select' commands.""" + exe_a = self.getBuildArtifact("a.out") + exe_b = self.getBuildArtifact("b.out") + exe_c = self.getBuildArtifact("c.out") + + self.runCmd("target list") + output = self.res.GetOutput() + if output.startswith("No targets"): + # We start from index 0. + base = 0 + else: + # Find the largest index of the existing list. + import re + pattern = re.compile("target #(\d+):") + for line in reversed(output.split(os.linesep)): + match = pattern.search(line) + if match: + # We will start from (index + 1) .... + base = int(match.group(1), 10) + 1 + #print("base is:", base) + break + + self.runCmd("target create " + exe_a, CURRENT_EXECUTABLE_SET) + self.runCmd("run", RUN_SUCCEEDED) + + self.runCmd("target create " + exe_b, CURRENT_EXECUTABLE_SET) + lldbutil.run_break_set_by_file_and_line( + self, 'b.c', self.line_b, num_expected_locations=1, loc_exact=True) + self.runCmd("run", RUN_SUCCEEDED) + + self.runCmd("target create " + exe_c, CURRENT_EXECUTABLE_SET) + lldbutil.run_break_set_by_file_and_line( + self, 'c.c', self.line_c, num_expected_locations=1, loc_exact=True) + self.runCmd("run", RUN_SUCCEEDED) + + self.runCmd("target list") + + self.runCmd("target select %d" % base) + self.runCmd("thread backtrace") + + self.runCmd("target select %d" % (base + 2)) + self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, + substrs=['c.c:%d' % self.line_c, + 'stop reason = breakpoint']) + + self.runCmd("target select %d" % (base + 1)) + self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, + substrs=['b.c:%d' % self.line_b, + 'stop reason = breakpoint']) + + self.runCmd("target list") + + def do_target_variable_command(self, exe_name): + """Exercise 'target variable' command before and after starting the inferior.""" + self.runCmd("file " + self.getBuildArtifact(exe_name), + CURRENT_EXECUTABLE_SET) + + self.expect( + "target variable my_global_char", + VARIABLES_DISPLAYED_CORRECTLY, + substrs=[ + "my_global_char", + "'X'"]) + self.expect( + "target variable my_global_str", + VARIABLES_DISPLAYED_CORRECTLY, + substrs=[ + 'my_global_str', + '"abc"']) + self.expect( + "target variable my_static_int", + VARIABLES_DISPLAYED_CORRECTLY, + substrs=[ + 'my_static_int', + '228']) + self.expect("target variable my_global_str_ptr", matching=False, + substrs=['"abc"']) + self.expect("target variable *my_global_str_ptr", matching=True, + substrs=['"abc"']) + self.expect( + "target variable *my_global_str", + VARIABLES_DISPLAYED_CORRECTLY, + substrs=['a']) + + self.runCmd("b main") + self.runCmd("run") + + self.expect( + "target variable my_global_str", + VARIABLES_DISPLAYED_CORRECTLY, + substrs=[ + 'my_global_str', + '"abc"']) + self.expect( + "target variable my_static_int", + VARIABLES_DISPLAYED_CORRECTLY, + substrs=[ + 'my_static_int', + '228']) + self.expect("target variable my_global_str_ptr", matching=False, + substrs=['"abc"']) + self.expect("target variable *my_global_str_ptr", matching=True, + substrs=['"abc"']) + self.expect( + "target variable *my_global_str", + VARIABLES_DISPLAYED_CORRECTLY, + substrs=['a']) + self.expect( + "target variable my_global_char", + VARIABLES_DISPLAYED_CORRECTLY, + substrs=[ + "my_global_char", + "'X'"]) + + self.runCmd("c") + + # rdar://problem/9763907 + # 'target variable' command fails if the target program has been run + self.expect( + "target variable my_global_str", + VARIABLES_DISPLAYED_CORRECTLY, + substrs=[ + 'my_global_str', + '"abc"']) + self.expect( + "target variable my_static_int", + VARIABLES_DISPLAYED_CORRECTLY, + substrs=[ + 'my_static_int', + '228']) + self.expect("target variable my_global_str_ptr", matching=False, + substrs=['"abc"']) + self.expect("target variable *my_global_str_ptr", matching=True, + substrs=['"abc"']) + self.expect( + "target variable *my_global_str", + VARIABLES_DISPLAYED_CORRECTLY, + substrs=['a']) + self.expect( + "target variable my_global_char", + VARIABLES_DISPLAYED_CORRECTLY, + substrs=[ + "my_global_char", + "'X'"]) + + def do_target_variable_command_no_fail(self, exe_name): + """Exercise 'target variable' command before and after starting the inferior.""" + self.runCmd("file " + self.getBuildArtifact(exe_name), + CURRENT_EXECUTABLE_SET) + + self.expect( + "target variable my_global_char", + VARIABLES_DISPLAYED_CORRECTLY, + substrs=[ + "my_global_char", + "'X'"]) + self.expect( + "target variable my_global_str", + VARIABLES_DISPLAYED_CORRECTLY, + substrs=[ + 'my_global_str', + '"abc"']) + self.expect( + "target variable my_static_int", + VARIABLES_DISPLAYED_CORRECTLY, + substrs=[ + 'my_static_int', + '228']) + self.expect("target variable my_global_str_ptr", matching=False, + substrs=['"abc"']) + self.expect("target variable *my_global_str_ptr", matching=True, + substrs=['"abc"']) + self.expect( + "target variable *my_global_str", + VARIABLES_DISPLAYED_CORRECTLY, + substrs=['a']) + + self.runCmd("b main") + self.runCmd("run") + + # New feature: you don't need to specify the variable(s) to 'target vaiable'. + # It will find all the global and static variables in the current + # compile unit. + self.expect("target variable", + substrs=['my_global_char', + 'my_global_str', + 'my_global_str_ptr', + 'my_static_int']) + + self.expect( + "target variable my_global_str", + VARIABLES_DISPLAYED_CORRECTLY, + substrs=[ + 'my_global_str', + '"abc"']) + self.expect( + "target variable my_static_int", + VARIABLES_DISPLAYED_CORRECTLY, + substrs=[ + 'my_static_int', + '228']) + self.expect("target variable my_global_str_ptr", matching=False, + substrs=['"abc"']) + self.expect("target variable *my_global_str_ptr", matching=True, + substrs=['"abc"']) + self.expect( + "target variable *my_global_str", + VARIABLES_DISPLAYED_CORRECTLY, + substrs=['a']) + self.expect( + "target variable my_global_char", + VARIABLES_DISPLAYED_CORRECTLY, + substrs=[ + "my_global_char", + "'X'"]) + + @no_debug_info_test + def test_target_stop_hook_disable_enable(self): + self.buildB() + self.runCmd("file " + self.getBuildArtifact("b.out"), CURRENT_EXECUTABLE_SET) + + self.expect("target stop-hook disable 1", error=True, substrs=['unknown stop hook id: "1"']) + self.expect("target stop-hook disable blub", error=True, substrs=['invalid stop hook id: "blub"']) + self.expect("target stop-hook enable 1", error=True, substrs=['unknown stop hook id: "1"']) + self.expect("target stop-hook enable blub", error=True, substrs=['invalid stop hook id: "blub"']) + + @no_debug_info_test + def test_target_stop_hook_delete(self): + self.buildB() + self.runCmd("file " + self.getBuildArtifact("b.out"), CURRENT_EXECUTABLE_SET) + + self.expect("target stop-hook delete 1", error=True, substrs=['unknown stop hook id: "1"']) + self.expect("target stop-hook delete blub", error=True, substrs=['invalid stop hook id: "blub"']) + + @no_debug_info_test + def test_target_list_args(self): + self.expect("target list blub", error=True, + substrs=["the 'target list' command takes no arguments"]) + + @no_debug_info_test + def test_target_select_no_index(self): + self.expect("target select", error=True, + substrs=["'target select' takes a single argument: a target index"]) + + @no_debug_info_test + def test_target_select_invalid_index(self): + self.runCmd("target delete --all") + self.expect("target select 0", error=True, + substrs=["index 0 is out of range since there are no active targets"]) + self.buildB() + self.runCmd("file " + self.getBuildArtifact("b.out"), CURRENT_EXECUTABLE_SET) + self.expect("target select 1", error=True, + substrs=["index 1 is out of range, valid target indexes are 0 - 0"]) + + + @no_debug_info_test + def test_target_create_multiple_args(self): + self.expect("target create a b", error=True, + substrs=["'target create' takes exactly one executable path"]) + + @no_debug_info_test + def test_target_create_nonexistent_core_file(self): + self.expect("target create -c doesntexist", error=True, + substrs=["core file 'doesntexist' doesn't exist"]) + + # Write only files don't seem to be supported on Windows. + @skipIfWindows + @no_debug_info_test + def test_target_create_unreadable_core_file(self): + tf = tempfile.NamedTemporaryFile() + os.chmod(tf.name, stat.S_IWRITE) + self.expect("target create -c '" + tf.name + "'", error=True, + substrs=["core file '", "' is not readable"]) + + @no_debug_info_test + def test_target_create_nonexistent_sym_file(self): + self.expect("target create -s doesntexist doesntexisteither", error=True, + substrs=["invalid symbol file path 'doesntexist'"]) + + @skipIfWindows + @no_debug_info_test + def test_target_create_invalid_core_file(self): + invalid_core_path = os.path.join(self.getSourceDir(), "invalid_core_file") + self.expect("target create -c '" + invalid_core_path + "'", error=True, + substrs=["Unable to find process plug-in for core file '"]) + + + # Write only files don't seem to be supported on Windows. + @skipIfWindows + @no_debug_info_test + def test_target_create_unreadable_sym_file(self): + tf = tempfile.NamedTemporaryFile() + os.chmod(tf.name, stat.S_IWRITE) + self.expect("target create -s '" + tf.name + "' no_exe", error=True, + substrs=["symbol file '", "' is not readable"]) + + @no_debug_info_test + def test_target_delete_all(self): + self.buildAll() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + self.runCmd("file " + self.getBuildArtifact("b.out"), CURRENT_EXECUTABLE_SET) + self.expect("target delete --all") + self.expect("target list", substrs=["No targets."]) + + @no_debug_info_test + def test_target_delete_by_index(self): + self.buildAll() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + self.runCmd("file " + self.getBuildArtifact("b.out"), CURRENT_EXECUTABLE_SET) + self.runCmd("file " + self.getBuildArtifact("c.out"), CURRENT_EXECUTABLE_SET) + self.expect("target delete 3", error=True, + substrs=["target index 3 is out of range, valid target indexes are 0 - 2"]) + + self.runCmd("target delete 1") + self.expect("target list", matching=False, substrs=["b.out"]) + self.runCmd("target delete 1") + self.expect("target list", matching=False, substrs=["c.out"]) + + self.expect("target delete 1", error=True, + substrs=["target index 1 is out of range, the only valid index is 0"]) + + self.runCmd("target delete 0") + self.expect("target list", matching=False, substrs=["a.out"]) + + self.expect("target delete 0", error=True, substrs=["no targets to delete"]) + self.expect("target delete 1", error=True, substrs=["no targets to delete"]) + + @no_debug_info_test + def test_target_delete_by_index_multiple(self): + self.buildAll() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + self.runCmd("file " + self.getBuildArtifact("b.out"), CURRENT_EXECUTABLE_SET) + self.runCmd("file " + self.getBuildArtifact("c.out"), CURRENT_EXECUTABLE_SET) + + self.expect("target delete 0 1 2 3", error=True, + substrs=["target index 3 is out of range, valid target indexes are 0 - 2"]) + self.expect("target list", substrs=["a.out", "b.out", "c.out"]) + + self.runCmd("target delete 0 1 2") + self.expect("target list", matching=False, substrs=["a.out", "c.out"]) + + @no_debug_info_test + def test_target_delete_selected(self): + self.buildAll() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + self.runCmd("file " + self.getBuildArtifact("b.out"), CURRENT_EXECUTABLE_SET) + self.runCmd("file " + self.getBuildArtifact("c.out"), CURRENT_EXECUTABLE_SET) + self.runCmd("target select 1") + self.runCmd("target delete") + self.expect("target list", matching=False, substrs=["b.out"]) + self.runCmd("target delete") + self.runCmd("target delete") + self.expect("target list", substrs=["No targets."]) + self.expect("target delete", error=True, substrs=["no target is currently selected"]) + + @no_debug_info_test + def test_target_modules_search_paths_clear(self): + self.buildB() + self.runCmd("file " + self.getBuildArtifact("b.out"), CURRENT_EXECUTABLE_SET) + self.runCmd("target modules search-paths add foo bar") + self.runCmd("target modules search-paths add foz baz") + self.runCmd("target modules search-paths clear") + self.expect("target list", matching=False, substrs=["bar", "baz"]) + + @no_debug_info_test + def test_target_modules_search_paths_query(self): + self.buildB() + self.runCmd("file " + self.getBuildArtifact("b.out"), CURRENT_EXECUTABLE_SET) + self.runCmd("target modules search-paths add foo bar") + self.expect("target modules search-paths query foo", substrs=["bar"]) + # Query something that doesn't exist. + self.expect("target modules search-paths query faz", substrs=["faz"]) + + # Invalid arguments. + self.expect("target modules search-paths query faz baz", error=True, + substrs=["query requires one argument"]) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/target/basic/a.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/target/basic/a.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/target/basic/a.c @@ -0,0 +1,15 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#include + +int main(int argc, const char* argv[]) +{ + int *null_ptr = 0; + printf("Hello, segfault!\n"); + printf("Now crash %d\n", *null_ptr); // Crash here. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/target/basic/b.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/target/basic/b.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/target/basic/b.c @@ -0,0 +1,12 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +int main (int argc, char const *argv[]) +{ + return 0; // Set break point at this line. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/target/basic/c.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/target/basic/c.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/target/basic/c.c @@ -0,0 +1,28 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#include + +int main (int argc, char const *argv[]) +{ + enum days { + Monday = 10, + Tuesday, + Wednesday, + Thursday, + Friday, + Saturday, + Sunday, + kNumDays + }; + enum days day; + for (day = Monday - 1; day <= kNumDays + 1; day++) + { + printf("day as int is %i\n", (int)day); + } + return 0; // Set break point at this line. +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/target/basic/globals.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/target/basic/globals.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/target/basic/globals.c @@ -0,0 +1,24 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#include + +char my_global_char = 'X'; +const char* my_global_str = "abc"; +const char **my_global_str_ptr = &my_global_str; +static int my_static_int = 228; + +int main (int argc, char const *argv[]) +{ + printf("global char: %c\n", my_global_char); + + printf("global str: %s\n", my_global_str); + + printf("argc + my_static_int = %d\n", (argc + my_static_int)); + + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/target/basic/invalid_core_file =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/target/basic/invalid_core_file +++ lldb/trunk/packages/Python/lldbsuite/test/commands/target/basic/invalid_core_file @@ -0,0 +1 @@ +stub Index: lldb/trunk/packages/Python/lldbsuite/test/commands/target/create-deps/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/target/create-deps/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/target/create-deps/Makefile @@ -0,0 +1,16 @@ +LEVEL := ../../make + +LIB_PREFIX := load_ + +LD_EXTRAS := -L. -l$(LIB_PREFIX)a +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules + +a.out: lib_a + +lib_%: + $(MAKE) VPATH=$(SRCDIR) -I $(SRCDIR) -f $(SRCDIR)/$*.mk + +clean:: + $(MAKE) -f $(SRCDIR)/a.mk clean Index: lldb/trunk/packages/Python/lldbsuite/test/commands/target/create-deps/TestTargetCreateDeps.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/target/create-deps/TestTargetCreateDeps.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/target/create-deps/TestTargetCreateDeps.py @@ -0,0 +1,114 @@ +""" +Test that loading of dependents works correctly for all the potential +combinations. +""" + +from __future__ import print_function + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +@skipIfWindows # Windows deals differently with shared libs. +class TargetDependentsTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + NO_DEBUG_INFO_TESTCASE = True + + def setUp(self): + TestBase.setUp(self) + self.build() + + def has_exactly_one_image(self, matching, msg=""): + self.expect( + "image list", + "image list should contain at least one image", + substrs=['[ 0]']) + should_match = not matching + self.expect( + "image list", msg, matching=should_match, substrs=['[ 1]']) + + + @expectedFailureAll(oslist=["linux"], + triple=no_match(".*-android")) + #linux does not support loading dependent files, but android does + @expectedFailureNetBSD + def test_dependents_implicit_default_exe(self): + """Test default behavior""" + exe = self.getBuildArtifact("a.out") + self.runCmd("target create " + exe, CURRENT_EXECUTABLE_SET) + self.has_exactly_one_image(False) + + @expectedFailureAll(oslist=["linux"], + triple=no_match(".*-android")) + #linux does not support loading dependent files, but android does + @expectedFailureNetBSD + def test_dependents_explicit_default_exe(self): + """Test default behavior""" + exe = self.getBuildArtifact("a.out") + self.runCmd("target create -ddefault " + exe, CURRENT_EXECUTABLE_SET) + self.has_exactly_one_image(False) + + def test_dependents_explicit_true_exe(self): + """Test default behavior""" + exe = self.getBuildArtifact("a.out") + self.runCmd("target create -dtrue " + exe, CURRENT_EXECUTABLE_SET) + self.has_exactly_one_image(True) + + @expectedFailureAll(oslist=["linux"], + triple=no_match(".*-android")) + #linux does not support loading dependent files, but android does + @expectedFailureNetBSD + def test_dependents_explicit_false_exe(self): + """Test default behavior""" + exe = self.getBuildArtifact("a.out") + self.runCmd("target create -dfalse " + exe, CURRENT_EXECUTABLE_SET) + self.has_exactly_one_image(False) + + def test_dependents_implicit_false_exe(self): + """Test default behavior""" + exe = self.getBuildArtifact("a.out") + self.runCmd("target create -d " + exe, CURRENT_EXECUTABLE_SET) + self.has_exactly_one_image(True) + + @expectedFailureAndroid # android will return mutiple images + def test_dependents_implicit_default_lib(self): + ctx = self.platformContext + dylibName = ctx.shlib_prefix + 'load_a.' + ctx.shlib_extension + lib = self.getBuildArtifact(dylibName) + self.runCmd("target create " + lib, CURRENT_EXECUTABLE_SET) + self.has_exactly_one_image(True) + + def test_dependents_explicit_default_lib(self): + ctx = self.platformContext + dylibName = ctx.shlib_prefix + 'load_a.' + ctx.shlib_extension + lib = self.getBuildArtifact(dylibName) + self.runCmd("target create -ddefault " + lib, CURRENT_EXECUTABLE_SET) + self.has_exactly_one_image(True) + + def test_dependents_explicit_true_lib(self): + ctx = self.platformContext + dylibName = ctx.shlib_prefix + 'load_a.' + ctx.shlib_extension + lib = self.getBuildArtifact(dylibName) + self.runCmd("target create -dtrue " + lib, CURRENT_EXECUTABLE_SET) + self.has_exactly_one_image(True) + + @expectedFailureAll(oslist=["linux"], + triple=no_match(".*-android")) + #linux does not support loading dependent files, but android does + @expectedFailureNetBSD + def test_dependents_explicit_false_lib(self): + ctx = self.platformContext + dylibName = ctx.shlib_prefix + 'load_a.' + ctx.shlib_extension + lib = self.getBuildArtifact(dylibName) + self.runCmd("target create -dfalse " + lib, CURRENT_EXECUTABLE_SET) + self.has_exactly_one_image(False) + + def test_dependents_implicit_false_lib(self): + ctx = self.platformContext + dylibName = ctx.shlib_prefix + 'load_a.' + ctx.shlib_extension + lib = self.getBuildArtifact(dylibName) + self.runCmd("target create -d " + lib, CURRENT_EXECUTABLE_SET) + self.has_exactly_one_image(True) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/target/create-deps/a.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/target/create-deps/a.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/target/create-deps/a.cpp @@ -0,0 +1,12 @@ +//===-- b.c -----------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +int a_function () +{ + return 500; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/target/create-deps/a.mk =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/target/create-deps/a.mk +++ lldb/trunk/packages/Python/lldbsuite/test/commands/target/create-deps/a.mk @@ -0,0 +1,9 @@ +LEVEL := ../../make + +LIB_PREFIX := load_ + +DYLIB_NAME := $(LIB_PREFIX)a +DYLIB_CXX_SOURCES := a.cpp +DYLIB_ONLY := YES + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/target/create-deps/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/target/create-deps/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/target/create-deps/main.cpp @@ -0,0 +1,16 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +extern int a_function (); +extern int b_function (); + +int +main (int argc, char const *argv[]) +{ + return a_function(); +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/target/create-no-such-arch/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/target/create-no-such-arch/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/target/create-no-such-arch/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/target/create-no-such-arch/TestNoSuchArch.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/target/create-no-such-arch/TestNoSuchArch.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/target/create-no-such-arch/TestNoSuchArch.py @@ -0,0 +1,33 @@ +""" +Test that using a non-existent architecture name does not crash LLDB. +""" +from __future__ import print_function + + +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + + +class NoSuchArchTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def test(self): + self.build() + exe = self.getBuildArtifact("a.out") + + # Check that passing an invalid arch via the command-line fails but + # doesn't crash + self.expect( + "target crete --arch nothingtoseehere %s" % + (exe), error=True) + + # Check that passing an invalid arch via the SB API fails but doesn't + # crash + target = self.dbg.CreateTargetWithFileAndArch(exe, "nothingtoseehere") + self.assertFalse(target.IsValid(), "This target should not be valid") + + # Now just create the target with the default arch and check it's fine + target = self.dbg.CreateTarget(exe) + self.assertTrue(target.IsValid(), "This target should now be valid") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/target/create-no-such-arch/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/target/create-no-such-arch/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/target/create-no-such-arch/main.cpp @@ -0,0 +1,3 @@ +int main() { + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/target/stop-hooks/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/target/stop-hooks/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/target/stop-hooks/Makefile @@ -0,0 +1,6 @@ +LEVEL = ../../make + +C_SOURCES := main.c +CFLAGS_EXTRAS += -std=c99 + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/target/stop-hooks/TestStopHooks.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/target/stop-hooks/TestStopHooks.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/target/stop-hooks/TestStopHooks.py @@ -0,0 +1,45 @@ +""" +Test that stop hooks trigger on "step-out" +""" + +from __future__ import print_function + + +import lldb +import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.lldbtest import * + + +class TestStopHooks(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # If your test case doesn't stress debug info, the + # set this to true. That way it won't be run once for + # each debug info format. + NO_DEBUG_INFO_TESTCASE = True + + def test_stop_hooks_step_out(self): + """Test that stop hooks fire on step-out.""" + self.build() + self.main_source_file = lldb.SBFileSpec("main.c") + self.step_out_test() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + def step_out_test(self): + (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, + "Set a breakpoint here", self.main_source_file) + + interp = self.dbg.GetCommandInterpreter() + result = lldb.SBCommandReturnObject() + interp.HandleCommand("target stop-hook add -o 'expr g_var++'", result) + self.assertTrue(result.Succeeded, "Set the target stop hook") + thread.StepOut() + var = target.FindFirstGlobalVariable("g_var") + self.assertTrue(var.IsValid()) + self.assertEqual(var.GetValueAsUnsigned(), 1, "Updated g_var") + + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/target/stop-hooks/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/target/stop-hooks/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/target/stop-hooks/main.c @@ -0,0 +1,14 @@ +#include + +static int g_var = 0; + +int step_out_of_me() +{ + return g_var; // Set a breakpoint here and step out. +} + +int +main() +{ + return step_out_of_me(); +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/version/TestVersion.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/version/TestVersion.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/version/TestVersion.py @@ -0,0 +1,22 @@ +import lldb +from lldbsuite.test.lldbtest import * +from lldbsuite.test.decorators import * + +class VersionTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + TestBase.setUp(self) + + @no_debug_info_test + def test_version(self): + # Should work even when people patch the output, + # so let's just assume that every vendor at least mentions + # 'lldb' in their version string. + self.expect("version", substrs=['lldb']) + + @no_debug_info_test + def test_version_invalid_invocation(self): + self.expect("version a", error=True, + substrs=['the version command takes no arguments.']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/.categories =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/.categories +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/.categories @@ -0,0 +1 @@ +watchpoint Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/hello_watchlocation/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/hello_watchlocation/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/hello_watchlocation/Makefile @@ -0,0 +1,6 @@ +LEVEL = ../../../make + +ENABLE_THREADS := YES +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/hello_watchlocation/TestWatchLocation.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/hello_watchlocation/TestWatchLocation.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/hello_watchlocation/TestWatchLocation.py @@ -0,0 +1,113 @@ +""" +Test lldb watchpoint that uses '-s size' to watch a pointed location with size. +""" + +from __future__ import print_function + + +import re +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class HelloWatchLocationTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Our simple source filename. + self.source = 'main.cpp' + # Find the line number to break inside main(). + self.line = line_number( + self.source, '// Set break point at this line.') + # This is for verifying that watch location works. + self.violating_func = "do_bad_thing_with_location" + # Build dictionary to have unique executable names for each test + # method. + self.exe_name = self.testMethodName + self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name} + + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") + # Most of the MIPS boards provide only one H/W watchpoints, and S/W + # watchpoints are not supported yet + @expectedFailureAll(triple=re.compile('^mips')) + # SystemZ and PowerPC also currently supports only one H/W watchpoint + @expectedFailureAll(archs=['powerpc64le', 's390x']) + @expectedFailureNetBSD + @skipIfDarwin + def test_hello_watchlocation(self): + """Test watching a location with '-s size' option.""" + self.build(dictionary=self.d) + self.setTearDownCleanup(dictionary=self.d) + exe = self.getBuildArtifact(self.exe_name) + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Add a breakpoint to set a watchpoint when stopped on the breakpoint. + lldbutil.run_break_set_by_file_and_line( + self, None, self.line, num_expected_locations=1, loc_exact=False) + + # Run the program. + self.runCmd("run", RUN_SUCCEEDED) + + # We should be stopped again due to the breakpoint. + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', + 'stop reason = breakpoint']) + + # Now let's set a write-type watchpoint pointed to by 'g_char_ptr'. + self.expect( + "watchpoint set expression -w write -s 1 -- g_char_ptr", + WATCHPOINT_CREATED, + substrs=[ + 'Watchpoint created', + 'size = 1', + 'type = w']) + # Get a hold of the watchpoint id just created, it is used later on to + # match the watchpoint id which is expected to be fired. + match = re.match( + "Watchpoint created: Watchpoint (.*):", + self.res.GetOutput().splitlines()[0]) + if match: + expected_wp_id = int(match.group(1), 0) + else: + self.fail("Grokking watchpoint id faailed!") + + self.runCmd("expr unsigned val = *g_char_ptr; val") + self.expect(self.res.GetOutput().splitlines()[0], exe=False, + endstr=' = 0') + + self.runCmd("watchpoint set expression -w write -s 4 -- &threads[0]") + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should be 0 initially. + self.expect("watchpoint list -v", + substrs=['hit_count = 0']) + + self.runCmd("process continue") + + # We should be stopped again due to the watchpoint (write type), but + # only once. The stop reason of the thread should be watchpoint. + self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT, + substrs=['stopped', + 'stop reason = watchpoint %d' % expected_wp_id]) + + # Switch to the thread stopped due to watchpoint and issue some + # commands. + self.switch_to_thread_with_stop_reason(lldb.eStopReasonWatchpoint) + self.runCmd("thread backtrace") + self.expect("frame info", + substrs=[self.violating_func]) + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should now be 1. + self.expect("watchpoint list -v", + substrs=['hit_count = 1']) + + self.runCmd("thread backtrace all") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/hello_watchlocation/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/hello_watchlocation/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/hello_watchlocation/main.cpp @@ -0,0 +1,103 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include +#include +#include +#include +#include + +std::default_random_engine g_random_engine{std::random_device{}()}; +std::uniform_int_distribution<> g_distribution{0, 3000000}; +std::condition_variable g_condition_variable; +std::mutex g_mutex; +int g_count; + +char *g_char_ptr = nullptr; + +void +barrier_wait() +{ + std::unique_lock lock{g_mutex}; + if (--g_count > 0) + g_condition_variable.wait(lock); + else + g_condition_variable.notify_all(); +} + +void +do_bad_thing_with_location(char *char_ptr, char new_val) +{ + unsigned what = new_val; + printf("new value written to location(%p) = %u\n", char_ptr, what); + *char_ptr = new_val; +} + +uint32_t +access_pool (bool flag = false) +{ + static std::mutex g_access_mutex; + g_access_mutex.lock(); + + char old_val = *g_char_ptr; + if (flag) + do_bad_thing_with_location(g_char_ptr, old_val + 1); + + g_access_mutex.unlock(); + return *g_char_ptr; +} + +void +thread_func (uint32_t thread_index) +{ + printf ("%s (thread index = %u) startng...\n", __FUNCTION__, thread_index); + + barrier_wait(); + + uint32_t count = 0; + uint32_t val; + while (count++ < 15) + { + // random micro second sleep from zero to 3 seconds + int usec = g_distribution(g_random_engine); + printf ("%s (thread = %u) doing a usleep (%d)...\n", __FUNCTION__, thread_index, usec); + std::this_thread::sleep_for(std::chrono::microseconds{usec}); + + if (count < 7) + val = access_pool (); + else + val = access_pool (true); + + printf ("%s (thread = %u) after usleep access_pool returns %d (count=%d)...\n", __FUNCTION__, thread_index, val, count); + } + printf ("%s (thread index = %u) exiting...\n", __FUNCTION__, thread_index); +} + + +int main (int argc, char const *argv[]) +{ + g_count = 4; + std::thread threads[3]; + + g_char_ptr = new char{}; + + // Create 3 threads + for (auto &thread : threads) + thread = std::thread{thread_func, std::distance(threads, &thread)}; + + printf ("Before turning all three threads loose...\n"); // Set break point at this line. + barrier_wait(); + + // Join all of our threads + for (auto &thread : threads) + thread.join(); + + delete g_char_ptr; + + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/hello_watchpoint/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/hello_watchpoint/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/hello_watchpoint/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/hello_watchpoint/TestMyFirstWatchpoint.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/hello_watchpoint/TestMyFirstWatchpoint.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/hello_watchpoint/TestMyFirstWatchpoint.py @@ -0,0 +1,95 @@ +""" +Test my first lldb watchpoint. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class HelloWatchpointTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Our simple source filename. + self.source = 'main.c' + # Find the line number to break inside main(). + self.line = line_number( + self.source, '// Set break point at this line.') + # And the watchpoint variable declaration line number. + self.decl = line_number(self.source, + '// Watchpoint variable declaration.') + self.exe_name = self.getBuildArtifact('a.out') + self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} + + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") + @add_test_categories(["basic_process"]) + def test_hello_watchpoint_using_watchpoint_set(self): + """Test a simple sequence of watchpoint creation and watchpoint hit.""" + self.build(dictionary=self.d) + self.setTearDownCleanup(dictionary=self.d) + + exe = self.getBuildArtifact(self.exe_name) + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Add a breakpoint to set a watchpoint when stopped on the breakpoint. + lldbutil.run_break_set_by_file_and_line( + self, None, self.line, num_expected_locations=1) + + # Run the program. + self.runCmd("run", RUN_SUCCEEDED) + + # We should be stopped again due to the breakpoint. + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', + 'stop reason = breakpoint']) + + # Now let's set a write-type watchpoint for 'global'. + # There should be only one watchpoint hit (see main.c). + self.expect( + "watchpoint set variable -w write global", + WATCHPOINT_CREATED, + substrs=[ + 'Watchpoint created', + 'size = 4', + 'type = w', + '%s:%d' % + (self.source, + self.decl)]) + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should be 0 initially. + self.expect("watchpoint list -v", + substrs=['hit_count = 0']) + + self.runCmd("process continue") + + # We should be stopped again due to the watchpoint (write type), but + # only once. The stop reason of the thread should be watchpoint. + self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT, + substrs=['stopped', + 'stop reason = watchpoint']) + + self.runCmd("process continue") + + # Don't expect the read of 'global' to trigger a stop exception. + process = self.dbg.GetSelectedTarget().GetProcess() + if process.GetState() == lldb.eStateStopped: + self.assertFalse( + lldbutil.get_stopped_thread( + process, lldb.eStopReasonWatchpoint)) + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should now be 1. + self.expect("watchpoint list -v", + substrs=['hit_count = 1']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/hello_watchpoint/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/hello_watchpoint/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/hello_watchpoint/main.c @@ -0,0 +1,29 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#include +#include + +int32_t global = 10; // Watchpoint variable declaration. +char gchar1 = 'a'; +char gchar2 = 'b'; + +int main(int argc, char** argv) { + int local = 0; + printf("&global=%p\n", &global); + printf("about to write to 'global'...\n"); // Set break point at this line. + // When stopped, watch 'global' for write. + global = 20; + gchar1 += 1; + gchar2 += 1; + local += argc; + ++local; + printf("local: %d\n", local); + printf("global=%d\n", global); + printf("gchar1='%c'\n", gchar1); + printf("gchar2='%c'\n", gchar2); +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multi_watchpoint_slots/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multi_watchpoint_slots/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multi_watchpoint_slots/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multi_watchpoint_slots/TestWatchpointMultipleSlots.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multi_watchpoint_slots/TestWatchpointMultipleSlots.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multi_watchpoint_slots/TestWatchpointMultipleSlots.py @@ -0,0 +1,101 @@ +""" +Test watchpoint slots we should not be able to install multiple watchpoints +within same word boundary. We should be able to install individual watchpoints +on any of the bytes, half-word, or word. This is only for ARM/AArch64 targets. +""" + +from __future__ import print_function + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class WatchpointSlotsTestCase(TestBase): + NO_DEBUG_INFO_TESTCASE = True + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + # Source filename. + self.source = 'main.c' + + # Output filename. + self.exe_name = self.getBuildArtifact("a.out") + self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} + + # This is a arm and aarch64 specific test case. No other architectures tested. + @skipIf(archs=no_match(['arm', 'aarch64'])) + def test_multiple_watchpoints_on_same_word(self): + + self.build(dictionary=self.d) + self.setTearDownCleanup(dictionary=self.d) + + exe = self.getBuildArtifact(self.exe_name) + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Detect line number after which we are going to increment arrayName. + loc_line = line_number('main.c', '// About to write byteArray') + + # Set a breakpoint on the line detected above. + lldbutil.run_break_set_by_file_and_line( + self, "main.c", loc_line, num_expected_locations=1, loc_exact=True) + + # Run the program. + 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']) + + # Delete breakpoint we just hit. + self.expect("breakpoint delete 1", substrs=['1 breakpoints deleted']) + + # Set a watchpoint at byteArray[0] + self.expect("watchpoint set variable byteArray[0]", WATCHPOINT_CREATED, + substrs=['Watchpoint created','size = 1']) + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should be 0 initially. + self.expect("watchpoint list -v 1", substrs=['hit_count = 0']) + + # debugserver on ios doesn't give an error, it creates another watchpoint, + # only expect errors on non-darwin platforms. + if not self.platformIsDarwin(): + # Try setting a watchpoint at byteArray[1] + self.expect("watchpoint set variable byteArray[1]", error=True, + substrs=['Watchpoint creation failed']) + + self.runCmd("process continue") + + # We should be stopped due to the watchpoint. + # The stop reason of the thread should be watchpoint. + self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT, + substrs=['stopped', 'stop reason = watchpoint 1']) + + # Delete the watchpoint we hit above successfully. + self.expect("watchpoint delete 1", substrs=['1 watchpoints deleted']) + + # Set a watchpoint at byteArray[3] + self.expect("watchpoint set variable byteArray[3]", WATCHPOINT_CREATED, + substrs=['Watchpoint created','size = 1']) + + # Resume inferior. + self.runCmd("process continue") + + # We should be stopped due to the watchpoint. + # The stop reason of the thread should be watchpoint. + if self.platformIsDarwin(): + # On darwin we'll hit byteArray[3] which is watchpoint 2 + self.expect("thread list -v", STOPPED_DUE_TO_WATCHPOINT, + substrs=['stopped', 'stop reason = watchpoint 2']) + else: + self.expect("thread list -v", STOPPED_DUE_TO_WATCHPOINT, + substrs=['stopped', 'stop reason = watchpoint 3']) + + # Resume inferior. + self.runCmd("process continue") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multi_watchpoint_slots/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multi_watchpoint_slots/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multi_watchpoint_slots/main.c @@ -0,0 +1,28 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#include +#include + +uint64_t pad0 = 0; +uint8_t byteArray[4] = {0}; +uint64_t pad1 = 0; + +int main(int argc, char** argv) { + + int i; + + for (i = 0; i < 4; i++) + { + printf("About to write byteArray[%d] ...\n", i); // About to write byteArray + pad0++; + byteArray[i] = 7; + pad1++; + } + + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multiple_hits/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multiple_hits/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multiple_hits/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multiple_hits/TestMultipleHits.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multiple_hits/TestMultipleHits.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multiple_hits/TestMultipleHits.py @@ -0,0 +1,57 @@ +""" +Test handling of cases when a single instruction triggers multiple watchpoints +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class MultipleHitsTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True + + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") + @skipIf(bugnumber="llvm.org/pr30758", oslist=["linux"], archs=["arm", "aarch64", "powerpc64le"]) + @skipIfwatchOS + def test(self): + self.build() + exe = self.getBuildArtifact("a.out") + target = self.dbg.CreateTarget(exe) + self.assertTrue(target and target.IsValid(), VALID_TARGET) + + bp = target.BreakpointCreateByName("main") + self.assertTrue(bp and bp.IsValid(), "Breakpoint is valid") + + process = target.LaunchSimple(None, None, + self.get_process_working_directory()) + self.assertEqual(process.GetState(), lldb.eStateStopped) + + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertIsNotNone(thread) + + frame = thread.GetFrameAtIndex(0) + self.assertTrue(frame and frame.IsValid(), "Frame is valid") + + buf = frame.FindValue("buf", lldb.eValueTypeVariableGlobal) + self.assertTrue(buf and buf.IsValid(), "buf is valid") + + for i in [0, target.GetAddressByteSize()]: + member = buf.GetChildAtIndex(i) + self.assertTrue(member and member.IsValid(), "member is valid") + + error = lldb.SBError() + watch = member.Watch(True, True, True, error) + self.assertTrue(error.Success()) + + process.Continue(); + self.assertEqual(process.GetState(), lldb.eStateStopped) + self.assertEqual(thread.GetStopReason(), lldb.eStopReasonWatchpoint) + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multiple_hits/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multiple_hits/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multiple_hits/main.cpp @@ -0,0 +1,28 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#include +#include +alignas(16) uint8_t buf[32]; +// This uses inline assembly to generate an instruction that writes to a large +// block of memory. If it fails on your compiler/architecture, please add +// appropriate code to generate a large write to "buf". If you cannot write at +// least 2*sizeof(void*) bytes with a single instruction, you will have to skip +// this test. + +int main() { +#if defined(__i386__) || defined(__x86_64__) + asm volatile ("movdqa %%xmm0, %0" : : "m"(buf)); +#elif defined(__arm__) + asm volatile ("stm %0, { r0, r1, r2, r3 }" : : "r"(buf)); +#elif defined(__aarch64__) + asm volatile ("stp x0, x1, %0" : : "m"(buf)); +#elif defined(__mips__) + asm volatile ("lw $2, %0" : : "m"(buf)); +#endif + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multiple_threads/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multiple_threads/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multiple_threads/Makefile @@ -0,0 +1,6 @@ +LEVEL = ../../../make + +ENABLE_THREADS := YES +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multiple_threads/TestWatchpointMultipleThreads.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multiple_threads/TestWatchpointMultipleThreads.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multiple_threads/TestWatchpointMultipleThreads.py @@ -0,0 +1,119 @@ +""" +Test that lldb watchpoint works for multiple threads. +""" + +from __future__ import print_function + + +import re +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class WatchpointForMultipleThreadsTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True + main_spec = lldb.SBFileSpec("main.cpp", False) + + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") + @expectedFailureNetBSD + def test_watchpoint_before_thread_start(self): + """Test that we can hit a watchpoint we set before starting another thread""" + self.do_watchpoint_test("Before running the thread") + + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") + @expectedFailureNetBSD + def test_watchpoint_after_thread_start(self): + """Test that we can hit a watchpoint we set after starting another thread""" + self.do_watchpoint_test("After running the thread") + + def do_watchpoint_test(self, line): + self.build() + lldbutil.run_to_source_breakpoint(self, line, self.main_spec) + + # Now let's set a write-type watchpoint for variable 'g_val'. + self.expect( + "watchpoint set variable -w write g_val", + WATCHPOINT_CREATED, + substrs=[ + 'Watchpoint created', + 'size = 4', + 'type = w']) + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should be 0 initially. + self.expect("watchpoint list -v", + substrs=['hit_count = 0']) + + self.runCmd("process continue") + + self.runCmd("thread list") + if "stop reason = watchpoint" in self.res.GetOutput(): + # Good, we verified that the watchpoint works! + self.runCmd("thread backtrace all") + else: + self.fail("The stop reason should be either break or watchpoint") + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should now be 1. + self.expect("watchpoint list -v", + substrs=['hit_count = 1']) + + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") + def test_watchpoint_multiple_threads_wp_set_and_then_delete(self): + """Test that lldb watchpoint works for multiple threads, and after the watchpoint is deleted, the watchpoint event should no longer fires.""" + self.build() + self.setTearDownCleanup() + + lldbutil.run_to_source_breakpoint(self, "After running the thread", self.main_spec) + + # Now let's set a write-type watchpoint for variable 'g_val'. + self.expect( + "watchpoint set variable -w write g_val", + WATCHPOINT_CREATED, + substrs=[ + 'Watchpoint created', + 'size = 4', + 'type = w']) + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should be 0 initially. + self.expect("watchpoint list -v", + substrs=['hit_count = 0']) + + watchpoint_stops = 0 + while True: + self.runCmd("process continue") + self.runCmd("process status") + if re.search("Process .* exited", self.res.GetOutput()): + # Great, we are done with this test! + break + + self.runCmd("thread list") + if "stop reason = watchpoint" in self.res.GetOutput(): + self.runCmd("thread backtrace all") + watchpoint_stops += 1 + if watchpoint_stops > 1: + self.fail( + "Watchpoint hits not supposed to exceed 1 by design!") + # Good, we verified that the watchpoint works! Now delete the + # watchpoint. + if self.TraceOn(): + print( + "watchpoint_stops=%d at the moment we delete the watchpoint" % + watchpoint_stops) + self.runCmd("watchpoint delete 1") + self.expect("watchpoint list -v", + substrs=['No watchpoints currently set.']) + continue + else: + self.fail("The stop reason should be either break or watchpoint") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multiple_threads/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multiple_threads/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/multiple_threads/main.cpp @@ -0,0 +1,34 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "pseudo_barrier.h" +#include +#include + +volatile uint32_t g_val = 0; +pseudo_barrier_t g_barrier; + +void thread_func() { + pseudo_barrier_wait(g_barrier); + printf("%s starting...\n", __FUNCTION__); + for (uint32_t i = 0; i < 10; ++i) + g_val = i; +} + +int main(int argc, char const *argv[]) { + printf("Before running the thread\n"); + pseudo_barrier_init(g_barrier, 2); + std::thread thread(thread_func); + + printf("After running the thread\n"); + pseudo_barrier_wait(g_barrier); + + thread.join(); + + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/step_over_watchpoint/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/step_over_watchpoint/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/step_over_watchpoint/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/step_over_watchpoint/TestStepOverWatchpoint.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/step_over_watchpoint/TestStepOverWatchpoint.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/step_over_watchpoint/TestStepOverWatchpoint.py @@ -0,0 +1,122 @@ +"""Test stepping over watchpoints.""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestStepOverWatchpoint(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @expectedFailureAll( + oslist=["linux"], + archs=[ + 'aarch64', + 'arm'], + bugnumber="llvm.org/pr26031") + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") + # Read-write watchpoints not supported on SystemZ + @expectedFailureAll(archs=['s390x']) + @expectedFailureAll(oslist=["ios", "watchos", "tvos", "bridgeos"], bugnumber="") # watchpoint tests aren't working on arm64 + @add_test_categories(["basic_process"]) + def test(self): + """Test stepping over watchpoints.""" + self.build() + exe = self.getBuildArtifact("a.out") + + target = self.dbg.CreateTarget(exe) + self.assertTrue(self.target, VALID_TARGET) + + lldbutil.run_break_set_by_symbol(self, 'main') + + process = target.LaunchSimple(None, None, + self.get_process_working_directory()) + self.assertTrue(process.IsValid(), PROCESS_IS_VALID) + self.assertTrue(process.GetState() == lldb.eStateStopped, + PROCESS_STOPPED) + + thread = lldbutil.get_stopped_thread(process, + lldb.eStopReasonBreakpoint) + self.assertTrue(thread.IsValid(), "Failed to get thread.") + + frame = thread.GetFrameAtIndex(0) + self.assertTrue(frame.IsValid(), "Failed to get frame.") + + read_value = frame.FindValue('g_watch_me_read', + lldb.eValueTypeVariableGlobal) + self.assertTrue(read_value.IsValid(), "Failed to find read value.") + + error = lldb.SBError() + + # resolve_location=True, read=True, write=False + read_watchpoint = read_value.Watch(True, True, False, error) + self.assertTrue(error.Success(), + "Error while setting watchpoint: %s" % + error.GetCString()) + self.assertTrue(read_watchpoint, "Failed to set read watchpoint.") + + thread.StepOver() + self.assertTrue(thread.GetStopReason() == lldb.eStopReasonWatchpoint, + STOPPED_DUE_TO_WATCHPOINT) + self.assertTrue(thread.GetStopDescription(20) == 'watchpoint 1') + + process.Continue() + self.assertTrue(process.GetState() == lldb.eStateStopped, + PROCESS_STOPPED) + self.assertTrue(thread.GetStopDescription(20) == 'step over') + + self.step_inst_for_watchpoint(1) + + write_value = frame.FindValue('g_watch_me_write', + lldb.eValueTypeVariableGlobal) + self.assertTrue(write_value, "Failed to find write value.") + + # Most of the MIPS boards provide only one H/W watchpoints, and S/W + # watchpoints are not supported yet + arch = self.getArchitecture() + if re.match("^mips", arch) or re.match("powerpc64le", arch): + self.runCmd("watchpoint delete 1") + + # resolve_location=True, read=False, write=True + write_watchpoint = write_value.Watch(True, False, True, error) + self.assertTrue(write_watchpoint, "Failed to set write watchpoint.") + self.assertTrue(error.Success(), + "Error while setting watchpoint: %s" % + error.GetCString()) + + thread.StepOver() + self.assertTrue(thread.GetStopReason() == lldb.eStopReasonWatchpoint, + STOPPED_DUE_TO_WATCHPOINT) + self.assertTrue(thread.GetStopDescription(20) == 'watchpoint 2') + + process.Continue() + self.assertTrue(process.GetState() == lldb.eStateStopped, + PROCESS_STOPPED) + self.assertTrue(thread.GetStopDescription(20) == 'step over') + + self.step_inst_for_watchpoint(2) + + def step_inst_for_watchpoint(self, wp_id): + watchpoint_hit = False + current_line = self.frame().GetLineEntry().GetLine() + while self.frame().GetLineEntry().GetLine() == current_line: + self.thread().StepInstruction(False) # step_over=False + stop_reason = self.thread().GetStopReason() + if stop_reason == lldb.eStopReasonWatchpoint: + self.assertFalse(watchpoint_hit, "Watchpoint already hit.") + expected_stop_desc = "watchpoint %d" % wp_id + actual_stop_desc = self.thread().GetStopDescription(20) + self.assertTrue(actual_stop_desc == expected_stop_desc, + "Watchpoint ID didn't match.") + watchpoint_hit = True + else: + self.assertTrue(stop_reason == lldb.eStopReasonPlanComplete, + STOPPED_DUE_TO_STEP_IN) + self.assertTrue(watchpoint_hit, "Watchpoint never hit.") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/step_over_watchpoint/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/step_over_watchpoint/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/step_over_watchpoint/main.c @@ -0,0 +1,19 @@ +char g_watch_me_read; +char g_watch_me_write; +char g_temp; + +void watch_read() { + g_temp = g_watch_me_read; +} + +void watch_write() { + g_watch_me_write = g_temp; +} + +int main() { + watch_read(); + g_temp = g_watch_me_read; + watch_write(); + g_watch_me_write = g_temp; + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/variable_out_of_scope/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/variable_out_of_scope/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/variable_out_of_scope/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/variable_out_of_scope/TestWatchedVarHitWhenInScope.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/variable_out_of_scope/TestWatchedVarHitWhenInScope.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/variable_out_of_scope/TestWatchedVarHitWhenInScope.py @@ -0,0 +1,84 @@ +""" +Test that a variable watchpoint should only hit when in scope. +""" + +from __future__ import print_function + + +import unittest2 +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.decorators import * + + +class WatchedVariableHitWhenInScopeTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # This test depends on not tracking watchpoint expression hits if we have + # left the watchpoint scope. We will provide such an ability at some point + # but the way this was done was incorrect, and it is unclear that for the + # most part that's not what folks mostly want, so we have to provide a + # clearer API to express this. + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Our simple source filename. + self.source = 'main.c' + self.exe_name = self.testMethodName + self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} + + # Test hangs due to a kernel bug, see fdfeff0f in the linux kernel for details + @skipIfTargetAndroid(api_levels=list(range(25+1)), archs=["aarch64", "arm"]) + @skipIf + def test_watched_var_should_only_hit_when_in_scope(self): + """Test that a variable watchpoint should only hit when in scope.""" + self.build(dictionary=self.d) + self.setTearDownCleanup(dictionary=self.d) + + exe = self.getBuildArtifact(self.exe_name) + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Add a breakpoint to set a watchpoint when stopped in main. + lldbutil.run_break_set_by_symbol( + self, "main", num_expected_locations=-1) + + # Run the program. + self.runCmd("run", RUN_SUCCEEDED) + + # We should be stopped again due to the breakpoint. + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', + 'stop reason = breakpoint']) + + # Now let's set a watchpoint for 'c.a'. + # There should be only one watchpoint hit (see main.c). + self.expect("watchpoint set variable c.a", WATCHPOINT_CREATED, + substrs=['Watchpoint created', 'size = 4', 'type = w']) + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should be 0 initially. + self.expect("watchpoint list -v", + substrs=['hit_count = 0']) + + self.runCmd("process continue") + + # We should be stopped again due to the watchpoint (write type), but + # only once. The stop reason of the thread should be watchpoint. + self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT, + substrs=['stopped', + 'stop reason = watchpoint']) + + self.runCmd("process continue") + # Don't expect the read of 'global' to trigger a stop exception. + # The process status should be 'exited'. + self.expect("process status", + substrs=['exited']) + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should now be 1. + self.expect("watchpoint list -v", + substrs=['hit_count = 1']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/variable_out_of_scope/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/variable_out_of_scope/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/variable_out_of_scope/main.c @@ -0,0 +1,15 @@ +typedef struct +{ + int a; + float b; +} mystruct; + +int main() +{ + mystruct c; + + c.a = 5; + c.b = 3.6; + + return 0; +} \ No newline at end of file Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/TestWatchpointCommands.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/TestWatchpointCommands.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/TestWatchpointCommands.py @@ -0,0 +1,375 @@ +""" +Test watchpoint list, enable, disable, and delete commands. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class WatchpointCommandsTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Our simple source filename. + self.source = 'main.c' + # Find the line number to break inside main(). + self.line = line_number( + self.source, '// Set break point at this line.') + self.line2 = line_number( + self.source, + '// Set 2nd break point for disable_then_enable test case.') + # And the watchpoint variable declaration line number. + self.decl = line_number(self.source, + '// Watchpoint variable declaration.') + # Build dictionary to have unique executable names for each test + # method. + self.exe_name = self.testMethodName + self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} + + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") + # Read-write watchpoints not supported on SystemZ + @expectedFailureAll(archs=['s390x']) + def test_rw_watchpoint(self): + """Test read_write watchpoint and expect to stop two times.""" + self.build(dictionary=self.d) + self.setTearDownCleanup(dictionary=self.d) + + exe = self.getBuildArtifact(self.exe_name) + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Add a breakpoint to set a watchpoint when stopped on the breakpoint. + lldbutil.run_break_set_by_file_and_line( + self, None, self.line, num_expected_locations=1) + + # Run the program. + self.runCmd("run", RUN_SUCCEEDED) + + # We should be stopped again due to the breakpoint. + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', + 'stop reason = breakpoint']) + + # Now let's set a read_write-type watchpoint for 'global'. + # There should be two watchpoint hits (see main.c). + self.expect( + "watchpoint set variable -w read_write global", + WATCHPOINT_CREATED, + substrs=[ + 'Watchpoint created', + 'size = 4', + 'type = rw', + '%s:%d' % + (self.source, + self.decl)]) + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should be 0 initially. + self.expect("watchpoint list -v", + substrs=['Number of supported hardware watchpoints:', + 'hit_count = 0']) + + self.runCmd("process continue") + + # We should be stopped again due to the watchpoint (read_write type). + # The stop reason of the thread should be watchpoint. + self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT, + substrs=['stop reason = watchpoint']) + + self.runCmd("process continue") + + # We should be stopped again due to the watchpoint (read_write type). + # The stop reason of the thread should be watchpoint. + self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT, + substrs=['stop reason = watchpoint']) + + self.runCmd("process continue") + + # There should be no more watchpoint hit and the process status should + # be 'exited'. + self.expect("process status", + substrs=['exited']) + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should now be 2. + self.expect("watchpoint list -v", + substrs=['hit_count = 2']) + + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") + # Read-write watchpoints not supported on SystemZ + @expectedFailureAll(archs=['s390x']) + def test_rw_watchpoint_delete(self): + """Test delete watchpoint and expect not to stop for watchpoint.""" + self.build(dictionary=self.d) + self.setTearDownCleanup(dictionary=self.d) + + exe = self.getBuildArtifact(self.exe_name) + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Add a breakpoint to set a watchpoint when stopped on the breakpoint. + lldbutil.run_break_set_by_file_and_line( + self, None, self.line, num_expected_locations=1) + + # Run the program. + self.runCmd("run", RUN_SUCCEEDED) + + # We should be stopped again due to the breakpoint. + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', + 'stop reason = breakpoint']) + + # Now let's set a read_write-type watchpoint for 'global'. + # There should be two watchpoint hits (see main.c). + self.expect( + "watchpoint set variable -w read_write global", + WATCHPOINT_CREATED, + substrs=[ + 'Watchpoint created', + 'size = 4', + 'type = rw', + '%s:%d' % + (self.source, + self.decl)]) + + # Delete the watchpoint immediately, but set auto-confirm to true + # first. + self.runCmd("settings set auto-confirm true") + self.expect("watchpoint delete", + substrs=['All watchpoints removed.']) + # Restore the original setting of auto-confirm. + self.runCmd("settings clear auto-confirm") + + # Use the '-v' option to do verbose listing of the watchpoint. + self.runCmd("watchpoint list -v") + + self.runCmd("process continue") + + # There should be no more watchpoint hit and the process status should + # be 'exited'. + self.expect("process status", + substrs=['exited']) + + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") + # Read-write watchpoints not supported on SystemZ + @expectedFailureAll(archs=['s390x']) + def test_rw_watchpoint_set_ignore_count(self): + """Test watchpoint ignore count and expect to not to stop at all.""" + self.build(dictionary=self.d) + self.setTearDownCleanup(dictionary=self.d) + + exe = self.getBuildArtifact(self.exe_name) + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Add a breakpoint to set a watchpoint when stopped on the breakpoint. + lldbutil.run_break_set_by_file_and_line( + self, None, self.line, num_expected_locations=1) + + # Run the program. + self.runCmd("run", RUN_SUCCEEDED) + + # We should be stopped again due to the breakpoint. + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', + 'stop reason = breakpoint']) + + # Now let's set a read_write-type watchpoint for 'global'. + # There should be two watchpoint hits (see main.c). + self.expect( + "watchpoint set variable -w read_write global", + WATCHPOINT_CREATED, + substrs=[ + 'Watchpoint created', + 'size = 4', + 'type = rw', + '%s:%d' % + (self.source, + self.decl)]) + + # Set the ignore count of the watchpoint immediately. + self.expect("watchpoint ignore -i 2", + substrs=['All watchpoints ignored.']) + + # Use the '-v' option to do verbose listing of the watchpoint. + # Expect to find an ignore_count of 2. + self.expect("watchpoint list -v", + substrs=['hit_count = 0', 'ignore_count = 2']) + + self.runCmd("process continue") + + # There should be no more watchpoint hit and the process status should + # be 'exited'. + self.expect("process status", + substrs=['exited']) + + # Use the '-v' option to do verbose listing of the watchpoint. + # Expect to find a hit_count of 2 as well. + self.expect("watchpoint list -v", + substrs=['hit_count = 2', 'ignore_count = 2']) + + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") + # Read-write watchpoints not supported on SystemZ + @expectedFailureAll(archs=['s390x']) + def test_rw_disable_after_first_stop(self): + """Test read_write watchpoint but disable it after the first stop.""" + self.build(dictionary=self.d) + self.setTearDownCleanup(dictionary=self.d) + + exe = self.getBuildArtifact(self.exe_name) + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Add a breakpoint to set a watchpoint when stopped on the breakpoint. + lldbutil.run_break_set_by_file_and_line( + self, None, self.line, num_expected_locations=1) + + # Run the program. + self.runCmd("run", RUN_SUCCEEDED) + + # We should be stopped again due to the breakpoint. + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', + 'stop reason = breakpoint']) + + # Now let's set a read_write-type watchpoint for 'global'. + # There should be two watchpoint hits (see main.c). + self.expect( + "watchpoint set variable -w read_write global", + WATCHPOINT_CREATED, + substrs=[ + 'Watchpoint created', + 'size = 4', + 'type = rw', + '%s:%d' % + (self.source, + self.decl)]) + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should be 0 initially. + self.expect("watchpoint list -v", + substrs=['state = enabled', 'hit_count = 0']) + + self.runCmd("process continue") + + # We should be stopped again due to the watchpoint (read_write type). + # The stop reason of the thread should be watchpoint. + self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT, + substrs=['stop reason = watchpoint']) + + # Before continuing, we'll disable the watchpoint, which means we won't + # stop again after this. + self.runCmd("watchpoint disable") + + self.expect("watchpoint list -v", + substrs=['state = disabled', 'hit_count = 1']) + + self.runCmd("process continue") + + # There should be no more watchpoint hit and the process status should + # be 'exited'. + self.expect("process status", + substrs=['exited']) + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should be 1. + self.expect("watchpoint list -v", + substrs=['hit_count = 1']) + + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") + # Read-write watchpoints not supported on SystemZ + @expectedFailureAll(archs=['s390x']) + def test_rw_disable_then_enable(self): + """Test read_write watchpoint, disable initially, then enable it.""" + self.build(dictionary=self.d) + self.setTearDownCleanup(dictionary=self.d) + + exe = self.getBuildArtifact(self.exe_name) + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Add a breakpoint to set a watchpoint when stopped on the breakpoint. + lldbutil.run_break_set_by_file_and_line( + self, None, self.line, num_expected_locations=1) + lldbutil.run_break_set_by_file_and_line( + self, None, self.line2, num_expected_locations=1) + + # Run the program. + self.runCmd("run", RUN_SUCCEEDED) + + # We should be stopped again due to the breakpoint. + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', + 'stop reason = breakpoint']) + + # Now let's set a read_write-type watchpoint for 'global'. + # There should be two watchpoint hits (see main.c). + self.expect( + "watchpoint set variable -w read_write global", + WATCHPOINT_CREATED, + substrs=[ + 'Watchpoint created', + 'size = 4', + 'type = rw', + '%s:%d' % + (self.source, + self.decl)]) + + # Immediately, we disable the watchpoint. We won't be stopping due to a + # watchpoint after this. + self.runCmd("watchpoint disable") + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should be 0 initially. + self.expect("watchpoint list -v", + substrs=['state = disabled', 'hit_count = 0']) + + self.runCmd("process continue") + + # We should be stopped again due to the breakpoint. + self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stop reason = breakpoint']) + + # Before continuing, we'll enable the watchpoint, which means we will + # stop again after this. + self.runCmd("watchpoint enable") + + self.expect("watchpoint list -v", + substrs=['state = enabled', 'hit_count = 0']) + + self.runCmd("process continue") + + # We should be stopped again due to the watchpoint (read_write type). + # The stop reason of the thread should be watchpoint. + self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT, + substrs=['stop reason = watchpoint']) + + self.runCmd("process continue") + + # There should be no more watchpoint hit and the process status should + # be 'exited'. + self.expect("process status", + substrs=['exited']) + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should be 1. + self.expect("watchpoint list -v", + substrs=['hit_count = 1']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/command/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/command/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/command/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/command/TestWatchpointCommandLLDB.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/command/TestWatchpointCommandLLDB.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/command/TestWatchpointCommandLLDB.py @@ -0,0 +1,172 @@ +""" +Test 'watchpoint command'. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class WatchpointLLDBCommandTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Our simple source filename. + self.source = 'main.cpp' + # Find the line number to break inside main(). + self.line = line_number( + self.source, '// Set break point at this line.') + # And the watchpoint variable declaration line number. + self.decl = line_number(self.source, + '// Watchpoint variable declaration.') + # Build dictionary to have unique executable names for each test + # method. + self.exe_name = 'a%d.out' % self.test_number + self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name} + + @expectedFailureAll( + oslist=["linux"], + archs=["aarch64"], + triple=no_match(".*-android"), + bugnumber="llvm.org/pr27710") # work on android + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") + @expectedFailureNetBSD + def test_watchpoint_command(self): + """Test 'watchpoint command'.""" + self.build(dictionary=self.d) + self.setTearDownCleanup(dictionary=self.d) + + exe = self.getBuildArtifact(self.exe_name) + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Add a breakpoint to set a watchpoint when stopped on the breakpoint. + lldbutil.run_break_set_by_file_and_line( + self, None, self.line, num_expected_locations=1) + + # Run the program. + self.runCmd("run", RUN_SUCCEEDED) + + # We should be stopped again due to the breakpoint. + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', + 'stop reason = breakpoint']) + + # Now let's set a write-type watchpoint for 'global'. + self.expect( + "watchpoint set variable -w write global", + WATCHPOINT_CREATED, + substrs=[ + 'Watchpoint created', + 'size = 4', + 'type = w', + '%s:%d' % + (self.source, + self.decl)]) + + self.runCmd('watchpoint command add 1 -o "expr -- cookie = 777"') + + # List the watchpoint command we just added. + self.expect("watchpoint command list 1", + substrs=['expr -- cookie = 777']) + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should be 0 initially. + self.expect("watchpoint list -v", + substrs=['hit_count = 0']) + + self.runCmd("process continue") + + # We should be stopped again due to the watchpoint (write type). + # The stop reason of the thread should be watchpoint. + self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT, + substrs=['stop reason = watchpoint']) + + # Check that the watchpoint snapshoting mechanism is working. + self.expect("watchpoint list -v", + substrs=['old value:', ' = 0', + 'new value:', ' = 1']) + + # The watchpoint command "forced" our global variable 'cookie' to + # become 777. + self.expect("frame variable --show-globals cookie", + substrs=['(int32_t)', 'cookie = 777']) + + @expectedFailureAll( + oslist=["linux"], + archs=["aarch64"], + triple=no_match(".*-android"), + bugnumber="llvm.org/pr27710") # work on android + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") + def test_watchpoint_command_can_disable_a_watchpoint(self): + """Test that 'watchpoint command' action can disable a watchpoint after it is triggered.""" + self.build(dictionary=self.d) + self.setTearDownCleanup(dictionary=self.d) + + exe = self.getBuildArtifact(self.exe_name) + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Add a breakpoint to set a watchpoint when stopped on the breakpoint. + lldbutil.run_break_set_by_file_and_line( + self, None, self.line, num_expected_locations=1) + + # Run the program. + self.runCmd("run", RUN_SUCCEEDED) + + # We should be stopped again due to the breakpoint. + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', + 'stop reason = breakpoint']) + + # Now let's set a write-type watchpoint for 'global'. + self.expect( + "watchpoint set variable -w write global", + WATCHPOINT_CREATED, + substrs=[ + 'Watchpoint created', + 'size = 4', + 'type = w', + '%s:%d' % + (self.source, + self.decl)]) + + self.runCmd('watchpoint command add 1 -o "watchpoint disable 1"') + + # List the watchpoint command we just added. + self.expect("watchpoint command list 1", + substrs=['watchpoint disable 1']) + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should be 0 initially. + self.expect("watchpoint list -v", + substrs=['hit_count = 0']) + + self.runCmd("process continue") + + # We should be stopped again due to the watchpoint (write type). + # The stop reason of the thread should be watchpoint. + self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT, + substrs=['stop reason = watchpoint']) + + # Check that the watchpoint has been disabled. + self.expect("watchpoint list -v", + substrs=['disabled']) + + self.runCmd("process continue") + + # There should be no more watchpoint hit and the process status should + # be 'exited'. + self.expect("process status", + substrs=['exited']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/command/TestWatchpointCommandPython.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/command/TestWatchpointCommandPython.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/command/TestWatchpointCommandPython.py @@ -0,0 +1,172 @@ +""" +Test 'watchpoint command'. +""" + +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 WatchpointPythonCommandTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Our simple source filename. + self.source = 'main.cpp' + # Find the line number to break inside main(). + self.line = line_number( + self.source, '// Set break point at this line.') + # And the watchpoint variable declaration line number. + self.decl = line_number(self.source, + '// Watchpoint variable declaration.') + # Build dictionary to have unique executable names for each test + # method. + self.exe_name = self.testMethodName + self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name} + + @skipIfFreeBSD # timing out on buildbot + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") + @expectedFailureAll( + oslist=["linux"], + archs=["aarch64"], + triple=no_match(".*-android"), + bugnumber="llvm.org/pr27710") # work on android + @expectedFailureNetBSD + def test_watchpoint_command(self): + """Test 'watchpoint command'.""" + self.build(dictionary=self.d) + self.setTearDownCleanup(dictionary=self.d) + + exe = self.getBuildArtifact(self.exe_name) + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Add a breakpoint to set a watchpoint when stopped on the breakpoint. + lldbutil.run_break_set_by_file_and_line( + self, None, self.line, num_expected_locations=1) + + # Run the program. + self.runCmd("run", RUN_SUCCEEDED) + + # We should be stopped again due to the breakpoint. + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', + 'stop reason = breakpoint']) + + # Now let's set a write-type watchpoint for 'global'. + self.expect( + "watchpoint set variable -w write global", + WATCHPOINT_CREATED, + substrs=[ + 'Watchpoint created', + 'size = 4', + 'type = w', + '%s:%d' % + (self.source, + self.decl)]) + + self.runCmd( + 'watchpoint command add -s python 1 -o \'frame.EvaluateExpression("cookie = 777")\'') + + # List the watchpoint command we just added. + self.expect("watchpoint command list 1", + substrs=['frame.EvaluateExpression', 'cookie = 777']) + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should be 0 initially. + self.expect("watchpoint list -v", + substrs=['hit_count = 0']) + + self.runCmd("process continue") + + # We should be stopped again due to the watchpoint (write type). + # The stop reason of the thread should be watchpoint. + self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT, + substrs=['stop reason = watchpoint']) + + # Check that the watchpoint snapshoting mechanism is working. + self.expect("watchpoint list -v", + substrs=['old value:', ' = 0', + 'new value:', ' = 1']) + + # The watchpoint command "forced" our global variable 'cookie' to + # become 777. + self.expect("frame variable --show-globals cookie", + substrs=['(int32_t)', 'cookie = 777']) + + @skipIfFreeBSD # timing out on buildbot + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") + @expectedFailureAll( + oslist=["linux"], + archs=["aarch64"], + triple=no_match(".*-android"), + bugnumber="llvm.org/pr27710") # work on android + @expectedFailureNetBSD + def test_continue_in_watchpoint_command(self): + """Test continue in a watchpoint command.""" + self.build(dictionary=self.d) + self.setTearDownCleanup(dictionary=self.d) + + exe = self.getBuildArtifact(self.exe_name) + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Add a breakpoint to set a watchpoint when stopped on the breakpoint. + lldbutil.run_break_set_by_file_and_line( + self, None, self.line, num_expected_locations=1) + + # Run the program. + self.runCmd("run", RUN_SUCCEEDED) + + # We should be stopped again due to the breakpoint. + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', + 'stop reason = breakpoint']) + + # Now let's set a write-type watchpoint for 'global'. + self.expect( + "watchpoint set variable -w write global", + WATCHPOINT_CREATED, + substrs=[ + 'Watchpoint created', + 'size = 4', + 'type = w', + '%s:%d' % + (self.source, + self.decl)]) + + cmd_script_file = os.path.join(self.getSourceDir(), + "watchpoint_command.py") + self.runCmd("command script import '%s'" % (cmd_script_file)) + + self.runCmd( + 'watchpoint command add -F watchpoint_command.watchpoint_command') + + # List the watchpoint command we just added. + self.expect("watchpoint command list 1", + substrs=['watchpoint_command.watchpoint_command']) + + self.runCmd("process continue") + + # We should be stopped again due to the watchpoint (write type). + # The stop reason of the thread should be watchpoint. + self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT, + substrs=['stop reason = watchpoint']) + + # We should have hit the watchpoint once, set cookie to 888, then continued to the + # second hit and set it to 999 + self.expect("frame variable --show-globals cookie", + substrs=['(int32_t)', 'cookie = 999']) + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/command/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/command/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/command/main.cpp @@ -0,0 +1,27 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#include +#include + +int32_t global = 0; // Watchpoint variable declaration. +int32_t cookie = 0; + +static void modify(int32_t &var) { + ++var; +} + +int main(int argc, char** argv) { + int local = 0; + printf("&global=%p\n", &global); + printf("about to write to 'global'...\n"); // Set break point at this line. + for (int i = 0; i < 10; ++i) + modify(global); + + printf("global=%d\n", global); + printf("cookie=%d\n", cookie); +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/command/watchpoint_command.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/command/watchpoint_command.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/command/watchpoint_command.py @@ -0,0 +1,15 @@ +import lldb + +num_hits = 0 + + +def watchpoint_command(frame, wp, dict): + global num_hits + if num_hits == 0: + print ("I stopped the first time") + frame.EvaluateExpression("cookie = 888") + num_hits += 1 + frame.thread.process.Continue() + else: + print ("I stopped the %d time" % (num_hits)) + frame.EvaluateExpression("cookie = 999") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/condition/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/condition/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/condition/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/condition/TestWatchpointConditionCmd.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/condition/TestWatchpointConditionCmd.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/condition/TestWatchpointConditionCmd.py @@ -0,0 +1,96 @@ +""" +Test watchpoint modify command to set condition on a watchpoint. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class WatchpointConditionCmdTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Our simple source filename. + self.source = 'main.cpp' + # Find the line number to break inside main(). + self.line = line_number( + self.source, '// Set break point at this line.') + # And the watchpoint variable declaration line number. + self.decl = line_number(self.source, + '// Watchpoint variable declaration.') + # Build dictionary to have unique executable names for each test + # method. + self.exe_name = self.testMethodName + self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name} + + @expectedFailureAll( + oslist=["linux"], + archs=["aarch64"], + triple=no_match(".*-android"), + bugnumber="llvm.org/pr27710") + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") + @expectedFailureNetBSD + def test_watchpoint_cond(self): + """Test watchpoint condition.""" + self.build(dictionary=self.d) + self.setTearDownCleanup(dictionary=self.d) + + exe = self.getBuildArtifact(self.exe_name) + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Add a breakpoint to set a watchpoint when stopped on the breakpoint. + lldbutil.run_break_set_by_file_and_line( + self, None, self.line, num_expected_locations=1) + + # Run the program. + self.runCmd("run", RUN_SUCCEEDED) + + # We should be stopped again due to the breakpoint. + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', + 'stop reason = breakpoint']) + + # Now let's set a write-type watchpoint for 'global'. + # With a condition of 'global==5'. + self.expect( + "watchpoint set variable -w write global", + WATCHPOINT_CREATED, + substrs=[ + 'Watchpoint created', + 'size = 4', + 'type = w', + '%s:%d' % + (self.source, + self.decl)]) + + self.runCmd("watchpoint modify -c 'global==5'") + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should be 0 initially. + self.expect("watchpoint list -v", + substrs=['hit_count = 0', 'global==5']) + + self.runCmd("process continue") + + # We should be stopped again due to the watchpoint (write type). + # The stop reason of the thread should be watchpoint. + self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT, + substrs=['stop reason = watchpoint']) + self.expect("frame variable --show-globals global", + substrs=['(int32_t)', 'global = 5']) + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should now be 2. + self.expect("watchpoint list -v", + substrs=['hit_count = 5']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/condition/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/condition/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/condition/main.cpp @@ -0,0 +1,27 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#include +#include + +int32_t global = 0; // Watchpoint variable declaration. + +static void modify(int32_t &var) { + ++var; +} + +int main(int argc, char** argv) { + int local = 0; + printf("&global=%p\n", &global); + printf("about to write to 'global'...\n"); // Set break point at this line. + // When stopped, watch 'global', + // for the condition "global == 5". + for (int i = 0; i < 10; ++i) + modify(global); + + printf("global=%d\n", global); +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_commands/main.c @@ -0,0 +1,23 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#include +#include + +int32_t global = 10; // Watchpoint variable declaration. + +int main(int argc, char** argv) { + int local = 0; + printf("&global=%p\n", &global); + printf("about to write to 'global'...\n"); // Set break point at this line. + // When stopped, watch 'global'. + global = 20; + local += argc; + ++local; // Set 2nd break point for disable_then_enable test case. + printf("local: %d\n", local); + printf("global=%d\n", global); +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_disable/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_disable/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_disable/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_disable/TestWatchpointDisable.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_disable/TestWatchpointDisable.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_disable/TestWatchpointDisable.py @@ -0,0 +1,80 @@ +""" +Test that the SBWatchpoint::SetEnable API works. +""" + +import lldb +from lldbsuite.test.lldbtest import * +from lldbsuite.test.decorators import * +from lldbsuite.test import lldbplatform, lldbplatformutil + + +class TestWatchpointSetEnable(TestBase): + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") + def test_disable_works (self): + """Set a watchpoint, disable it, and make sure it doesn't get hit.""" + self.build() + self.do_test(False) + + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") + def test_disable_enable_works (self): + """Set a watchpoint, disable it, and make sure it doesn't get hit.""" + self.build() + self.do_test(True) + + def do_test(self, test_enable): + """Set a watchpoint, disable it and make sure it doesn't get hit.""" + + exe = self.getBuildArtifact("a.out") + main_file_spec = lldb.SBFileSpec("main.c") + + # Create a target by the debugger. + self.target = self.dbg.CreateTarget(exe) + self.assertTrue(self.target, VALID_TARGET) + + bkpt_before = self.target.BreakpointCreateBySourceRegex("Set a breakpoint here", main_file_spec) + self.assertEqual(bkpt_before.GetNumLocations(), 1, "Failed setting the before breakpoint.") + + bkpt_after = self.target.BreakpointCreateBySourceRegex("We should have stopped", main_file_spec) + self.assertEqual(bkpt_after.GetNumLocations(), 1, "Failed setting the after breakpoint.") + + process = self.target.LaunchSimple( + None, None, self.get_process_working_directory()) + self.assertTrue(process, PROCESS_IS_VALID) + + thread = lldbutil.get_one_thread_stopped_at_breakpoint(process, bkpt_before) + self.assertTrue(thread.IsValid(), "We didn't stop at the before breakpoint.") + + ret_val = lldb.SBCommandReturnObject() + self.dbg.GetCommandInterpreter().HandleCommand("watchpoint set variable -w write global_var", ret_val) + self.assertTrue(ret_val.Succeeded(), "Watchpoint set variable did not return success.") + + wp = self.target.FindWatchpointByID(1) + self.assertTrue(wp.IsValid(), "Didn't make a valid watchpoint.") + self.assertTrue(wp.GetWatchAddress() != lldb.LLDB_INVALID_ADDRESS, "Watch address is invalid") + + wp.SetEnabled(False) + self.assertTrue(not wp.IsEnabled(), "The watchpoint thinks it is still enabled") + + process.Continue() + + stop_reason = thread.GetStopReason() + + self.assertEqual(stop_reason, lldb.eStopReasonBreakpoint, "We didn't stop at our breakpoint.") + + if test_enable: + wp.SetEnabled(True) + self.assertTrue(wp.IsEnabled(), "The watchpoint thinks it is still disabled.") + process.Continue() + stop_reason = thread.GetStopReason() + self.assertEqual(stop_reason, lldb.eStopReasonWatchpoint, "We didn't stop at our watchpoint") + Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_disable/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_disable/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_disable/main.c @@ -0,0 +1,13 @@ +#include + +int global_var = 10; + +int +main() +{ + printf("Set a breakpoint here: %d.\n", global_var); + global_var = 20; + printf("We should have stopped on the previous line: %d.\n", global_var); + global_var = 30; + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_events/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_events/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_events/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_events/TestWatchpointEvents.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_events/TestWatchpointEvents.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_events/TestWatchpointEvents.py @@ -0,0 +1,117 @@ +"""Test that adding, deleting and modifying watchpoints sends the appropriate events.""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestWatchpointEvents (TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line numbers that we will step to in main: + self.main_source = "main.c" + + @add_test_categories(['pyapi']) + @expectedFailureAll( + oslist=["linux"], + archs=["aarch64"], + triple=no_match(".*-android"), + bugnumber="llvm.org/pr27710") + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") + def test_with_python_api(self): + """Test that adding, deleting and modifying watchpoints sends the appropriate events.""" + self.build() + + exe = self.getBuildArtifact("a.out") + + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + self.main_source_spec = lldb.SBFileSpec(self.main_source) + + break_in_main = target.BreakpointCreateBySourceRegex( + '// Put a breakpoint here.', self.main_source_spec) + self.assertTrue(break_in_main, VALID_BREAKPOINT) + + # Now launch the process, and do not stop at entry point. + process = target.LaunchSimple( + None, None, self.get_process_working_directory()) + + self.assertTrue(process, PROCESS_IS_VALID) + + # The stop reason of the thread should be breakpoint. + threads = lldbutil.get_threads_stopped_at_breakpoint( + process, break_in_main) + + if len(threads) != 1: + self.fail("Failed to stop at first breakpoint in main.") + + thread = threads[0] + frame = thread.GetFrameAtIndex(0) + local_var = frame.FindVariable("local_var") + self.assertTrue(local_var.IsValid()) + + self.listener = lldb.SBListener("com.lldb.testsuite_listener") + self.target_bcast = target.GetBroadcaster() + self.target_bcast.AddListener( + self.listener, lldb.SBTarget.eBroadcastBitWatchpointChanged) + self.listener.StartListeningForEvents( + self.target_bcast, lldb.SBTarget.eBroadcastBitWatchpointChanged) + + error = lldb.SBError() + local_watch = local_var.Watch(True, False, True, error) + if not error.Success(): + self.fail( + "Failed to make watchpoint for local_var: %s" % + (error.GetCString())) + + self.GetWatchpointEvent(lldb.eWatchpointEventTypeAdded) + # Now change some of the features of this watchpoint and make sure we + # get events: + local_watch.SetEnabled(False) + self.GetWatchpointEvent(lldb.eWatchpointEventTypeDisabled) + + local_watch.SetEnabled(True) + self.GetWatchpointEvent(lldb.eWatchpointEventTypeEnabled) + + local_watch.SetIgnoreCount(10) + self.GetWatchpointEvent(lldb.eWatchpointEventTypeIgnoreChanged) + + condition = "1 == 2" + local_watch.SetCondition(condition) + self.GetWatchpointEvent(lldb.eWatchpointEventTypeConditionChanged) + + self.assertTrue(local_watch.GetCondition() == condition, + 'make sure watchpoint condition is "' + condition + '"') + + def GetWatchpointEvent(self, event_type): + # We added a watchpoint so we should get a watchpoint added event. + event = lldb.SBEvent() + success = self.listener.WaitForEvent(1, event) + self.assertTrue(success, "Successfully got watchpoint event") + self.assertTrue( + lldb.SBWatchpoint.EventIsWatchpointEvent(event), + "Event is a watchpoint event.") + found_type = lldb.SBWatchpoint.GetWatchpointEventTypeFromEvent(event) + self.assertTrue( + found_type == event_type, + "Event is not correct type, expected: %d, found: %d" % + (event_type, + found_type)) + # There shouldn't be another event waiting around: + found_event = self.listener.PeekAtNextEventForBroadcasterWithType( + self.target_bcast, lldb.SBTarget.eBroadcastBitBreakpointChanged, event) + if found_event: + print("Found an event I didn't expect: ", event) + + self.assertTrue(not found_event, "Only one event per change.") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_events/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_events/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_events/main.c @@ -0,0 +1,9 @@ +#include + +int +main (int argc, char **argv) +{ + int local_var = 10; + printf ("local_var is: %d.\n", local_var++); // Put a breakpoint here. + return local_var; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_on_vectors/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_on_vectors/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_on_vectors/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_on_vectors/TestValueOfVectorVariable.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_on_vectors/TestValueOfVectorVariable.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_on_vectors/TestValueOfVectorVariable.py @@ -0,0 +1,50 @@ +""" +Test displayed value of a vector variable while doing watchpoint operations +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestValueOfVectorVariableTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") + def test_value_of_vector_variable_using_watchpoint_set(self): + """Test verify displayed value of vector variable.""" + exe = self.getBuildArtifact("a.out") + d = {'C_SOURCES': self.source, 'EXE': exe} + self.build(dictionary=d) + self.setTearDownCleanup(dictionary=d) + self.value_of_vector_variable_with_watchpoint_set() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Our simple source filename. + self.source = 'main.c' + + def value_of_vector_variable_with_watchpoint_set(self): + """Test verify displayed value of vector variable""" + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Set break to get a frame + self.runCmd("b main") + + # Run the program. + self.runCmd("run", RUN_SUCCEEDED) + + # Value of a vector variable should be displayed correctly + self.expect( + "watchpoint set variable global_vector", + WATCHPOINT_CREATED, + substrs=['new value: (1, 2, 3, 4)']) Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_on_vectors/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_on_vectors/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_on_vectors/main.c @@ -0,0 +1,15 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +typedef signed char v4i8 __attribute__ ((vector_size(4))); +v4i8 global_vector = {1, 2, 3, 4}; + +int +main () +{ + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_set_command/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_set_command/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_set_command/Makefile @@ -0,0 +1,6 @@ +LEVEL = ../../../make + +ENABLE_THREADS := YES +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_set_command/TestWatchLocationWithWatchSet.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_set_command/TestWatchLocationWithWatchSet.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_set_command/TestWatchLocationWithWatchSet.py @@ -0,0 +1,107 @@ +""" +Test lldb watchpoint that uses 'watchpoint set -w write -s size' to watch a pointed location with size. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class WatchLocationUsingWatchpointSetTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Our simple source filename. + self.source = 'main.cpp' + # Find the line number to break inside main(). + self.line = line_number( + self.source, '// Set break point at this line.') + # This is for verifying that watch location works. + self.violating_func = "do_bad_thing_with_location" + # Build dictionary to have unique executable names for each test + # method. + + @expectedFailureAll( + oslist=["linux"], + archs=[ + 'aarch64', + 'arm'], + bugnumber="llvm.org/pr26031") + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") + @expectedFailureNetBSD + def test_watchlocation_using_watchpoint_set(self): + """Test watching a location with 'watchpoint set expression -w write -s size' option.""" + self.build() + self.setTearDownCleanup() + + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Add a breakpoint to set a watchpoint when stopped on the breakpoint. + lldbutil.run_break_set_by_file_and_line( + self, None, self.line, num_expected_locations=1) + + # Run the program. + self.runCmd("run", RUN_SUCCEEDED) + + # We should be stopped again due to the breakpoint. + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', + 'stop reason = breakpoint']) + + # Now let's set a write-type watchpoint pointed to by 'g_char_ptr' and + # with offset as 7. + # The main.cpp, by design, misbehaves by not following the agreed upon + # protocol of only accessing the allowable index range of [0, 6]. + self.expect( + "watchpoint set expression -w write -s 1 -- g_char_ptr + 7", + WATCHPOINT_CREATED, + substrs=[ + 'Watchpoint created', + 'size = 1', + 'type = w']) + self.runCmd("expr unsigned val = g_char_ptr[7]; val") + self.expect(self.res.GetOutput().splitlines()[0], exe=False, + endstr=' = 0') + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should be 0 initially. + self.expect("watchpoint list -v", + substrs=['hit_count = 0']) + + self.runCmd("process continue") + + # We should be stopped again due to the watchpoint (write type), but + # only once. The stop reason of the thread should be watchpoint. + self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT, + substrs=['stopped', + 'stop reason = watchpoint', + self.violating_func]) + + # Switch to the thread stopped due to watchpoint and issue some + # commands. + self.switch_to_thread_with_stop_reason(lldb.eStopReasonWatchpoint) + self.runCmd("thread backtrace") + self.runCmd("expr unsigned val = g_char_ptr[7]; val") + self.expect(self.res.GetOutput().splitlines()[0], exe=False, + endstr=' = 99') + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should now be the same as the number of threads that + # stopped on a watchpoint. + threads = lldbutil.get_stopped_threads( + self.process(), lldb.eStopReasonWatchpoint) + self.expect("watchpoint list -v", + substrs=['hit_count = %d' % len(threads)]) + + self.runCmd("thread backtrace all") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_set_command/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_set_command/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_set_command/main.cpp @@ -0,0 +1,115 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include +#include +#include +#include + +std::condition_variable g_condition_variable; +std::mutex g_mutex; +int g_count; + +char *g_char_ptr = nullptr; + +void +barrier_wait() +{ + std::unique_lock lock{g_mutex}; + if (--g_count > 0) + g_condition_variable.wait(lock); + else + g_condition_variable.notify_all(); +} + +void +do_bad_thing_with_location(unsigned index, char *char_ptr, char new_val) +{ + unsigned what = new_val; + printf("new value written to array(%p) and index(%u) = %u\n", char_ptr, index, what); + char_ptr[index] = new_val; +} + +uint32_t +access_pool (bool flag = false) +{ + static std::mutex g_access_mutex; + static unsigned idx = 0; // Well-behaving thread only writes into indexs from 0..6. + if (!flag) + g_access_mutex.lock(); + + // idx valid range is [0, 6]. + if (idx > 6) + idx = 0; + + if (flag) + { + // Write into a forbidden area. + do_bad_thing_with_location(7, g_char_ptr, 99); + } + + unsigned index = idx++; + + if (!flag) + g_access_mutex.unlock(); + return g_char_ptr[index]; +} + +void +thread_func (uint32_t thread_index) +{ + printf ("%s (thread index = %u) startng...\n", __FUNCTION__, thread_index); + + barrier_wait(); + + uint32_t count = 0; + uint32_t val; + while (count++ < 15) + { + printf ("%s (thread = %u) sleeping for 1 second...\n", __FUNCTION__, thread_index); + std::this_thread::sleep_for(std::chrono::seconds(1)); + + if (count < 7) + val = access_pool (); + else + val = access_pool (true); + + printf ("%s (thread = %u) after sleep access_pool returns %d (count=%d)...\n", __FUNCTION__, thread_index, val, count); + } + printf ("%s (thread index = %u) exiting...\n", __FUNCTION__, thread_index); +} + + +int main (int argc, char const *argv[]) +{ + g_count = 4; + std::thread threads[3]; + + g_char_ptr = new char[10]{}; + + // Create 3 threads + for (auto &thread : threads) + thread = std::thread{thread_func, std::distance(threads, &thread)}; + + struct { + int a; + int b; + int c; + } MyAggregateDataType; + + printf ("Before turning all three threads loose...\n"); // Set break point at this line. + barrier_wait(); + + // Join all of our threads + for (auto &thread : threads) + thread.join(); + + delete[] g_char_ptr; + + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_size/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_size/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_size/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_size/TestWatchpointSizes.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_size/TestWatchpointSizes.py +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_size/TestWatchpointSizes.py @@ -0,0 +1,132 @@ +""" +Test watchpoint size cases (1-byte, 2-byte, 4-byte). +Make sure we can watch all bytes, words or double words individually +when they are packed in a 8-byte region. + +""" + +from __future__ import print_function + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class WatchpointSizeTestCase(TestBase): + NO_DEBUG_INFO_TESTCASE = True + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + # Source filename. + self.source = 'main.c' + + # Output filename. + self.exe_name = self.getBuildArtifact("a.out") + self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} + + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") + # Read-write watchpoints not supported on SystemZ + @expectedFailureAll(archs=['s390x']) + def test_byte_size_watchpoints_with_byte_selection(self): + """Test to selectively watch different bytes in a 8-byte array.""" + self.run_watchpoint_size_test('byteArray', 8, '1') + + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") + # Read-write watchpoints not supported on SystemZ + @expectedFailureAll(archs=['s390x']) + def test_two_byte_watchpoints_with_word_selection(self): + """Test to selectively watch different words in an 8-byte word array.""" + self.run_watchpoint_size_test('wordArray', 4, '2') + + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") + # Read-write watchpoints not supported on SystemZ + @expectedFailureAll(archs=['s390x']) + def test_four_byte_watchpoints_with_dword_selection(self): + """Test to selectively watch two double words in an 8-byte dword array.""" + self.run_watchpoint_size_test('dwordArray', 2, '4') + + def run_watchpoint_size_test(self, arrayName, array_size, watchsize): + self.build(dictionary=self.d) + self.setTearDownCleanup(dictionary=self.d) + + exe = self.getBuildArtifact(self.exe_name) + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Detect line number after which we are going to increment arrayName. + loc_line = line_number('main.c', '// About to write ' + arrayName) + + # Set a breakpoint on the line detected above. + lldbutil.run_break_set_by_file_and_line( + self, "main.c", loc_line, num_expected_locations=1, loc_exact=True) + + # Run the program. + self.runCmd("run", RUN_SUCCEEDED) + + for i in range(array_size): + # We should be stopped again due to the breakpoint. + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', 'stop reason = breakpoint']) + + # Set a read_write type watchpoint arrayName + watch_loc = arrayName + "[" + str(i) + "]" + self.expect( + "watchpoint set variable -w read_write " + + watch_loc, + WATCHPOINT_CREATED, + substrs=[ + 'Watchpoint created', + 'size = ' + + watchsize, + 'type = rw']) + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should be 0 initially. + self.expect("watchpoint list -v", substrs=['hit_count = 0']) + + self.runCmd("process continue") + + # We should be stopped due to the watchpoint. + # The stop reason of the thread should be watchpoint. + self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT, + substrs=['stopped', 'stop reason = watchpoint']) + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should now be 1. + self.expect("watchpoint list -v", + substrs=['hit_count = 1']) + + self.runCmd("process continue") + + # We should be stopped due to the watchpoint. + # The stop reason of the thread should be watchpoint. + self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT, + substrs=['stopped', 'stop reason = watchpoint']) + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should now be 1. + # Verify hit_count has been updated after value has been read. + self.expect("watchpoint list -v", + substrs=['hit_count = 2']) + + # Delete the watchpoint immediately, but set auto-confirm to true + # first. + self.runCmd("settings set auto-confirm true") + self.expect( + "watchpoint delete", + substrs=['All watchpoints removed.']) + # Restore the original setting of auto-confirm. + self.runCmd("settings clear auto-confirm") + + self.runCmd("process continue") Index: lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_size/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_size/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/commands/watchpoints/watchpoint_size/main.c @@ -0,0 +1,65 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#include +#include + +uint64_t pad0 = 0; +uint8_t byteArray[8] = {0}; +uint64_t pad1 = 0; +uint16_t wordArray[4] = {0}; +uint64_t pad2 = 0; +uint32_t dwordArray[2] = {0}; + +int main(int argc, char** argv) { + + int i; + uint8_t localByte; + uint16_t localWord; + uint32_t localDword; + + for (i = 0; i < 8; i++) + { + printf("About to write byteArray[%d] ...\n", i); // About to write byteArray + pad0++; + byteArray[i] = 7; + pad1++; + localByte = byteArray[i]; // Here onwards we should'nt be stopped in loop + byteArray[i]++; + localByte = byteArray[i]; + } + + pad0 = 0; + pad1 = 0; + + for (i = 0; i < 4; i++) + { + printf("About to write wordArray[%d] ...\n", i); // About to write wordArray + pad0++; + wordArray[i] = 7; + pad1++; + localWord = wordArray[i]; // Here onwards we should'nt be stopped in loop + wordArray[i]++; + localWord = wordArray[i]; + } + + pad0 = 0; + pad1 = 0; + + for (i = 0; i < 2; i++) + { + printf("About to write dwordArray[%d] ...\n", i); // About to write dwordArray + pad0++; + dwordArray[i] = 7; + pad1++; + localDword = dwordArray[i]; // Here onwards we shouldn't be stopped in loop + dwordArray[i]++; + localDword = dwordArray[i]; + } + + return 0; +} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/.categories =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/.categories +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/.categories @@ -1 +0,0 @@ -expression Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/anonymous-struct/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/anonymous-struct/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/anonymous-struct/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/anonymous-struct/TestCallUserAnonTypedef.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/anonymous-struct/TestCallUserAnonTypedef.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/anonymous-struct/TestCallUserAnonTypedef.py @@ -1,45 +0,0 @@ -""" -Test calling user defined functions using expression evaluation. -This test checks that typesystem lookup works correctly for typedefs of -untagged structures. - -Ticket: https://llvm.org/bugs/show_bug.cgi?id=26790 -""" - -from __future__ import print_function - -import lldb - -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestExprLookupAnonStructTypedef(TestBase): - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - TestBase.setUp(self) - # Find the breakpoint - self.line = line_number('main.cpp', '// lldb testsuite break') - - @expectedFailureAll( - oslist=['linux'], - archs=['arm'], - bugnumber="llvm.org/pr27868") - def test(self): - """Test typedeffed untagged struct arguments for function call expressions""" - self.build() - - self.runCmd("file "+self.getBuildArtifact("a.out"), - CURRENT_EXECUTABLE_SET) - lldbutil.run_break_set_by_file_and_line( - self, - "main.cpp", - self.line, - num_expected_locations=-1, - loc_exact=True - ) - - self.runCmd("run", RUN_SUCCEEDED) - self.expect("expr multiply(&s)", substrs=['$0 = 1']) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/anonymous-struct/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/anonymous-struct/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/anonymous-struct/main.cpp @@ -1,26 +0,0 @@ -#include - -typedef struct { - float f; - int i; -} my_untagged_struct; - -double multiply(my_untagged_struct *s) -{ - return s->f * s->i; -} - -double multiply(my_untagged_struct *s, int x) -{ - return multiply(s) * x; -} - -int main(int argc, char **argv) -{ - my_untagged_struct s = { - .f = (float)argc, - .i = argc, - }; - // lldb testsuite break - return !(multiply(&s, argc) == pow(argc, 3)); -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/TestArgumentPassingRestrictions.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/TestArgumentPassingRestrictions.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/TestArgumentPassingRestrictions.py @@ -1,33 +0,0 @@ -""" -This is a test to ensure that both lldb is reconstructing the right -calling convention for a CXXRecordDecl as represented by: - - DW_CC_pass_by_reference - DW_CC_pass_by_value - -and to also make sure that the ASTImporter is copying over this -setting when importing the CXXRecordDecl via setArgPassingRestrictions. -""" - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestArgumentPassingRestrictions(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @skipIf(compiler="clang", compiler_version=['<', '7.0']) - def test_argument_passing_restrictions(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, '// break here', - lldb.SBFileSpec("main.cpp")) - - self.expect("expr returnPassByRef()", - substrs=['(PassByRef)', '= 11223344']) - - self.expect("expr takePassByRef(p)", - substrs=['(int)', '= 42']) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/main.cpp @@ -1,19 +0,0 @@ -// This structure has a non-trivial copy constructor so -// it needs to be passed by reference. -struct PassByRef { - PassByRef() = default; - PassByRef(const PassByRef &p){x = p.x;}; - - int x = 11223344; -}; - -PassByRef returnPassByRef() { return PassByRef(); } -int takePassByRef(PassByRef p) { - return p.x; -} - -int main() { - PassByRef p = returnPassByRef(); - p.x = 42; - return takePassByRef(p); // break here -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/calculator_mode/TestCalculatorMode.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/calculator_mode/TestCalculatorMode.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/calculator_mode/TestCalculatorMode.py @@ -1,27 +0,0 @@ -""" -Test calling an expression without a target. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestCalculatorMode(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - - def test__calculator_mode(self): - """Test calling expressions in the dummy target.""" - self.expect("expression 11 + 22", "11 + 22 didn't get the expected result", substrs=["33"]) - # Now try it with a specific language: - self.expect("expression -l c -- 11 + 22", "11 + 22 didn't get the expected result", substrs=["33"]) - Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-function/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-function/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-function/Makefile @@ -1,8 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules - -clean:: - rm -rf $(wildcard *.o *.d *.dSYM) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-function/TestCallBuiltinFunction.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-function/TestCallBuiltinFunction.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-function/TestCallBuiltinFunction.py @@ -1,53 +0,0 @@ -""" -Tests calling builtin functions using expression evaluation. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class ExprCommandCallBuiltinFunction(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # Builtins are expanded by Clang, so debug info shouldn't matter. - NO_DEBUG_INFO_TESTCASE = True - - def setUp(self): - 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:') - - def test(self): - self.build() - - # Set breakpoint in main and run exe - self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) - lldbutil.run_break_set_by_file_and_line( - self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True) - - self.runCmd("run", RUN_SUCCEEDED) - - interp = self.dbg.GetCommandInterpreter() - result = lldb.SBCommandReturnObject() - - # Test different builtin functions. - - interp.HandleCommand("expr __builtin_isinf(0.0f)", result) - self.assertEqual(result.GetOutput(), "(int) $0 = 0\n") - - interp.HandleCommand("expr __builtin_isnormal(0.0f)", result) - self.assertEqual(result.GetOutput(), "(int) $1 = 0\n") - - interp.HandleCommand("expr __builtin_constant_p(1)", result) - self.assertEqual(result.GetOutput(), "(int) $2 = 1\n") - - interp.HandleCommand("expr __builtin_abs(-14)", result) - self.assertEqual(result.GetOutput(), "(int) $3 = 14\n") Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-function/TestCallStdStringFunction.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-function/TestCallStdStringFunction.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-function/TestCallStdStringFunction.py @@ -1,57 +0,0 @@ -""" -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__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to break for main.c. - self.line = line_number( - 'main.cpp', - '// Please test these expressions while stopped at this line:') - - @expectedFailureAll( - compiler="icc", - bugnumber="llvm.org/pr14437, fails with ICC 13.1") - @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765") - def test_with(self): - """Test calling std::String member function.""" - self.build() - self.runCmd("file " + self.getBuildArtifact("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) - - self.runCmd("run", RUN_SUCCEEDED) - - self.expect("print str", - 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. - - # clang's libstdc++ on ios arm64 inlines std::string::c_str() always; - # skip this part of the test. - triple = self.dbg.GetSelectedPlatform().GetTriple() - do_cstr_test = True - if triple == "arm64-apple-ios" or triple == "arm64-apple-tvos" or triple == "armv7k-apple-watchos" or triple == "arm64-apple-bridgeos": - do_cstr_test = False - if do_cstr_test: - self.expect("print str.c_str()", - substrs=['Hello world']) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-function/TestCallStopAndContinue.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-function/TestCallStopAndContinue.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-function/TestCallStopAndContinue.py @@ -1,53 +0,0 @@ -""" -Test calling a function, stopping in the call, continue and gather the result on stop. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class ExprCommandCallStopContinueTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to break for main.c. - self.line = line_number( - 'main.cpp', - '// Please test these expressions while stopped at this line:') - self.func_line = line_number('main.cpp', '{5, "five"}') - - def test(self): - """Test gathering result from interrupted function call.""" - self.build() - self.runCmd("file " + self.getBuildArtifact("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) - - 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) - - self.expect("expr -i false -- returnsFive()", error=True, - 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")']) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-function/TestCallUserDefinedFunction.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-function/TestCallUserDefinedFunction.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-function/TestCallUserDefinedFunction.py @@ -1,58 +0,0 @@ -""" -Test calling user defined functions using expression evaluation. - -Note: - LLDBs current first choice of evaluating functions is using the IR interpreter, - which is only supported on Hexagon. Otherwise JIT is used for the evaluation. - -""" - -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__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to break for main.c. - self.line = line_number( - 'main.cpp', - '// Please test these expressions while stopped at this line:') - - def test(self): - """Test return values of user defined function calls.""" - self.build() - - # Set breakpoint in main and run exe - self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) - lldbutil.run_break_set_by_file_and_line( - self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True) - - self.runCmd("run", RUN_SUCCEEDED) - - # Test recursive function call. - self.expect("expr fib(5)", substrs=['$0 = 5']) - - # Test function with more than one paramter - 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']) - - # 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']) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-function/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-function/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-function/main.cpp @@ -1,53 +0,0 @@ -#include -#include -#include - -struct Five -{ - int number; - const char *name; -}; - -Five -returnsFive() -{ - Five my_five = {5, "five"}; - return my_five; -} - -unsigned int -fib(unsigned int n) -{ - if (n < 2) - return n; - else - return fib(n - 1) + fib(n - 2); -} - -int -add(int a, int b) -{ - return a + b; -} - -bool -stringCompare(const char *str) -{ - if (strcmp( str, "Hello world" ) == 0) - return true; - else - return false; -} - -int main (int argc, char const *argv[]) -{ - std::string str = "Hello world"; - std::cout << str << std::endl; - std::cout << str.c_str() << std::endl; - Five main_five = returnsFive(); -#if 0 - print str - print str.c_str() -#endif - return 0; // Please test these expressions while stopped at this line: -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-overridden-method/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-overridden-method/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-overridden-method/Makefile @@ -1,8 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules - -clean:: - rm -rf $(wildcard *.o *.d *.dSYM) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-overridden-method/TestCallOverriddenMethod.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-overridden-method/TestCallOverriddenMethod.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-overridden-method/TestCallOverriddenMethod.py @@ -1,49 +0,0 @@ -""" -Test calling an overriden method. - -Note: - This verifies that LLDB is correctly building the method overrides table. - If this table is not built correctly then calls to overridden methods in - derived classes may generate references to non-existant vtable entries, - as the compiler treats the overridden method as a totally new virtual - method definition. - - -""" - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class ExprCommandCallOverriddenMethod(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to break for main.c. - self.line = line_number('main.cpp', '// Set breakpoint here') - - @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765") - def test(self): - """Test calls to overridden methods in derived classes.""" - self.build() - - # Set breakpoint in main and run exe - self.runCmd("file " + self.getBuildArtifact("a.out"), - CURRENT_EXECUTABLE_SET) - lldbutil.run_break_set_by_file_and_line( - self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True) - - self.runCmd("run", RUN_SUCCEEDED) - - # Test call to method in base class (this should always work as the base - # class method is never an override). - self.expect("expr b->foo()") - - # Test call to overridden method in derived class (this will fail if the - # overrides table is not correctly set up, as Derived::foo will be assigned - # a vtable entry that does not exist in the compiled program). - self.expect("expr d.foo()") Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-overridden-method/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-overridden-method/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-overridden-method/main.cpp @@ -1,16 +0,0 @@ -class Base { -public: - virtual ~Base() {} - virtual void foo() {} -}; - -class Derived : public Base { -public: - virtual void foo() {} -}; - -int main() { - Derived d; - Base *b = &d; - return 0; // Set breakpoint here -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-restarts/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-restarts/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-restarts/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -C_SOURCES := lotta-signals.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-restarts/TestCallThatRestarts.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-restarts/TestCallThatRestarts.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-restarts/TestCallThatRestarts.py @@ -1,166 +0,0 @@ -""" -Test calling a function that hits a signal set to auto-restart, make sure the call completes. -""" - -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__) - NO_DEBUG_INFO_TESTCASE = True - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - - self.main_source = "lotta-signals.c" - 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 - @expectedFlakeyAndroid(bugnumber="llvm.org/pr19246") - def test(self): - """Test calling function that hits a signal and restarts.""" - self.build() - self.call_function() - - 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.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") - - def call_function(self): - (target, process, self.thread, bkpt) = lldbutil.run_to_source_breakpoint(self, - 'Stop here in main.', self.main_source_spec) - - # 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(), "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.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 - options.SetUnwindOnError(True) - - frame = self.thread.GetFrameAtIndex(0) - # 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()) - 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) - options.SetIgnoreBreakpoints(True) - options.SetUnwindOnError(True) - - value = frame.EvaluateExpression( - "call_me (%d)" % - (num_sigchld), options) - - 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(), - "Set SIGCHLD to pass, no-stop, notify") - - value = frame.EvaluateExpression( - "call_me (%d)" % - (num_sigchld), options) - - 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: - options.SetUnwindOnError(False) - value = frame.EvaluateExpression( - "call_me (%d)" % - (num_sigchld), options) - - 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(), - "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.") - - frame = self.thread.GetFrameAtIndex(0) - self.assertTrue( - frame.GetPC() == self.orig_frame_pc, - "Continuing returned to the place we started.") Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-restarts/lotta-signals.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-restarts/lotta-signals.c +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-restarts/lotta-signals.c @@ -1,61 +0,0 @@ -#include -#include -#include - -static int sigchld_no; -static int nosig_no; -static int weird_value; - -void -sigchld_handler (int signo) -{ - sigchld_no++; - printf ("Got sigchld %d.\n", sigchld_no); -} - -int -call_me (int some_value) -{ - int ret_val = 0; - int i; - for (i = 0; i < some_value; i++) - { - int result = 0; - if (i%2 == 0) - result = kill (getpid(), SIGCHLD); - else - sigchld_no++; - - usleep(1000); - if (result == 0) - ret_val++; - } - usleep (10000); - return ret_val; -} - -int -call_me_nosig (int some_value) -{ - int ret_val = 0; - int i; - for (i = 0; i < some_value; i++) - weird_value += i % 4; - - nosig_no += some_value; - return some_value; -} - -int -main () -{ - int ret_val; - signal (SIGCHLD, sigchld_handler); - - ret_val = call_me (2); // Stop here in main. - - ret_val = call_me_nosig (10); - - return 0; - -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-throws/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-throws/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-throws/Makefile @@ -1,6 +0,0 @@ -LEVEL = ../../make - -OBJC_SOURCES := call-throws.m - -include $(LEVEL)/Makefile.rules -LDFLAGS += -framework Foundation Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-throws/TestCallThatThrows.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-throws/TestCallThatThrows.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-throws/TestCallThatThrows.py @@ -1,104 +0,0 @@ -""" -Test calling a function that throws an ObjC exception, make sure that it doesn't propagate the exception. -""" - -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__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - - self.main_source = "call-throws.m" - self.main_source_spec = lldb.SBFileSpec(self.main_source) - - @skipUnlessDarwin - def test(self): - """Test calling a function that throws and ObjC exception.""" - self.build() - self.call_function() - - 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") - - def call_function(self): - """Test calling function that throws.""" - (target, process, self.thread, bkpt) = lldbutil.run_to_source_breakpoint(self, - 'I am about to throw.', self.main_source_spec) - - 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 - self.orig_frame_pc = frame.GetPC() - - 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) - options.SetIgnoreBreakpoints(True) - options.SetUnwindOnError(True) - - value = frame.EvaluateExpression("[my_class callMeIThrow]", options) - - 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) - self.assertTrue(exception_bkpt.GetNumLocations() > 0) - - options.SetIgnoreBreakpoints(True) - options.SetUnwindOnError(True) - - value = frame.EvaluateExpression("[my_class callMeIThrow]", options) - - 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: - options.SetTrapExceptions(False) - 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 - options.SetUnwindOnError(False) - value = frame.EvaluateExpression("[my_class callMeIThrow]", options) - - self.assertTrue( - value.IsValid() and value.GetError().Success() == False) - self.check_after_call() Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-throws/call-throws.m =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-throws/call-throws.m +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/call-throws/call-throws.m @@ -1,47 +0,0 @@ -#import - -@interface MyClass : NSObject -{ -} -- (int) callMeIThrow; -- (int) iCatchMyself; -@end - -@implementation MyClass -- (int) callMeIThrow -{ - NSException *e = [NSException - exceptionWithName:@"JustForTheHeckOfItException" - reason:@"I felt like it" - userInfo:nil]; - @throw e; - return 56; -} - -- (int) iCatchMyself -{ - int return_value = 55; - @try - { - return_value = [self callMeIThrow]; - } - @catch (NSException *e) - { - return_value = 57; - } - return return_value; -} -@end - -int -main () -{ - int return_value; - MyClass *my_class = [[MyClass alloc] init]; - - NSLog (@"I am about to throw."); - - return_value = [my_class iCatchMyself]; - - return return_value; -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/cast_int_to_anonymous_enum/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/cast_int_to_anonymous_enum/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/cast_int_to_anonymous_enum/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/cast_int_to_anonymous_enum/TestCastIntToAnonymousEnum.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/cast_int_to_anonymous_enum/TestCastIntToAnonymousEnum.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/cast_int_to_anonymous_enum/TestCastIntToAnonymousEnum.py @@ -1,22 +0,0 @@ -""" -Test Expression Parser regression text to ensure that we handle anonymous -enums importing correctly. -""" - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class TestCastIntToAnonymousEnum(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def test_cast_int_to_anonymous_enum(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, '// break here', - lldb.SBFileSpec("main.cpp", False)) - - self.expect("expr (flow_e)0", substrs=['(flow_e) $0 = A']) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/cast_int_to_anonymous_enum/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/cast_int_to_anonymous_enum/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/cast_int_to_anonymous_enum/main.cpp @@ -1,9 +0,0 @@ -enum flow_e { - A=0, -}; - -int main() { - flow_e f; - - return 0; // break here -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/char/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/char/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/char/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/char/TestExprsChar.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/char/TestExprsChar.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/char/TestExprsChar.py @@ -1,67 +0,0 @@ -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__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - - self.main_source = "main.cpp" - self.main_source_spec = lldb.SBFileSpec(self.main_source) - - def do_test(self, dictionary=None): - """These basic expression commands should work as expected.""" - self.build(dictionary=dictionary) - - (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, - '// Break here', self.main_source_spec) - frame = thread.GetFrameAtIndex(0) - - value = frame.EvaluateExpression("foo(c)") - self.assertTrue(value.IsValid()) - self.assertTrue(value.GetError().Success()) - self.assertEqual(value.GetValueAsSigned(0), 1) - - value = frame.EvaluateExpression("foo(sc)") - self.assertTrue(value.IsValid()) - self.assertTrue(value.GetError().Success()) - self.assertEqual(value.GetValueAsSigned(0), 2) - - value = frame.EvaluateExpression("foo(uc)") - self.assertTrue(value.IsValid()) - self.assertTrue(value.GetError().Success()) - self.assertEqual(value.GetValueAsSigned(0), 3) - - def test_default_char(self): - self.do_test() - - @expectedFailureAll( - archs=[ - "arm", - "aarch64", - "powerpc64le", - "s390x"], - bugnumber="llvm.org/pr23069") - def test_signed_char(self): - self.do_test(dictionary={'CFLAGS_EXTRAS': '-fsigned-char'}) - - @expectedFailureAll( - archs=[ - "i[3-6]86", - "x86_64", - "arm64", - 'armv7', - 'armv7k'], - bugnumber="llvm.org/pr23069, ") - @expectedFailureAll(triple='mips*', bugnumber="llvm.org/pr23069") - def test_unsigned_char(self): - self.do_test(dictionary={'CFLAGS_EXTRAS': '-funsigned-char'}) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/char/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/char/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/char/main.cpp @@ -1,10 +0,0 @@ -int foo(char c) { return 1; } -int foo(signed char c) { return 2; } -int foo(unsigned char c) { return 3; } - -int main() { - char c = 0; - signed char sc = 0; - unsigned char uc = 0; - return 0; // Break here -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/class_template_specialization_empty_pack/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/class_template_specialization_empty_pack/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/class_template_specialization_empty_pack/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/class_template_specialization_empty_pack/TestClassTemplateSpecializationParametersHandling.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/class_template_specialization_empty_pack/TestClassTemplateSpecializationParametersHandling.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/class_template_specialization_empty_pack/TestClassTemplateSpecializationParametersHandling.py @@ -1,23 +0,0 @@ -""" -Test Expression Parser code gen for ClassTemplateSpecializationDecl to insure -that we generate a TemplateTypeParmDecl in the TemplateParameterList for empty -variadic packs. -""" - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class TestClassTemplateSpecializationParametersHandling(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def test_class_template_specialization(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, '// break here', - lldb.SBFileSpec("main.cpp", False)) - - self.expect("expr -u 0 -- b.foo()", substrs=['$0 = 1']) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/class_template_specialization_empty_pack/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/class_template_specialization_empty_pack/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/class_template_specialization_empty_pack/main.cpp @@ -1,9 +0,0 @@ -template -struct A { - int foo() { return 1;} -}; - -int main() { - A b; - return b.foo(); // break here -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash-incomplete-record/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash-incomplete-record/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash-incomplete-record/Makefile @@ -1,3 +0,0 @@ -LEVEL = ../../make -CXX_SOURCES := main.cpp -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash-incomplete-record/TestCompletionCrashIncompleteRecord.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash-incomplete-record/TestCompletionCrashIncompleteRecord.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash-incomplete-record/TestCompletionCrashIncompleteRecord.py @@ -1,4 +0,0 @@ -from lldbsuite.test import lldbinline -from lldbsuite.test import decorators - -lldbinline.MakeInlineTest(__file__, globals(), [decorators.skipIf(bugnumber="rdar://53756116")]) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash-incomplete-record/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash-incomplete-record/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash-incomplete-record/main.cpp @@ -1,11 +0,0 @@ -int i; -struct F { - int &r; - F() : r(i) {} -}; -template struct unique_ptr { - F i; - unique_ptr() : i() {//%self.dbg.GetCommandInterpreter().HandleCompletion("e ", len("e "), 0, -1, lldb.SBStringList()) -} -}; -int main() {unique_ptr u; } Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash-lambda/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash-lambda/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash-lambda/Makefile @@ -1,3 +0,0 @@ -LEVEL = ../../make -CXX_SOURCES := main.cpp -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash1/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash1/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash1/Makefile @@ -1,3 +0,0 @@ -LEVEL = ../../make -CXX_SOURCES := main.cpp -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash1/TestCompletionCrash1.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash1/TestCompletionCrash1.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash1/TestCompletionCrash1.py @@ -1,4 +0,0 @@ -from lldbsuite.test import lldbinline -from lldbsuite.test import decorators - -lldbinline.MakeInlineTest(__file__, globals(), [decorators.skipIf(bugnumber="rdar://53659341")]) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash1/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash1/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash1/main.cpp @@ -1,12 +0,0 @@ -namespace std { -struct a { - a() {} - a(a &&); -}; -template struct au { - a ay; - ~au() { //%self.dbg.GetCommandInterpreter().HandleCompletion("e ", len("e "), 0, -1, lldb.SBStringList()) - } -}; -} -int main() { std::au{}; } Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash2/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash2/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash2/Makefile @@ -1,3 +0,0 @@ -LEVEL = ../../make -CXX_SOURCES := main.cpp -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash2/TestCompletionCrash2.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash2/TestCompletionCrash2.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash2/TestCompletionCrash2.py @@ -1,4 +0,0 @@ -from lldbsuite.test import lldbinline -from lldbsuite.test import decorators - -lldbinline.MakeInlineTest(__file__, globals(), [decorators.skipIf(bugnumber="rdar://53754063")]) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash2/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash2/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-crash2/main.cpp @@ -1,11 +0,0 @@ -namespace n { -template class a {}; -template struct shared_ptr { - template - static void make_shared() { //%self.dbg.GetCommandInterpreter().HandleCompletion("e ", len("e "), 0, -1, lldb.SBStringList()) - typedef a c; - c d; - } -}; -} // namespace n -int main() { n::shared_ptr::make_shared(); } Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-in-lambda-and-unnnamed-class/TestCompletionInLambdaAndUnnamedClass.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-in-lambda-and-unnnamed-class/TestCompletionInLambdaAndUnnamedClass.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-in-lambda-and-unnnamed-class/TestCompletionInLambdaAndUnnamedClass.py @@ -1,4 +0,0 @@ -from lldbsuite.test import lldbinline -from lldbsuite.test import decorators - -lldbinline.MakeInlineTest(__file__, globals(),) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-in-lambda-and-unnnamed-class/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-in-lambda-and-unnnamed-class/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion-in-lambda-and-unnnamed-class/main.cpp @@ -1,11 +0,0 @@ -int main() { - []() - { //%self.dbg.GetCommandInterpreter().HandleCompletion("e ", len("e "), 0, -1, lldb.SBStringList()) - } - (); - struct { - void f() - { //%self.dbg.GetCommandInterpreter().HandleCompletion("e ", len("e "), 0, -1, lldb.SBStringList()) - } - } A; -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion/.categories =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion/.categories +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion/.categories @@ -1 +0,0 @@ -cmdline Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp other.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion/TestExprCompletion.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion/TestExprCompletion.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion/TestExprCompletion.py @@ -1,255 +0,0 @@ -""" -Test the lldb command line completion mechanism for the 'expr' command. -""" - -from __future__ import print_function - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbplatform -from lldbsuite.test import lldbutil - -class CommandLineExprCompletionTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - NO_DEBUG_INFO_TESTCASE = True - - def test_expr_completion(self): - self.build() - self.main_source = "main.cpp" - self.main_source_spec = lldb.SBFileSpec(self.main_source) - self.dbg.CreateTarget(self.getBuildArtifact("a.out")) - - # Try the completion before we have a context to complete on. - self.assume_no_completions('expr some_expr') - self.assume_no_completions('expr ') - self.assume_no_completions('expr f') - - - (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, - '// Break here', self.main_source_spec) - - # Completing member functions - self.complete_exactly('expr some_expr.FooNoArgs', - 'expr some_expr.FooNoArgsBar()') - self.complete_exactly('expr some_expr.FooWithArgs', - 'expr some_expr.FooWithArgsBar(') - self.complete_exactly('expr some_expr.FooWithMultipleArgs', - 'expr some_expr.FooWithMultipleArgsBar(') - self.complete_exactly('expr some_expr.FooUnderscore', - 'expr some_expr.FooUnderscoreBar_()') - self.complete_exactly('expr some_expr.FooNumbers', - 'expr some_expr.FooNumbersBar1()') - self.complete_exactly('expr some_expr.StaticMemberMethod', - 'expr some_expr.StaticMemberMethodBar()') - - # Completing static functions - self.complete_exactly('expr Expr::StaticMemberMethod', - 'expr Expr::StaticMemberMethodBar()') - - # Completing member variables - self.complete_exactly('expr some_expr.MemberVariab', - 'expr some_expr.MemberVariableBar') - - # Multiple completions - self.completions_contain('expr some_expr.', - ['some_expr.FooNumbersBar1()', - 'some_expr.FooUnderscoreBar_()', - 'some_expr.FooWithArgsBar(', - 'some_expr.MemberVariableBar']) - - self.completions_contain('expr some_expr.Foo', - ['some_expr.FooNumbersBar1()', - 'some_expr.FooUnderscoreBar_()', - 'some_expr.FooWithArgsBar(']) - - self.completions_contain('expr ', - ['static_cast', - 'reinterpret_cast', - 'dynamic_cast']) - - self.completions_contain('expr 1 + ', - ['static_cast', - 'reinterpret_cast', - 'dynamic_cast']) - - # Completion expr without spaces - # This is a bit awkward looking for the user, but that's how - # the completion API works at the moment. - self.completions_contain('expr 1+', - ['1+some_expr', "1+static_cast"]) - - # Test with spaces - self.complete_exactly('expr some_expr .FooNoArgs', - 'expr some_expr .FooNoArgsBar()') - self.complete_exactly('expr some_expr .FooNoArgs', - 'expr some_expr .FooNoArgsBar()') - self.complete_exactly('expr some_expr .FooNoArgs', - 'expr some_expr .FooNoArgsBar()') - self.complete_exactly('expr some_expr. FooNoArgs', - 'expr some_expr. FooNoArgsBar()') - self.complete_exactly('expr some_expr . FooNoArgs', - 'expr some_expr . FooNoArgsBar()') - self.complete_exactly('expr Expr :: StaticMemberMethod', - 'expr Expr :: StaticMemberMethodBar()') - self.complete_exactly('expr Expr ::StaticMemberMethod', - 'expr Expr ::StaticMemberMethodBar()') - self.complete_exactly('expr Expr:: StaticMemberMethod', - 'expr Expr:: StaticMemberMethodBar()') - - # Test that string literals don't break our parsing logic. - self.complete_exactly('expr const char *cstr = "some_e"; char c = *cst', - 'expr const char *cstr = "some_e"; char c = *cstr') - self.complete_exactly('expr const char *cstr = "some_e" ; char c = *cst', - 'expr const char *cstr = "some_e" ; char c = *cstr') - # Requesting completions inside an incomplete string doesn't provide any - # completions. - self.complete_exactly('expr const char *cstr = "some_e', - 'expr const char *cstr = "some_e') - - # Completing inside double dash should do nothing - self.assume_no_completions('expr -i0 -- some_expr.', 10) - self.assume_no_completions('expr -i0 -- some_expr.', 11) - - # Test with expr arguments - self.complete_exactly('expr -i0 -- some_expr .FooNoArgs', - 'expr -i0 -- some_expr .FooNoArgsBar()') - self.complete_exactly('expr -i0 -- some_expr .FooNoArgs', - 'expr -i0 -- some_expr .FooNoArgsBar()') - - # Addrof and deref - self.complete_exactly('expr (*(&some_expr)).FooNoArgs', - 'expr (*(&some_expr)).FooNoArgsBar()') - self.complete_exactly('expr (*(&some_expr)) .FooNoArgs', - 'expr (*(&some_expr)) .FooNoArgsBar()') - self.complete_exactly('expr (* (&some_expr)) .FooNoArgs', - 'expr (* (&some_expr)) .FooNoArgsBar()') - self.complete_exactly('expr (* (& some_expr)) .FooNoArgs', - 'expr (* (& some_expr)) .FooNoArgsBar()') - - # Addrof and deref (part 2) - self.complete_exactly('expr (&some_expr)->FooNoArgs', - 'expr (&some_expr)->FooNoArgsBar()') - self.complete_exactly('expr (&some_expr) ->FooNoArgs', - 'expr (&some_expr) ->FooNoArgsBar()') - self.complete_exactly('expr (&some_expr) -> FooNoArgs', - 'expr (&some_expr) -> FooNoArgsBar()') - self.complete_exactly('expr (&some_expr)-> FooNoArgs', - 'expr (&some_expr)-> FooNoArgsBar()') - - # Builtin arg - self.complete_exactly('expr static_ca', - 'expr static_cast') - - # From other files - self.complete_exactly('expr fwd_decl_ptr->Hidden', - 'expr fwd_decl_ptr->HiddenMember') - - - # Types - self.complete_exactly('expr LongClassNa', - 'expr LongClassName') - self.complete_exactly('expr LongNamespaceName::NestedCla', - 'expr LongNamespaceName::NestedClass') - - # Namespaces - self.complete_exactly('expr LongNamespaceNa', - 'expr LongNamespaceName::') - - # Multiple arguments - self.complete_exactly('expr &some_expr + &some_e', - 'expr &some_expr + &some_expr') - self.complete_exactly('expr SomeLongVarNameWithCapitals + SomeLongVarName', - 'expr SomeLongVarNameWithCapitals + SomeLongVarNameWithCapitals') - self.complete_exactly('expr SomeIntVar + SomeIntV', - 'expr SomeIntVar + SomeIntVar') - - # Multiple statements - self.complete_exactly('expr long LocalVariable = 0; LocalVaria', - 'expr long LocalVariable = 0; LocalVariable') - - # Custom Decls - self.complete_exactly('expr auto l = [](int LeftHandSide, int bx){ return LeftHandS', - 'expr auto l = [](int LeftHandSide, int bx){ return LeftHandSide') - self.complete_exactly('expr struct LocalStruct { long MemberName; } ; LocalStruct S; S.Mem', - 'expr struct LocalStruct { long MemberName; } ; LocalStruct S; S.MemberName') - - # Completing function call arguments - self.complete_exactly('expr some_expr.FooWithArgsBar(some_exp', - 'expr some_expr.FooWithArgsBar(some_expr') - self.complete_exactly('expr some_expr.FooWithArgsBar(SomeIntV', - 'expr some_expr.FooWithArgsBar(SomeIntVar') - self.complete_exactly('expr some_expr.FooWithMultipleArgsBar(SomeIntVar, SomeIntVa', - 'expr some_expr.FooWithMultipleArgsBar(SomeIntVar, SomeIntVar') - - # Function return values - self.complete_exactly('expr some_expr.Self().FooNoArgs', - 'expr some_expr.Self().FooNoArgsBar()') - self.complete_exactly('expr some_expr.Self() .FooNoArgs', - 'expr some_expr.Self() .FooNoArgsBar()') - self.complete_exactly('expr some_expr.Self(). FooNoArgs', - 'expr some_expr.Self(). FooNoArgsBar()') - - def test_expr_completion_with_descriptions(self): - self.build() - self.main_source = "main.cpp" - self.main_source_spec = lldb.SBFileSpec(self.main_source) - self.dbg.CreateTarget(self.getBuildArtifact("a.out")) - - (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, - '// Break here', self.main_source_spec) - - self.check_completion_with_desc("expr ", [ - # VarDecls have their type as description. - ["some_expr", "Expr &"], - # builtin types have no description. - ["int", ""], - ["float", ""] - ]) - self.check_completion_with_desc("expr some_expr.", [ - # Functions have their signature as description. - ["some_expr.Self()", "Expr &Self()"], - ["some_expr.operator=(", "inline Expr &operator=(const Expr &)"], - ["some_expr.FooNumbersBar1()", "int FooNumbersBar1()"], - ["some_expr.StaticMemberMethodBar()", "static int StaticMemberMethodBar()"], - ["some_expr.FooWithArgsBar(", "int FooWithArgsBar(int)"], - ["some_expr.FooNoArgsBar()", "int FooNoArgsBar()"], - ["some_expr.FooUnderscoreBar_()", "int FooUnderscoreBar_()"], - ["some_expr.FooWithMultipleArgsBar(", "int FooWithMultipleArgsBar(int, int)"], - ["some_expr.~Expr()", "inline ~Expr()"], - # FieldDecls have their type as description. - ["some_expr.MemberVariableBar", "int"], - ]) - - def assume_no_completions(self, str_input, cursor_pos = None): - interp = self.dbg.GetCommandInterpreter() - match_strings = lldb.SBStringList() - if cursor_pos is None: - cursor_pos = len(str_input) - num_matches = interp.HandleCompletion(str_input, cursor_pos, 0, -1, match_strings) - - available_completions = [] - for m in match_strings: - available_completions.append(m) - - self.assertEquals(num_matches, 0, "Got matches, but didn't expect any: " + str(available_completions)) - - def completions_contain(self, str_input, items): - interp = self.dbg.GetCommandInterpreter() - match_strings = lldb.SBStringList() - num_matches = interp.HandleCompletion(str_input, len(str_input), 0, -1, match_strings) - common_match = match_strings.GetStringAtIndex(0) - - for item in items: - found = False - for m in match_strings: - if m == item: - found = True - if not found: - # Transform match_strings to a python list with strings - available_completions = [] - for m in match_strings: - available_completions.append(m) - self.assertTrue(found, "Couldn't find completion " + item + " in completions " + str(available_completions)) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion/main.cpp @@ -1,35 +0,0 @@ -namespace LongNamespaceName { class NestedClass { long m; }; } - -// Defined in other.cpp, we only have a forward declaration here. -struct ForwardDecl; -extern ForwardDecl fwd_decl; - -class LongClassName { long i ; }; - -class Expr { -public: - int FooNoArgsBar() { return 1; } - int FooWithArgsBar(int i) { return i; } - int FooWithMultipleArgsBar(int i, int j) { return i + j; } - int FooUnderscoreBar_() { return 4; } - int FooNumbersBar1() { return 8; } - int MemberVariableBar = 0; - Expr &Self() { return *this; } - static int StaticMemberMethodBar() { return 82; } -}; - -int main() -{ - LongClassName a; - LongNamespaceName::NestedClass NestedFoo; - long SomeLongVarNameWithCapitals = 44; - int SomeIntVar = 33; - Expr some_expr; - some_expr.FooNoArgsBar(); - some_expr.FooWithArgsBar(1); - some_expr.FooUnderscoreBar_(); - some_expr.FooNumbersBar1(); - Expr::StaticMemberMethodBar(); - ForwardDecl *fwd_decl_ptr = &fwd_decl; - return 0; // Break here -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion/other.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion/other.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/completion/other.cpp @@ -1,4 +0,0 @@ -struct ForwardDecl { - long HiddenMemberName; -}; -ForwardDecl fwd_decl; Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/context-object-objc/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/context-object-objc/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/context-object-objc/Makefile @@ -1,6 +0,0 @@ -LEVEL = ../../make - -OBJC_SOURCES := main.m - -include $(LEVEL)/Makefile.rules -LDFLAGS += -framework Foundation Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/context-object-objc/TestContextObjectObjc.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/context-object-objc/TestContextObjectObjc.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/context-object-objc/TestContextObjectObjc.py @@ -1,78 +0,0 @@ -""" -Tests expression evaluation in context of an objc class. -""" - -import lldb -import lldbsuite.test.lldbutil as lldbutil -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * - -class ContextObjectObjcTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @skipUnlessDarwin - def test_context_object_objc(self): - """Tests expression evaluation in context of an objc class.""" - self.build() - - (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, '// Break here', self.main_source_spec) - frame = thread.GetFrameAtIndex(0) - - # - # Test objc class variable - # - - obj_val = frame.FindVariable("objcClass") - self.assertTrue(obj_val.IsValid()) - obj_val = obj_val.Dereference() - self.assertTrue(obj_val.IsValid()) - - # Test an empty expression evaluation - value = obj_val.EvaluateExpression("") - self.assertFalse(value.IsValid()) - self.assertFalse(value.GetError().Success()) - - # Test retrieving of a field (not a local with the same name) - value = obj_val.EvaluateExpression("field") - self.assertTrue(value.IsValid()) - self.assertTrue(value.GetError().Success()) - self.assertEqual(value.GetValueAsSigned(), 1111) - - # Test if the self pointer is properly evaluated - - # Test retrieving of an objcClass's property through the self pointer - value = obj_val.EvaluateExpression("self.property") - self.assertTrue(value.IsValid()) - self.assertTrue(value.GetError().Success()) - self.assertEqual(value.GetValueAsSigned(), 2222) - - # Test objcClass's methods evaluation through the self pointer - value = obj_val.EvaluateExpression("[self method]") - self.assertTrue(value.IsValid()) - self.assertTrue(value.GetError().Success()) - self.assertEqual(value.GetValueAsSigned(), 3333) - - # Test if we can use a computation result reference object correctly - - obj_val = frame.EvaluateExpression("[ObjcClass createNew]") - self.assertTrue(obj_val.IsValid()) - obj_val = obj_val.Dereference() - self.assertTrue(obj_val.IsValid()) - - # Test an expression evaluation on it - value = obj_val.EvaluateExpression("1") - self.assertTrue(value.IsValid()) - self.assertTrue(value.GetError().Success()) - - # Test retrieving of a field on it - value = obj_val.EvaluateExpression("field") - self.assertTrue(value.IsValid()) - self.assertTrue(value.GetError().Success()) - self.assertEqual(value.GetValueAsSigned(), 1111) - - def setUp(self): - TestBase.setUp(self) - - self.main_source = "main.m" - self.main_source_spec = lldb.SBFileSpec(self.main_source) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/context-object-objc/main.m =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/context-object-objc/main.m +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/context-object-objc/main.m @@ -1,47 +0,0 @@ -#import - -@interface ObjcClass : NSObject { - int field; -} - -@property int property; - -+(ObjcClass*)createNew; - --(id)init; - --(int)method; - -@end - -@implementation ObjcClass - -+(ObjcClass*)createNew { - return [ObjcClass new]; -} - --(id)init { - self = [super init]; - if (self) { - field = 1111; - _property = 2222; - } - return self; -} - --(int)method { - return 3333; -} - -@end - -int main() -{ - @autoreleasepool { - ObjcClass* objcClass = [ObjcClass new]; - - int field = 4444; - - return 0; // Break here - } -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/context-object/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/context-object/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/context-object/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/context-object/TestContextObject.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/context-object/TestContextObject.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/context-object/TestContextObject.py @@ -1,145 +0,0 @@ -""" -Tests expression evaluation in context of an object. -""" - -import lldb -import lldbsuite.test.lldbutil as lldbutil -from lldbsuite.test.lldbtest import * - -class ContextObjectTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def test_context_object(self): - """Tests expression evaluation in context of an object.""" - self.build() - - (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, '// Break here', self.main_source_spec) - frame = thread.GetFrameAtIndex(0) - - # - # Test C++ struct variable - # - - obj_val = frame.FindVariable("cpp_struct") - self.assertTrue(obj_val.IsValid()) - - # Test an empty expression evaluation - value = obj_val.EvaluateExpression("") - self.assertFalse(value.IsValid()) - self.assertFalse(value.GetError().Success()) - - # Test retrieveing of a field (not a local with the same name) - value = obj_val.EvaluateExpression("field") - self.assertTrue(value.IsValid()) - self.assertTrue(value.GetError().Success()) - self.assertEqual(value.GetValueAsSigned(), 1111) - - # Test functions evaluation - value = obj_val.EvaluateExpression("function()") - self.assertTrue(value.IsValid()) - self.assertTrue(value.GetError().Success()) - self.assertEqual(value.GetValueAsSigned(), 2222) - - # Test that we retrieve the right global - value = obj_val.EvaluateExpression("global.field") - self.assertTrue(value.IsValid()) - self.assertTrue(value.GetError().Success()) - self.assertEqual(value.GetValueAsSigned(), 1111) - - # - # Test C++ union variable - # - - obj_val = frame.FindVariable("cpp_union") - self.assertTrue(obj_val.IsValid()) - - # Test retrieveing of a field - value = obj_val.EvaluateExpression("field_int") - self.assertTrue(value.IsValid()) - self.assertTrue(value.GetError().Success()) - self.assertEqual(value.GetValueAsSigned(), 5555) - - # - # Test C++ scalar - # - - obj_val = frame.FindVariable("cpp_scalar") - self.assertTrue(obj_val.IsValid()) - - # Test an expression evaluation - value = obj_val.EvaluateExpression("1") - self.assertFalse(value.IsValid()) - self.assertFalse(value.GetError().Success()) - - # - # Test C++ array - # - - obj_val = frame.FindVariable("cpp_array") - self.assertTrue(obj_val.IsValid()) - - # Test an expression evaluation - value = obj_val.EvaluateExpression("1") - self.assertFalse(value.IsValid()) - self.assertFalse(value.GetError().Success()) - - # Test retrieveing of an element's field - value = obj_val.GetValueForExpressionPath("[7]").EvaluateExpression("field") - self.assertTrue(value.IsValid()) - self.assertTrue(value.GetError().Success()) - self.assertEqual(value.GetValueAsSigned(), 1111) - - # - # Test C++ pointer - # - - obj_val = frame.FindVariable("cpp_pointer") - self.assertTrue(obj_val.IsValid()) - - # Test an expression evaluation - value = obj_val.EvaluateExpression("1") - self.assertFalse(value.IsValid()) - self.assertFalse(value.GetError().Success()) - - # Test retrieveing of a dereferenced object's field - value = obj_val.Dereference().EvaluateExpression("field") - self.assertTrue(value.IsValid()) - self.assertTrue(value.GetError().Success()) - self.assertEqual(value.GetValueAsSigned(), 1111) - - # - # Test C++ computation result - # - - obj_val = frame.EvaluateExpression("cpp_namespace::GetCppStruct()") - self.assertTrue(obj_val.IsValid()) - - # Test an expression evaluation - value = obj_val.EvaluateExpression("1") - self.assertTrue(value.IsValid()) - self.assertFalse(value.GetError().Success()) - - # - # Test C++ computation result located in debuggee memory - # - - obj_val = frame.EvaluateExpression("cpp_namespace::GetCppStructPtr()") - self.assertTrue(obj_val.IsValid()) - - # Test an expression evaluation - value = obj_val.EvaluateExpression("1") - self.assertFalse(value.IsValid()) - self.assertFalse(value.GetError().Success()) - - # Test retrieveing of a dereferenced object's field - value = obj_val.Dereference().EvaluateExpression("field") - self.assertTrue(value.IsValid()) - self.assertTrue(value.GetError().Success()) - self.assertEqual(value.GetValueAsSigned(), 1111) - - def setUp(self): - TestBase.setUp(self) - - self.main_source = "main.cpp" - self.main_source_spec = lldb.SBFileSpec(self.main_source) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/context-object/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/context-object/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/context-object/main.cpp @@ -1,46 +0,0 @@ -namespace cpp_namespace { - struct CppStruct { - int field = 1111; - - int function() { - return 2222; - } - }; - - union CppUnion { - char field_char; - short field_short; - int field_int; - }; - - CppStruct GetCppStruct() { - return CppStruct(); - } - - CppStruct global; - - CppStruct *GetCppStructPtr() { - return &global; - } -} - -int global = 3333; - -int main() -{ - cpp_namespace::CppStruct cpp_struct = cpp_namespace::GetCppStruct(); - cpp_struct.function(); - - int field = 4444; - - cpp_namespace::CppUnion cpp_union; - cpp_union.field_int = 5555; - - int cpp_scalar = 6666; - - cpp_namespace::CppStruct cpp_array[16]; - - cpp_namespace::CppStruct *cpp_pointer = cpp_namespace::GetCppStructPtr(); - - return 0; // Break here -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/dollar-in-variable/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/dollar-in-variable/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/dollar-in-variable/Makefile @@ -1,3 +0,0 @@ -LEVEL = ../../make -C_SOURCES := main.c -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/dollar-in-variable/TestDollarInVariable.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/dollar-in-variable/TestDollarInVariable.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/dollar-in-variable/TestDollarInVariable.py @@ -1,5 +0,0 @@ -from lldbsuite.test import lldbinline -from lldbsuite.test import decorators - -lldbinline.MakeInlineTest(__file__, globals(), - [lldbinline.expectedFailureAll(oslist=["windows"])]) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/dollar-in-variable/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/dollar-in-variable/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/dollar-in-variable/main.c @@ -1,21 +0,0 @@ -// Make sure we correctly handle $ in variable names. - -int main() { - // Some variables that might conflict with our variables below. - int __lldb_expr_result = 2; - int $$foo = 1; - int R0 = 2; - - // Some variables with dollar signs that should work (and shadow - // any built-in LLDB variables). - int $__lldb_expr_result = 11; - int $foo = 12; - int $R0 = 13; - int $0 = 14; - - //%self.expect("expr $__lldb_expr_result", substrs=['(int) $0 = 11']) - //%self.expect("expr $foo", substrs=['(int)', ' = 12']) - //%self.expect("expr $R0", substrs=['(int)', ' = 13']) - //%self.expect("expr int $foo = 123", error=True, substrs=["declaration conflicts"]) - return 0; //%self.expect("expr $0", substrs=['(int)', ' = 14']) -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/dont_allow_jit/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/dont_allow_jit/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/dont_allow_jit/Makefile @@ -1,6 +0,0 @@ -LEVEL = ../../make - -C_SOURCES := main.c -CFLAGS_EXTRAS += -std=c99 - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/dont_allow_jit/TestAllowJIT.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/dont_allow_jit/TestAllowJIT.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/dont_allow_jit/TestAllowJIT.py @@ -1,87 +0,0 @@ -""" -Test that --allow-jit=false does disallow JITting: -""" - -from __future__ import print_function - - -import lldb -import lldbsuite.test.lldbutil as lldbutil -from lldbsuite.test.lldbtest import * -from lldbsuite.test.decorators import * - -class TestAllowJIT(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # If your test case doesn't stress debug info, the - # set this to true. That way it won't be run once for - # each debug info format. - NO_DEBUG_INFO_TESTCASE = True - - def test_allow_jit_expr_command(self): - """Test the --allow-jit command line flag""" - self.build() - self.main_source_file = lldb.SBFileSpec("main.c") - self.expr_cmd_test() - - def test_allow_jit_options(self): - """Test the SetAllowJIT SBExpressionOption setting""" - self.build() - self.main_source_file = lldb.SBFileSpec("main.c") - self.expr_options_test() - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - - def expr_cmd_test(self): - (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, - "Set a breakpoint here", self.main_source_file) - - frame = thread.GetFrameAtIndex(0) - - # First make sure we can call the function with - interp = self.dbg.GetCommandInterpreter() - self.expect("expr --allow-jit 1 -- call_me(10)", - substrs = ["(int) $", "= 18"]) - # Now make sure it fails with the "can't IR interpret message" if allow-jit is false: - self.expect("expr --allow-jit 0 -- call_me(10)", - error=True, - substrs = ["Can't run the expression locally"]) - - def expr_options_test(self): - (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, - "Set a breakpoint here", self.main_source_file) - - frame = thread.GetFrameAtIndex(0) - - # First make sure we can call the function with the default option set. - options = lldb.SBExpressionOptions() - # Check that the default is to allow JIT: - self.assertEqual(options.GetAllowJIT(), True, "Default is true") - - # Now use the options: - result = frame.EvaluateExpression("call_me(10)", options) - self.assertTrue(result.GetError().Success(), "expression succeeded") - self.assertEqual(result.GetValueAsSigned(), 18, "got the right value.") - - # Now disallow JIT and make sure it fails: - options.SetAllowJIT(False) - # Check that we got the right value: - self.assertEqual(options.GetAllowJIT(), False, "Got False after setting to False") - - # Again use it and ensure we fail: - result = frame.EvaluateExpression("call_me(10)", options) - self.assertTrue(result.GetError().Fail(), "expression failed with no JIT") - self.assertTrue("Can't run the expression locally" in result.GetError().GetCString(), "Got right error") - - # Finally set the allow JIT value back to true and make sure that works: - options.SetAllowJIT(True) - self.assertEqual(options.GetAllowJIT(), True, "Set back to True correctly") - - # And again, make sure this works: - result = frame.EvaluateExpression("call_me(10)", options) - self.assertTrue(result.GetError().Success(), "expression succeeded") - self.assertEqual(result.GetValueAsSigned(), 18, "got the right value.") - Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/dont_allow_jit/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/dont_allow_jit/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/dont_allow_jit/main.c @@ -1,15 +0,0 @@ -#include - -int -call_me(int input) -{ - return printf("I was called: %d.\n", input); -} - -int -main() -{ - int test_var = 10; - printf ("Set a breakpoint here: %d.\n", test_var); - return call_me(100); -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/expr-in-syscall/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/expr-in-syscall/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/expr-in-syscall/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/expr-in-syscall/TestExpressionInSyscall.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/expr-in-syscall/TestExpressionInSyscall.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/expr-in-syscall/TestExpressionInSyscall.py @@ -1,92 +0,0 @@ -"""Test that we are able to evaluate expressions when the inferior is blocked in a syscall""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class ExprSyscallTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @expectedFailureAll( - oslist=["windows"], - bugnumber="llvm.org/pr21765, getpid() does not exist on Windows") - @expectedFailureNetBSD - def test_setpgid(self): - self.build() - self.expr_syscall() - - def expr_syscall(self): - exe = self.getBuildArtifact("a.out") - - # Create a target by the debugger. - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, VALID_TARGET) - - listener = lldb.SBListener("my listener") - - # 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 - - self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID) - - event = lldb.SBEvent() - - # Give the child enough time to reach the syscall, - # while clearing out all the pending events. - # The last WaitForEvent call will time out after 2 seconds. - while listener.WaitForEvent(2, event): - pass - - # now the process should be running (blocked in the syscall) - self.assertEqual( - process.GetState(), - lldb.eStateRunning, - "Process is running") - - # send the process a signal - process.SendAsyncInterrupt() - while listener.WaitForEvent(2, event): - 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) - 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())]) - - # and run the process to completion - process.Continue() - - # process all events - while listener.WaitForEvent(10, event): - new_state = lldb.SBProcess.GetStateFromEvent(event) - if new_state == lldb.eStateExited: - break - - self.assertEqual(process.GetState(), lldb.eStateExited) - self.assertEqual(process.GetExitStatus(), 0) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/expr-in-syscall/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/expr-in-syscall/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/expr-in-syscall/main.cpp @@ -1,12 +0,0 @@ -#include -#include - -volatile int release_flag = 0; - -int main(int argc, char const *argv[]) -{ - while (! release_flag) // Wait for debugger to attach - std::this_thread::sleep_for(std::chrono::seconds(3)); - - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/fixits/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/fixits/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/fixits/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/fixits/TestFixIts.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/fixits/TestFixIts.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/fixits/TestFixIts.py @@ -1,72 +0,0 @@ -""" -Test calling an expression with errors that a FixIt can fix. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class ExprCommandWithFixits(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - - self.main_source = "main.cpp" - self.main_source_spec = lldb.SBFileSpec(self.main_source) - - @skipUnlessDarwin - def test_with_target(self): - """Test calling expressions with errors that can be fixed by the FixIts.""" - self.build() - self.try_expressions() - - def test_with_dummy_target(self): - """Test calling expressions in the dummy target with errors that can be fixed by the FixIts.""" - ret_val = lldb.SBCommandReturnObject() - result = self.dbg.GetCommandInterpreter().HandleCommand("expression ((1 << 16) - 1))", ret_val) - self.assertEqual(result, lldb.eReturnStatusSuccessFinishResult, "The expression was successful.") - self.assertTrue("Fix-it applied" in ret_val.GetError(), "Found the applied FixIt.") - - def try_expressions(self): - """Test calling expressions with errors that can be fixed by the FixIts.""" - (target, process, self.thread, bkpt) = lldbutil.run_to_source_breakpoint(self, - 'Stop here to evaluate expressions', self.main_source_spec) - - options = lldb.SBExpressionOptions() - options.SetAutoApplyFixIts(True) - - frame = self.thread.GetFrameAtIndex(0) - - # Try with one error: - value = frame.EvaluateExpression("my_pointer.first", options) - self.assertTrue(value.IsValid()) - self.assertTrue(value.GetError().Success()) - self.assertTrue(value.GetValueAsUnsigned() == 10) - - # Try with two errors: - two_error_expression = "my_pointer.second->a" - value = frame.EvaluateExpression(two_error_expression, options) - self.assertTrue(value.IsValid()) - self.assertTrue(value.GetError().Success()) - self.assertTrue(value.GetValueAsUnsigned() == 20) - - # Now turn off the fixits, and the expression should fail: - options.SetAutoApplyFixIts(False) - value = frame.EvaluateExpression(two_error_expression, options) - self.assertTrue(value.IsValid()) - self.assertTrue(value.GetError().Fail()) - error_string = value.GetError().GetCString() - self.assertTrue( - error_string.find("fixed expression suggested:") != -1, - "Fix was suggested") - self.assertTrue( - error_string.find("my_pointer->second.a") != -1, - "Fix was right") Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/fixits/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/fixits/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/fixits/main.cpp @@ -1,25 +0,0 @@ -#include - -struct SubStruct -{ - int a; - int b; -}; - -struct MyStruct -{ - int first; - struct SubStruct second; -}; - -int -main() -{ - struct MyStruct my_struct = {10, {20, 30}}; - struct MyStruct *my_pointer = &my_struct; - printf ("Stop here to evaluate expressions: %d %d %p\n", my_pointer->first, my_pointer->second.a, my_pointer); - return 0; -} - - - Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/formatters/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/formatters/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/formatters/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/formatters/TestFormatters.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/formatters/TestFormatters.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/formatters/TestFormatters.py @@ -1,287 +0,0 @@ -""" -Test using LLDB data formatters with frozen objects coming from the expression parser. -""" - -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__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to break for main.cpp. - self.line = line_number('main.cpp', - '// Stop here') - - @skipIfFreeBSD # llvm.org/pr24691 skipping to avoid crashing the test runner - @expectedFailureNetBSD - @expectedFailureAll( - oslist=['freebsd'], - bugnumber='llvm.org/pr19011 Newer Clang omits C1 complete object constructor') - @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765") - @skipIfTargetAndroid() # skipping to avoid crashing the test runner - @expectedFailureAndroid('llvm.org/pr24691') # we hit an assertion in clang - def test(self): - """Test expr + formatters for good interoperability.""" - 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 " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) - - 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.filecheck("expression --show-types -- *(new foo(47))", __file__, - '-check-prefix=EXPR-TYPES-NEW-FOO') - # EXPR-TYPES-NEW-FOO: (foo) ${{.*}} = { - # EXPR-TYPES-NEW-FOO-NEXT: (int) a = 47 - # EXPR-TYPES-NEW-FOO-NEXT: (int *) a_ptr = 0x - # EXPR-TYPES-NEW-FOO-NEXT: (bar) b = { - # EXPR-TYPES-NEW-FOO-NEXT: (int) i = 94 - # EXPR-TYPES-NEW-FOO-NEXT: (int *) i_ptr = 0x - # EXPR-TYPES-NEW-FOO-NEXT: (baz) b = { - # EXPR-TYPES-NEW-FOO-NEXT: (int) h = 97 - # EXPR-TYPES-NEW-FOO-NEXT: (int) k = 99 - # EXPR-TYPES-NEW-FOO-NEXT: } - # EXPR-TYPES-NEW-FOO-NEXT: (baz &) b_ref = 0x - # EXPR-TYPES-NEW-FOO-NEXT: } - # EXPR-TYPES-NEW-FOO-NEXT: } - - self.runCmd("type summary add -F formatters.foo_SummaryProvider foo") - - self.expect("expression new int(12)", - substrs=['(int *) $', ' = 0x']) - - self.runCmd( - "type summary add -s \"${var%pointer} -> ${*var%decimal}\" \"int *\"") - - self.expect("expression new int(12)", - substrs=['(int *) $', '= 0x', ' -> 12']) - - self.expect("expression foo1.a_ptr", - substrs=['(int *) $', '= 0x', ' -> 13']) - - self.filecheck("expression foo1", __file__, '-check-prefix=EXPR-FOO1') - # EXPR-FOO1: (foo) $ - # EXPR-FOO1-SAME: a = 12 - # EXPR-FOO1-SAME: a_ptr = {{[0-9]+}} -> 13 - # EXPR-FOO1-SAME: i = 24 - # EXPR-FOO1-SAME: i_ptr = {{[0-9]+}} -> 25 - # EXPR-FOO1-SAME: b_ref = {{[0-9]+}} - # EXPR-FOO1-SAME: h = 27 - # EXPR-FOO1-SAME: k = 29 - - self.filecheck("expression --ptr-depth=1 -- new foo(47)", __file__, - '-check-prefix=EXPR-PTR-DEPTH1') - # EXPR-PTR-DEPTH1: (foo *) $ - # EXPR-PTR-DEPTH1-SAME: a = 47 - # EXPR-PTR-DEPTH1-SAME: a_ptr = {{[0-9]+}} -> 48 - # EXPR-PTR-DEPTH1-SAME: i = 94 - # EXPR-PTR-DEPTH1-SAME: i_ptr = {{[0-9]+}} -> 95 - - self.filecheck("expression foo2", __file__, '-check-prefix=EXPR-FOO2') - # EXPR-FOO2: (foo) $ - # EXPR-FOO2-SAME: a = 121 - # EXPR-FOO2-SAME: a_ptr = {{[0-9]+}} -> 122 - # EXPR-FOO2-SAME: i = 242 - # EXPR-FOO2-SAME: i_ptr = {{[0-9]+}} -> 243 - # EXPR-FOO2-SAME: h = 245 - # EXPR-FOO2-SAME: k = 247 - - object_name = self.res.GetOutput() - object_name = object_name[7:] - object_name = object_name[0:object_name.find(' =')] - - self.filecheck("frame variable foo2", __file__, '-check-prefix=VAR-FOO2') - # VAR-FOO2: (foo) foo2 - # VAR-FOO2-SAME: a = 121 - # VAR-FOO2-SAME: a_ptr = {{[0-9]+}} -> 122 - # VAR-FOO2-SAME: i = 242 - # VAR-FOO2-SAME: i_ptr = {{[0-9]+}} -> 243 - # VAR-FOO2-SAME: h = 245 - # VAR-FOO2-SAME: k = 247 - - # The object is the same as foo2, so use the EXPR-FOO2 checks. - self.filecheck("expression $" + object_name, __file__, - '-check-prefix=EXPR-FOO2') - - self.runCmd("type summary delete foo") - self.runCmd( - "type synthetic add --python-class foosynth.FooSyntheticProvider foo") - - self.expect("expression --show-types -- $" + object_name, - substrs=['(foo) $', ' = {', '(int) *i_ptr = 243']) - - self.runCmd("n") - self.runCmd("n") - - 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 $" + object_name + '.a', - 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']) - - self.runCmd("type summary delete foo") - self.runCmd( - "type synthetic add --python-class foosynth.FooSyntheticProvider foo") - - self.expect("expression --show-types -- $" + object_name, - 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']) - - process = self.dbg.GetSelectedTarget().GetProcess() - thread = process.GetThreadAtIndex(0) - frame = thread.GetSelectedFrame() - - frozen = frame.EvaluateExpression("$" + object_name + ".a_ptr") - - a_data = frozen.GetPointeeData() - - error = lldb.SBError() - self.assertTrue( - a_data.GetUnsignedInt32( - error, - 0) == 122, - '*a_ptr = 122') - - self.runCmd("n") - self.runCmd("n") - self.runCmd("n") - - self.expect("frame variable numbers", - substrs=['1', '2', '3', '4', '5']) - - self.expect("expression numbers", - 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') - - 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') Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/formatters/foosynth.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/formatters/foosynth.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/formatters/foosynth.py @@ -1,33 +0,0 @@ -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') Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/formatters/formatters.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/formatters/formatters.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/formatters/formatters.py @@ -1,17 +0,0 @@ -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)) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/formatters/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/formatters/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/formatters/main.cpp @@ -1,48 +0,0 @@ -#include -#include - -struct baz - { - int h; - int k; - baz(int a, int b) : h(a), k(b) {} - }; - -struct bar - { - int i; - int* i_ptr; - baz b; - baz& b_ref; - bar(int x) : i(x),i_ptr(new int(x+1)),b(i+3,i+5),b_ref(b) {} - }; - -struct foo - { - int a; - int* a_ptr; - bar b; - - foo(int x) : a(x), - a_ptr(new int(x+1)), - b(2*x) {} - - }; - -int main(int argc, char** argv) -{ - foo foo1(12); - foo foo2(121); - - foo2.a = 7777; // Stop here - *(foo2.b.i_ptr) = 8888; - foo2.b.b.h = 9999; - - *(foo1.a_ptr) = 9999; - foo1.b.i = 9999; - - int numbers[5] = {1,2,3,4,5}; - - return 0; - -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/function_template_specialization_temp_args/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/function_template_specialization_temp_args/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/function_template_specialization_temp_args/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/function_template_specialization_temp_args/TestFunctionTemplateSpecializationTempArgs.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/function_template_specialization_temp_args/TestFunctionTemplateSpecializationTempArgs.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/function_template_specialization_temp_args/TestFunctionTemplateSpecializationTempArgs.py @@ -1,17 +0,0 @@ -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class TestFunctionTemplateSpecializationTempArgs(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def test_function_template_specialization_temp_args(self): - self.build() - - (self.target, self.process, _, bkpt) = lldbutil.run_to_source_breakpoint(self, '// break here', - lldb.SBFileSpec("main.cpp", False)) - - self.expect("expr p0", - substrs=['(VType) $0 = {}']) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/function_template_specialization_temp_args/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/function_template_specialization_temp_args/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/function_template_specialization_temp_args/main.cpp @@ -1,17 +0,0 @@ -template struct M {}; - -template void f(T &t); - -template <> void f(int &t) { - typedef M VType; - - VType p0; // break here -} - -int main() { - int x; - - f(x); - - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/basic/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/basic/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/basic/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make -USE_LIBCPP := 1 -CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) -CXX_SOURCES := main.cpp -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/basic/TestImportStdModule.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/basic/TestImportStdModule.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/basic/TestImportStdModule.py @@ -1,56 +0,0 @@ -""" -Test importing the 'std' C++ module and evaluate expressions with it. -""" - -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class ImportStdModule(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # FIXME: This should work on more setups, so remove these - # skipIf's in the future. - @add_test_categories(["libc++"]) - @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) - @skipIf(debug_info=no_match(["dwarf"])) - def test(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, - "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) - - # Activate importing of std module. - self.runCmd("settings set target.import-std-module true") - # Calling some normal std functions that return non-template types. - self.expect("expr std::abs(-42)", substrs=['(int) $0 = 42']) - self.expect("expr std::div(2, 1).quot", substrs=['(int) $1 = 2']) - # Using types from std. - self.expect("expr (std::size_t)33U", substrs=['(size_t) $2 = 33']) - # Calling templated functions that return non-template types. - self.expect("expr char char_a = 'b'; char char_b = 'a'; std::swap(char_a, char_b); char_a", - substrs=["(char) $3 = 'a'"]) - - # FIXME: This should work on more setups, so remove these - # skipIf's in the future. - @add_test_categories(["libc++"]) - @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) - @skipIf(debug_info=no_match(["dwarf"])) - def test_non_cpp_language(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, - "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) - - # Activate importing of std module. - self.runCmd("settings set target.import-std-module true") - # These languages don't support C++ modules, so they shouldn't - # be able to evaluate the expression. - self.expect("expr -l C -- std::abs(-42)", error=True) - self.expect("expr -l C99 -- std::abs(-42)", error=True) - self.expect("expr -l C11 -- std::abs(-42)", error=True) - self.expect("expr -l ObjC -- std::abs(-42)", error=True) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/basic/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/basic/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/basic/main.cpp @@ -1,7 +0,0 @@ -// We need to import any std module. It doesn't matter which one. -#include - -int main(int argc, char **argv) { - std::cout << "Test" << std::endl; - return 0; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/conflicts/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/conflicts/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/conflicts/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make -USE_LIBCPP := 1 -CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) -CXX_SOURCES := main.cpp -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/conflicts/TestStdModuleWithConflicts.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/conflicts/TestStdModuleWithConflicts.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/conflicts/TestStdModuleWithConflicts.py @@ -1,36 +0,0 @@ -""" -Test importing the 'std' C++ module and check if we can handle -prioritizing the conflicting functions from debug info and std -module. - -See also import-std-module/basic/TestImportStdModule.py for -the same test on a 'clean' code base without conflicts. -""" - -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestImportStdModuleConflicts(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # FIXME: This should work on more setups, so remove these - # skipIf's in the future. - @add_test_categories(["libc++"]) - @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) - @skipIf(debug_info=no_match(["dwarf"])) - def test(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, - "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) - - self.runCmd("settings set target.import-std-module true") - self.expect("expr std::abs(-42)", substrs=['(int) $0 = 42']) - self.expect("expr std::div(2, 1).quot", substrs=['(int) $1 = 2']) - self.expect("expr (std::size_t)33U", substrs=['(size_t) $2 = 33']) - self.expect("expr char char_a = 'b'; char char_b = 'a'; std::swap(char_a, char_b); char_a", - substrs=["(char) $3 = 'a'"]) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/conflicts/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/conflicts/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/conflicts/main.cpp @@ -1,10 +0,0 @@ -#include -#include - -int main(int argc, char **argv) { - std::size_t f = argc; - f = std::abs(argc); - f = std::div(argc * 2, argc).quot; - std::swap(f, f); - return f; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/deque-basic/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/deque-basic/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/deque-basic/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make -USE_LIBCPP := 1 -CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) -CXX_SOURCES := main.cpp -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/deque-basic/TestBasicDeque.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/deque-basic/TestBasicDeque.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/deque-basic/TestBasicDeque.py @@ -1,41 +0,0 @@ -""" -Test basic std::list functionality. -""" - -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class TestBasicDeque(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # FIXME: This should work on more setups, so remove these - # skipIf's in the future. - @add_test_categories(["libc++"]) - @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) - @skipIf(debug_info=no_match(["dwarf"])) - def test(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, - "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) - - self.runCmd("settings set target.import-std-module true") - - self.expect("expr (size_t)a.size()", substrs=['(size_t) $0 = 3']) - self.expect("expr (int)a.front()", substrs=['(int) $1 = 3']) - self.expect("expr (int)a.back()", substrs=['(int) $2 = 2']) - - self.expect("expr std::sort(a.begin(), a.end())") - self.expect("expr (int)a.front()", substrs=['(int) $3 = 1']) - self.expect("expr (int)a.back()", substrs=['(int) $4 = 3']) - - self.expect("expr std::reverse(a.begin(), a.end())") - self.expect("expr (int)a.front()", substrs=['(int) $5 = 3']) - self.expect("expr (int)a.back()", substrs=['(int) $6 = 1']) - - self.expect("expr (int)(*a.begin())", substrs=['(int) $7 = 3']) - self.expect("expr (int)(*a.rbegin())", substrs=['(int) $8 = 1']) - Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/deque-basic/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/deque-basic/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/deque-basic/main.cpp @@ -1,6 +0,0 @@ -#include - -int main(int argc, char **argv) { - std::deque a = {3, 1, 2}; - return 0; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/deque-dbg-info-content/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/deque-dbg-info-content/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/deque-dbg-info-content/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make -USE_LIBCPP := 1 -CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) -CXX_SOURCES := main.cpp -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/deque-dbg-info-content/TestDbgInfoContentDeque.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/deque-dbg-info-content/TestDbgInfoContentDeque.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/deque-dbg-info-content/TestDbgInfoContentDeque.py @@ -1,37 +0,0 @@ -""" -Test std::deque functionality with a decl from dbg info as content. -""" - -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class TestDbgInfoContentDeque(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # FIXME: This should work on more setups, so remove these - # skipIf's in the future. - @add_test_categories(["libc++"]) - @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) - @skipIf(debug_info=no_match(["dwarf"])) - def test(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, - "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) - - self.runCmd("settings set target.import-std-module true") - - self.expect("expr (size_t)a.size()", substrs=['(size_t) $0 = 3']) - self.expect("expr (int)a.front().a", substrs=['(int) $1 = 3']) - self.expect("expr (int)a.back().a", substrs=['(int) $2 = 2']) - - self.expect("expr std::reverse(a.begin(), a.end())") - self.expect("expr (int)a.front().a", substrs=['(int) $3 = 2']) - self.expect("expr (int)a.back().a", substrs=['(int) $4 = 3']) - - self.expect("expr (int)(a.begin()->a)", substrs=['(int) $5 = 2']) - self.expect("expr (int)(a.rbegin()->a)", substrs=['(int) $6 = 3']) - Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/deque-dbg-info-content/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/deque-dbg-info-content/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/deque-dbg-info-content/main.cpp @@ -1,10 +0,0 @@ -#include - -struct Foo { - int a; -}; - -int main(int argc, char **argv) { - std::deque a = {{3}, {1}, {2}}; - return 0; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/forward_list-basic/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/forward_list-basic/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/forward_list-basic/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make -USE_LIBCPP := 1 -CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) -CXX_SOURCES := main.cpp -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/forward_list-basic/TestBasicForwardList.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/forward_list-basic/TestBasicForwardList.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/forward_list-basic/TestBasicForwardList.py @@ -1,34 +0,0 @@ -""" -Test basic std::forward_list functionality. -""" - -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class TestBasicForwardList(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # FIXME: This should work on more setups, so remove these - # skipIf's in the future. - @add_test_categories(["libc++"]) - @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) - @skipIf(debug_info=no_match(["dwarf"])) - def test(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, - "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) - - self.runCmd("settings set target.import-std-module true") - - self.expect("expr (size_t)std::distance(a.begin(), a.end())", substrs=['(size_t) $0 = 3']) - self.expect("expr (int)a.front()", substrs=['(int) $1 = 3']) - - self.expect("expr a.sort()") - self.expect("expr (int)a.front()", substrs=['(int) $2 = 1']) - - self.expect("expr (int)(*a.begin())", substrs=['(int) $3 = 1']) - Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/forward_list-basic/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/forward_list-basic/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/forward_list-basic/main.cpp @@ -1,6 +0,0 @@ -#include - -int main(int argc, char **argv) { - std::forward_list a = {3, 1, 2}; - return 0; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/forward_list-dbg-info-content/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/forward_list-dbg-info-content/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/forward_list-dbg-info-content/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make -USE_LIBCPP := 1 -CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) -CXX_SOURCES := main.cpp -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/forward_list-dbg-info-content/TestDbgInfoContentForwardList.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/forward_list-dbg-info-content/TestDbgInfoContentForwardList.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/forward_list-dbg-info-content/TestDbgInfoContentForwardList.py @@ -1,31 +0,0 @@ -""" -Test std::forward_list functionality with a decl from debug info as content. -""" - -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class TestDbgInfoContentForwardList(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # FIXME: This should work on more setups, so remove these - # skipIf's in the future. - @add_test_categories(["libc++"]) - @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) - @skipIf(debug_info=no_match(["dwarf"])) - def test(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, - "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) - - self.runCmd("settings set target.import-std-module true") - - self.expect("expr (size_t)std::distance(a.begin(), a.end())", substrs=['(size_t) $0 = 3']) - self.expect("expr (int)a.front().a", substrs=['(int) $1 = 3']) - - self.expect("expr (int)(a.begin()->a)", substrs=['(int) $2 = 3']) - Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/forward_list-dbg-info-content/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/forward_list-dbg-info-content/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/forward_list-dbg-info-content/main.cpp @@ -1,10 +0,0 @@ -#include - -struct Foo { - int a; -}; - -int main(int argc, char **argv) { - std::forward_list a = {{3}, {1}, {2}}; - return 0; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/list-basic/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/list-basic/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/list-basic/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make -USE_LIBCPP := 1 -CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) -CXX_SOURCES := main.cpp -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/list-basic/TestBasicList.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/list-basic/TestBasicList.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/list-basic/TestBasicList.py @@ -1,41 +0,0 @@ -""" -Test basic std::list functionality. -""" - -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class TestBasicList(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # FIXME: This should work on more setups, so remove these - # skipIf's in the future. - @add_test_categories(["libc++"]) - @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) - @skipIf(debug_info=no_match(["dwarf"])) - def test(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, - "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) - - self.runCmd("settings set target.import-std-module true") - - self.expect("expr (size_t)a.size()", substrs=['(size_t) $0 = 3']) - self.expect("expr (int)a.front()", substrs=['(int) $1 = 3']) - self.expect("expr (int)a.back()", substrs=['(int) $2 = 2']) - - self.expect("expr a.sort()") - self.expect("expr (int)a.front()", substrs=['(int) $3 = 1']) - self.expect("expr (int)a.back()", substrs=['(int) $4 = 3']) - - self.expect("expr std::reverse(a.begin(), a.end())") - self.expect("expr (int)a.front()", substrs=['(int) $5 = 3']) - self.expect("expr (int)a.back()", substrs=['(int) $6 = 1']) - - self.expect("expr (int)(*a.begin())", substrs=['(int) $7 = 3']) - self.expect("expr (int)(*a.rbegin())", substrs=['(int) $8 = 1']) - Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/list-basic/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/list-basic/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/list-basic/main.cpp @@ -1,6 +0,0 @@ -#include - -int main(int argc, char **argv) { - std::list a = {3, 1, 2}; - return 0; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/list-dbg-info-content/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/list-dbg-info-content/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/list-dbg-info-content/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make -USE_LIBCPP := 1 -CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) -CXX_SOURCES := main.cpp -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/list-dbg-info-content/TestDbgInfoContentList.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/list-dbg-info-content/TestDbgInfoContentList.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/list-dbg-info-content/TestDbgInfoContentList.py @@ -1,38 +0,0 @@ -""" -Test basic std::list functionality but with a declaration from -the debug info (the Foo struct) as content. -""" - -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class TestDbgInfoContentList(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # FIXME: This should work on more setups, so remove these - # skipIf's in the future. - @add_test_categories(["libc++"]) - @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) - @skipIf(debug_info=no_match(["dwarf"])) - def test(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, - "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) - - self.runCmd("settings set target.import-std-module true") - - self.expect("expr (size_t)a.size()", substrs=['(size_t) $0 = 3']) - self.expect("expr (int)a.front().a", substrs=['(int) $1 = 3']) - self.expect("expr (int)a.back().a", substrs=['(int) $2 = 2']) - - self.expect("expr std::reverse(a.begin(), a.end())") - self.expect("expr (int)a.front().a", substrs=['(int) $3 = 2']) - self.expect("expr (int)a.back().a", substrs=['(int) $4 = 3']) - - self.expect("expr (int)(a.begin()->a)", substrs=['(int) $5 = 2']) - self.expect("expr (int)(a.rbegin()->a)", substrs=['(int) $6 = 3']) - Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/list-dbg-info-content/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/list-dbg-info-content/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/list-dbg-info-content/main.cpp @@ -1,10 +0,0 @@ -#include - -struct Foo { - int a; -}; - -int main(int argc, char **argv) { - std::list a = {{3}, {1}, {2}}; - return 0; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/no-std-module/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/no-std-module/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/no-std-module/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make -USE_LIBCPP := 1 -CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) -CXX_SOURCES := main.cpp -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/no-std-module/TestMissingStdModule.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/no-std-module/TestMissingStdModule.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/no-std-module/TestMissingStdModule.py @@ -1,40 +0,0 @@ -""" -Test that importing the std module on a compile unit -that doesn't use the std module will not break LLDB. - -It's not really specified at the moment what kind of -error we should report back to the user in this -situation. Currently Clang will just complain that -the std module doesn't exist or can't be loaded. -""" - -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class STLTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # FIXME: This should work on more setups, so remove these - # skipIf's in the future. - @add_test_categories(["libc++"]) - @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) - @skipIf(debug_info=no_match(["dwarf"])) - def test(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, - "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) - - # Activate importing of std module. - self.runCmd("settings set target.import-std-module true") - - # Run some commands that should all fail without our std module. - self.expect("expr std::abs(-42)", error=True) - self.expect("expr std::div(2, 1).quot", error=True) - self.expect("expr (std::size_t)33U", error=True) - self.expect("expr char a = 'b'; char b = 'a'; std::swap(a, b); a", - error=True) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/no-std-module/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/no-std-module/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/no-std-module/main.cpp @@ -1,5 +0,0 @@ -// We don't import any std module here. - -int main(int argc, char **argv) { - return 0; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/queue/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/queue/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/queue/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make -USE_LIBCPP := 1 -CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) -CXX_SOURCES := main.cpp -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/queue/TestQueue.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/queue/TestQueue.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/queue/TestQueue.py @@ -1,47 +0,0 @@ -""" -Tests std::queue functionality. -""" - -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class TestQueue(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # FIXME: This should work on more setups, so remove these - # skipIf's in the future. - @add_test_categories(["libc++"]) - @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) - @skipIf(debug_info=no_match(["dwarf"])) - def test(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, - "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) - - self.runCmd("settings set target.import-std-module true") - - # Test std::queue functionality with a std::deque. - self.expect("expr q_deque.pop()") - self.expect("expr q_deque.push({4})") - self.expect("expr (size_t)q_deque.size()", substrs=['(size_t) $0 = 1']) - self.expect("expr (int)q_deque.front().i", substrs=['(int) $1 = 4']) - self.expect("expr (int)q_deque.back().i", substrs=['(int) $2 = 4']) - self.expect("expr q_deque.empty()", substrs=['(bool) $3 = false']) - self.expect("expr q_deque.pop()") - self.expect("expr q_deque.emplace(5)") - self.expect("expr (int)q_deque.front().i", substrs=['(int) $4 = 5']) - - # Test std::queue functionality with a std::list. - self.expect("expr q_list.pop()") - self.expect("expr q_list.push({4})") - self.expect("expr (size_t)q_list.size()", substrs=['(size_t) $5 = 1']) - self.expect("expr (int)q_list.front().i", substrs=['(int) $6 = 4']) - self.expect("expr (int)q_list.back().i", substrs=['(int) $7 = 4']) - self.expect("expr q_list.empty()", substrs=['(bool) $8 = false']) - self.expect("expr q_list.pop()") - self.expect("expr q_list.emplace(5)") - self.expect("expr (int)q_list.front().i", substrs=['(int) $9 = 5']) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/queue/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/queue/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/queue/main.cpp @@ -1,16 +0,0 @@ -#include -#include -#include - -struct C { - // Constructor for testing emplace. - C(int i) : i(i) {}; - int i; -}; - -int main(int argc, char **argv) { - // std::deque is the default container. - std::queue q_deque({{1}}); - std::queue> q_list({{1}}); - return 0; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/shared_ptr-dbg-info-content/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/shared_ptr-dbg-info-content/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/shared_ptr-dbg-info-content/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make -USE_LIBCPP := 1 -CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) -CXX_SOURCES := main.cpp -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/shared_ptr-dbg-info-content/TestSharedPtrDbgInfoContent.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/shared_ptr-dbg-info-content/TestSharedPtrDbgInfoContent.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/shared_ptr-dbg-info-content/TestSharedPtrDbgInfoContent.py @@ -1,33 +0,0 @@ -""" -Test std::shared_ptr functionality with a class from debug info as content. -""" - -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class TestSharedPtrDbgInfoContent(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # FIXME: This should work on more setups, so remove these - # skipIf's in the future. - @add_test_categories(["libc++"]) - @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) - @skipIf(debug_info=no_match(["dwarf"])) - def test(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, - "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) - - self.runCmd("settings set target.import-std-module true") - - self.expect("expr (int)s->a", substrs=['(int) $0 = 3']) - self.expect("expr (int)(s->a = 5)", substrs=['(int) $1 = 5']) - self.expect("expr (int)s->a", substrs=['(int) $2 = 5']) - self.expect("expr (bool)s", substrs=['(bool) $3 = true']) - self.expect("expr s.reset()") - self.expect("expr (bool)s", substrs=['(bool) $4 = false']) - Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/shared_ptr-dbg-info-content/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/shared_ptr-dbg-info-content/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/shared_ptr-dbg-info-content/main.cpp @@ -1,11 +0,0 @@ -#include - -struct Foo { - int a; -}; - -int main(int argc, char **argv) { - std::shared_ptr s(new Foo); - s->a = 3; - return s->a; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/shared_ptr/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/shared_ptr/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/shared_ptr/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make -USE_LIBCPP := 1 -CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) -CXX_SOURCES := main.cpp -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/shared_ptr/TestSharedPtr.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/shared_ptr/TestSharedPtr.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/shared_ptr/TestSharedPtr.py @@ -1,33 +0,0 @@ -""" -Test basic std::shared_ptr functionality. -""" - -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class TestSharedPtr(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # FIXME: This should work on more setups, so remove these - # skipIf's in the future. - @add_test_categories(["libc++"]) - @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) - @skipIf(debug_info=no_match(["dwarf"])) - def test(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, - "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) - - self.runCmd("settings set target.import-std-module true") - - self.expect("expr (int)*s", substrs=['(int) $0 = 3']) - self.expect("expr (int)(*s = 5)", substrs=['(int) $1 = 5']) - self.expect("expr (int)*s", substrs=['(int) $2 = 5']) - self.expect("expr (bool)s", substrs=['(bool) $3 = true']) - self.expect("expr s.reset()") - self.expect("expr (bool)s", substrs=['(bool) $4 = false']) - Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/shared_ptr/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/shared_ptr/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/shared_ptr/main.cpp @@ -1,7 +0,0 @@ -#include - -int main(int argc, char **argv) { - std::shared_ptr s(new int); - *s = 3; - return *s; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/stack/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/stack/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/stack/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make -USE_LIBCPP := 1 -CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) -CXX_SOURCES := main.cpp -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/stack/TestStack.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/stack/TestStack.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/stack/TestStack.py @@ -1,49 +0,0 @@ -""" -Tests std::stack functionality. -""" - -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class TestStack(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # FIXME: This should work on more setups, so remove these - # skipIf's in the future. - @add_test_categories(["libc++"]) - @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) - @skipIf(debug_info=no_match(["dwarf"])) - def test(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, - "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) - - self.runCmd("settings set target.import-std-module true") - - # Test std::stack functionality with a std::deque. - self.expect("expr s_deque.pop()") - self.expect("expr s_deque.push({4})") - self.expect("expr (size_t)s_deque.size()", substrs=['(size_t) $0 = 3']) - self.expect("expr (int)s_deque.top().i", substrs=['(int) $1 = 4']) - self.expect("expr s_deque.emplace(5)") - self.expect("expr (int)s_deque.top().i", substrs=['(int) $2 = 5']) - - # Test std::stack functionality with a std::vector. - self.expect("expr s_vector.pop()") - self.expect("expr s_vector.push({4})") - self.expect("expr (size_t)s_vector.size()", substrs=['(size_t) $3 = 3']) - self.expect("expr (int)s_vector.top().i", substrs=['(int) $4 = 4']) - self.expect("expr s_vector.emplace(5)") - self.expect("expr (int)s_vector.top().i", substrs=['(int) $5 = 5']) - - # Test std::stack functionality with a std::list. - self.expect("expr s_list.pop()") - self.expect("expr s_list.push({4})") - self.expect("expr (size_t)s_list.size()", substrs=['(size_t) $6 = 3']) - self.expect("expr (int)s_list.top().i", substrs=['(int) $7 = 4']) - self.expect("expr s_list.emplace(5)") - self.expect("expr (int)s_list.top().i", substrs=['(int) $8 = 5']) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/stack/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/stack/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/stack/main.cpp @@ -1,17 +0,0 @@ -#include -#include -#include - -struct C { - // Constructor for testing emplace. - C(int i) : i(i) {}; - int i; -}; - -int main(int argc, char **argv) { - // std::deque is the default container. - std::stack s_deque({{1}, {2}, {3}}); - std::stack> s_vector({{1}, {2}, {3}}); - std::stack> s_list({{1}, {2}, {3}}); - return 0; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/sysroot/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/sysroot/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/sysroot/Makefile @@ -1,10 +0,0 @@ -LEVEL = ../../../make -# We don't have any standard include directories, so we can't -# parse the test_common.h header we usually inject as it includes -# system headers. -NO_TEST_COMMON_H := 1 - -CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) -CXXFLAGS += -I $(SRCDIR)/root/usr/include/c++/include/ -I $(SRCDIR)/root/usr/include/ -nostdinc -nostdinc++ -nostdlib++ -CXX_SOURCES := main.cpp -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/sysroot/TestStdModuleSysroot.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/sysroot/TestStdModuleSysroot.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/sysroot/TestStdModuleSysroot.py @@ -1,34 +0,0 @@ -""" -Test that we respect the sysroot when building the std module. -""" - -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil -import os - -class ImportStdModule(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # FIXME: This should work on more setups, so remove these - # skipIf's in the future. - @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) - @skipIf(debug_info=no_match(["dwarf"])) - def test(self): - self.build() - - sysroot = os.path.join(os.getcwd(), "root") - - # Set the sysroot. - self.runCmd("platform select --sysroot '" + sysroot + "' host", CURRENT_EXECUTABLE_SET) - - lldbutil.run_to_source_breakpoint(self, - "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) - - self.runCmd("settings set target.import-std-module true") - - # Call our custom function in our sysroot std module. - # If this gives us the correct result, then we used the sysroot. - self.expect("expr std::myabs(-42)", substrs=['(int) $0 = 42']) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/sysroot/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/sysroot/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/sysroot/main.cpp @@ -1,6 +0,0 @@ -#include - -int main(int argc, char **argv) { - libc_struct s; - return 0; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/sysroot/root/usr/include/c++/include/algorithm =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/sysroot/root/usr/include/c++/include/algorithm +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/sysroot/root/usr/include/c++/include/algorithm @@ -1,7 +0,0 @@ -#include "libc_header.h" - -namespace std { - int myabs(int i) { - return i < 0 ? -i : i; - } -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/sysroot/root/usr/include/c++/include/module.modulemap =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/sysroot/root/usr/include/c++/include/module.modulemap +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/sysroot/root/usr/include/c++/include/module.modulemap @@ -1,3 +0,0 @@ -module std { - module "algorithm" { header "algorithm" export * } -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/sysroot/root/usr/include/libc_header.h =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/sysroot/root/usr/include/libc_header.h +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/sysroot/root/usr/include/libc_header.h @@ -1 +0,0 @@ -struct libc_struct {}; Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/unique_ptr-dbg-info-content/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/unique_ptr-dbg-info-content/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/unique_ptr-dbg-info-content/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make -USE_LIBCPP := 1 -CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) -CXX_SOURCES := main.cpp -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/unique_ptr-dbg-info-content/TestUniquePtrDbgInfoContent.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/unique_ptr-dbg-info-content/TestUniquePtrDbgInfoContent.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/unique_ptr-dbg-info-content/TestUniquePtrDbgInfoContent.py @@ -1,33 +0,0 @@ -""" -Test std::unique_ptr functionality with a decl from debug info as content. -""" - -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class TestUniquePtrDbgInfoContent(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # FIXME: This should work on more setups, so remove these - # skipIf's in the future. - @add_test_categories(["libc++"]) - @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) - @skipIf(debug_info=no_match(["dwarf"])) - def test(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, - "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) - - self.runCmd("settings set target.import-std-module true") - - self.expect("expr (int)s->a", substrs=['(int) $0 = 3']) - self.expect("expr (int)(s->a = 5)", substrs=['(int) $1 = 5']) - self.expect("expr (int)s->a", substrs=['(int) $2 = 5']) - self.expect("expr (bool)s", substrs=['(bool) $3 = true']) - self.expect("expr s.reset()") - self.expect("expr (bool)s", substrs=['(bool) $4 = false']) - Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/unique_ptr-dbg-info-content/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/unique_ptr-dbg-info-content/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/unique_ptr-dbg-info-content/main.cpp @@ -1,11 +0,0 @@ -#include - -struct Foo { - int a; -}; - -int main(int argc, char **argv) { - std::shared_ptr s(new Foo); - s->a = 3; - return s->a; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/unique_ptr/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/unique_ptr/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/unique_ptr/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make -USE_LIBCPP := 1 -CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) -CXX_SOURCES := main.cpp -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/unique_ptr/TestUniquePtr.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/unique_ptr/TestUniquePtr.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/unique_ptr/TestUniquePtr.py @@ -1,33 +0,0 @@ -""" -Test basic std::unique_ptr functionality. -""" - -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class TestUniquePtr(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # FIXME: This should work on more setups, so remove these - # skipIf's in the future. - @add_test_categories(["libc++"]) - @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) - @skipIf(debug_info=no_match(["dwarf"])) - def test(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, - "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) - - self.runCmd("settings set target.import-std-module true") - - self.expect("expr (int)*s", substrs=['(int) $0 = 3']) - self.expect("expr (int)(*s = 5)", substrs=['(int) $1 = 5']) - self.expect("expr (int)*s", substrs=['(int) $2 = 5']) - self.expect("expr (bool)s", substrs=['(bool) $3 = true']) - self.expect("expr s.reset()") - self.expect("expr (bool)s", substrs=['(bool) $4 = false']) - Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/unique_ptr/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/unique_ptr/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/unique_ptr/main.cpp @@ -1,7 +0,0 @@ -#include - -int main(int argc, char **argv) { - std::shared_ptr s(new int); - *s = 3; - return *s; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-basic/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-basic/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-basic/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make -USE_LIBCPP := 1 -CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) -CXX_SOURCES := main.cpp -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-basic/TestBasicVector.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-basic/TestBasicVector.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-basic/TestBasicVector.py @@ -1,57 +0,0 @@ -""" -Test basic std::vector functionality. -""" - -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class TestBasicVector(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # FIXME: This should work on more setups, so remove these - # skipIf's in the future. - @add_test_categories(["libc++"]) - @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) - @skipIf(debug_info=no_match(["dwarf"])) - def test(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, - "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) - - self.runCmd("settings set target.import-std-module true") - - self.expect("expr (size_t)a.size()", substrs=['(size_t) $0 = 3']) - self.expect("expr (int)a.front()", substrs=['(int) $1 = 3']) - self.expect("expr (int)a[1]", substrs=['(int) $2 = 1']) - self.expect("expr (int)a.back()", substrs=['(int) $3 = 2']) - - self.expect("expr std::sort(a.begin(), a.end())") - self.expect("expr (int)a.front()", substrs=['(int) $4 = 1']) - self.expect("expr (int)a[1]", substrs=['(int) $5 = 2']) - self.expect("expr (int)a.back()", substrs=['(int) $6 = 3']) - - self.expect("expr std::reverse(a.begin(), a.end())") - self.expect("expr (int)a.front()", substrs=['(int) $7 = 3']) - self.expect("expr (int)a[1]", substrs=['(int) $8 = 2']) - self.expect("expr (int)a.back()", substrs=['(int) $9 = 1']) - - self.expect("expr (int)(*a.begin())", substrs=['(int) $10 = 3']) - self.expect("expr (int)(*a.rbegin())", substrs=['(int) $11 = 1']) - - self.expect("expr a.pop_back()") - self.expect("expr (int)a.back()", substrs=['(int) $12 = 2']) - self.expect("expr (size_t)a.size()", substrs=['(size_t) $13 = 2']) - - self.expect("expr (int)a.at(0)", substrs=['(int) $14 = 3']) - - self.expect("expr a.push_back(4)") - self.expect("expr (int)a.back()", substrs=['(int) $15 = 4']) - self.expect("expr (size_t)a.size()", substrs=['(size_t) $16 = 3']) - - self.expect("expr a.emplace_back(5)") - self.expect("expr (int)a.back()", substrs=['(int) $17 = 5']) - self.expect("expr (size_t)a.size()", substrs=['(size_t) $18 = 4']) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-basic/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-basic/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-basic/main.cpp @@ -1,6 +0,0 @@ -#include - -int main(int argc, char **argv) { - std::vector a = {3, 1, 2}; - return 0; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-bool/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-bool/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-bool/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make -USE_LIBCPP := 1 -CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) -CXX_SOURCES := main.cpp -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-bool/TestBoolVector.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-bool/TestBoolVector.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-bool/TestBoolVector.py @@ -1,34 +0,0 @@ -""" -Test basic std::vector functionality. -""" - -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class TestBoolVector(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # FIXME: This should work on more setups, so remove these - # skipIf's in the future. - @add_test_categories(["libc++"]) - @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) - @skipIf(debug_info=no_match(["dwarf"])) - def test(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, - "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) - - self.runCmd("settings set target.import-std-module true") - - self.expect("expr (size_t)a.size()", substrs=['(size_t) $0 = 4']) - self.expect("expr (bool)a.front()", substrs=['(bool) $1 = false']) - self.expect("expr (bool)a[1]", substrs=['(bool) $2 = true']) - self.expect("expr (bool)a.back()", substrs=['(bool) $3 = true']) - - self.expect("expr (bool)(*a.begin())", substrs=['(bool) $4 = false']) - self.expect("expr (bool)(*a.rbegin())", substrs=['(bool) $5 = true']) - Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-bool/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-bool/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-bool/main.cpp @@ -1,6 +0,0 @@ -#include - -int main(int argc, char **argv) { - std::vector a = {0, 1, 0, 1}; - return 0; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-dbg-info-content/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-dbg-info-content/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-dbg-info-content/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make -USE_LIBCPP := 1 -CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) -CXX_SOURCES := main.cpp -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-dbg-info-content/TestDbgInfoContentVector.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-dbg-info-content/TestDbgInfoContentVector.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-dbg-info-content/TestDbgInfoContentVector.py @@ -1,47 +0,0 @@ -""" -Test basic std::vector functionality but with a declaration from -the debug info (the Foo struct) as content. -""" - -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class TestDbgInfoContentVector(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # FIXME: This should work on more setups, so remove these - # skipIf's in the future. - @add_test_categories(["libc++"]) - @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) - @skipIf(debug_info=no_match(["dwarf"])) - def test(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, - "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) - - self.runCmd("settings set target.import-std-module true") - - self.expect("expr (size_t)a.size()", substrs=['(size_t) $0 = 3']) - self.expect("expr (int)a.front().a", substrs=['(int) $1 = 3']) - self.expect("expr (int)a[1].a", substrs=['(int) $2 = 1']) - self.expect("expr (int)a.back().a", substrs=['(int) $3 = 2']) - - self.expect("expr std::reverse(a.begin(), a.end())") - self.expect("expr (int)a.front().a", substrs=['(int) $4 = 2']) - - self.expect("expr (int)(a.begin()->a)", substrs=['(int) $5 = 2']) - self.expect("expr (int)(a.rbegin()->a)", substrs=['(int) $6 = 3']) - - self.expect("expr a.pop_back()") - self.expect("expr (int)a.back().a", substrs=['(int) $7 = 1']) - self.expect("expr (size_t)a.size()", substrs=['(size_t) $8 = 2']) - - self.expect("expr (int)a.at(0).a", substrs=['(int) $9 = 2']) - - self.expect("expr a.push_back({4})") - self.expect("expr (int)a.back().a", substrs=['(int) $10 = 4']) - self.expect("expr (size_t)a.size()", substrs=['(size_t) $11 = 3']) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-dbg-info-content/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-dbg-info-content/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-dbg-info-content/main.cpp @@ -1,10 +0,0 @@ -#include - -struct Foo { - int a; -}; - -int main(int argc, char **argv) { - std::vector a = {{3}, {1}, {2}}; - return 0; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-of-vectors/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-of-vectors/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-of-vectors/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make -USE_LIBCPP := 1 -CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) -CXX_SOURCES := main.cpp -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-of-vectors/TestVectorOfVectors.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-of-vectors/TestVectorOfVectors.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-of-vectors/TestVectorOfVectors.py @@ -1,30 +0,0 @@ -""" -Test std::vector functionality when it's contents are vectors. -""" - -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class TestVectorOfVectors(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # FIXME: This should work on more setups, so remove these - # skipIf's in the future. - @add_test_categories(["libc++"]) - @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) - @skipIf(debug_info=no_match(["dwarf"])) - def test(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, - "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) - - self.runCmd("settings set target.import-std-module true") - - self.expect("expr (size_t)a.size()", substrs=['(size_t) $0 = 2']) - self.expect("expr (int)a.front().front()", substrs=['(int) $1 = 1']) - self.expect("expr (int)a[1][1]", substrs=['(int) $2 = 2']) - self.expect("expr (int)a.back().at(0)", substrs=['(int) $3 = 3']) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-of-vectors/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-of-vectors/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-of-vectors/main.cpp @@ -1,6 +0,0 @@ -#include - -int main(int argc, char **argv) { - std::vector > a = {{1, 2, 3}, {3, 2, 1}}; - return 0; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/weak_ptr-dbg-info-content/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/weak_ptr-dbg-info-content/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/weak_ptr-dbg-info-content/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make -USE_LIBCPP := 1 -CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) -CXX_SOURCES := main.cpp -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtr.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtr.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtr.py @@ -1,33 +0,0 @@ -""" -Test std::weak_ptr functionality with a decl from debug info as content. -""" - -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class TestDbgInfoContentWeakPtr(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # FIXME: This should work on more setups, so remove these - # skipIf's in the future. - @add_test_categories(["libc++"]) - @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) - @skipIf(debug_info=no_match(["dwarf"])) - def test(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, - "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) - - self.runCmd("settings set target.import-std-module true") - - self.expect("expr (int)w.lock()->a", substrs=['(int) $0 = 3']) - self.expect("expr (int)(w.lock()->a = 5)", substrs=['(int) $1 = 5']) - self.expect("expr (int)w.lock()->a", substrs=['(int) $2 = 5']) - self.expect("expr w.use_count()", substrs=['(long) $3 = 1']) - self.expect("expr w.reset()") - self.expect("expr w.use_count()", substrs=['(long) $4 = 0']) - Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/weak_ptr-dbg-info-content/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/weak_ptr-dbg-info-content/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/weak_ptr-dbg-info-content/main.cpp @@ -1,12 +0,0 @@ -#include - -struct Foo { - int a; -}; - -int main(int argc, char **argv) { - std::shared_ptr s(new Foo); - s->a = 3; - std::weak_ptr w = s; - return s->a; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/weak_ptr/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/weak_ptr/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/weak_ptr/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make -USE_LIBCPP := 1 -CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS) -CXX_SOURCES := main.cpp -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/weak_ptr/TestWeakPtr.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/weak_ptr/TestWeakPtr.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/weak_ptr/TestWeakPtr.py @@ -1,33 +0,0 @@ -""" -Test basic std::weak_ptr functionality. -""" - -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class TestSharedPtr(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # FIXME: This should work on more setups, so remove these - # skipIf's in the future. - @add_test_categories(["libc++"]) - @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) - @skipIf(debug_info=no_match(["dwarf"])) - def test(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, - "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) - - self.runCmd("settings set target.import-std-module true") - - self.expect("expr (int)*w.lock()", substrs=['(int) $0 = 3']) - self.expect("expr (int)(*w.lock() = 5)", substrs=['(int) $1 = 5']) - self.expect("expr (int)*w.lock()", substrs=['(int) $2 = 5']) - self.expect("expr w.use_count()", substrs=['(long) $3 = 1']) - self.expect("expr w.reset()") - self.expect("expr w.use_count()", substrs=['(long) $4 = 0']) - Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/weak_ptr/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/weak_ptr/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import-std-module/weak_ptr/main.cpp @@ -1,8 +0,0 @@ -#include - -int main(int argc, char **argv) { - std::shared_ptr s(new int); - *s = 3; - std::weak_ptr w = s; - return *s; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import_builtin_fileid/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import_builtin_fileid/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import_builtin_fileid/Makefile @@ -1,6 +0,0 @@ -LEVEL = ../../make - -OBJC_SOURCES := main.m - -include $(LEVEL)/Makefile.rules -LDFLAGS += -framework Cocoa Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import_builtin_fileid/TestImportBuiltinFileID.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import_builtin_fileid/TestImportBuiltinFileID.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import_builtin_fileid/TestImportBuiltinFileID.py @@ -1,27 +0,0 @@ -""" -They may be cases where an expression will import SourceLocation and if the -SourceLocation ends up with a FileID that is a built-in we need to copy that -buffer over correctly. -""" - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class TestImportBuiltinFileID(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @skipUnlessDarwin - @skipIfDarwinEmbedded - @add_test_categories(["gmodules"]) - def test_import_builtin_fileid(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, '// break here', - lldb.SBFileSpec("main.m", False)) - - self.expect("expr int (*DBG_CGImageGetRenderingIntent)(void *) = ((int (*)(void *))CGImageGetRenderingIntent); DBG_CGImageGetRenderingIntent((void *)0x00000000000000);", - substrs=['$0 = 0']) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/import_builtin_fileid/main.m =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/import_builtin_fileid/main.m +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/import_builtin_fileid/main.m @@ -1,6 +0,0 @@ -#import - -int main(int argc, const char * argv[]) { - - return 0; // break here -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/inline-namespace/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/inline-namespace/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/inline-namespace/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/inline-namespace/TestInlineNamespace.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/inline-namespace/TestInlineNamespace.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/inline-namespace/TestInlineNamespace.py @@ -1,26 +0,0 @@ -""" -Test that we correctly handle inline namespaces. -""" - -import lldb - -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestInlineNamespace(TestBase): - mydir = TestBase.compute_mydir(__file__) - - def test(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, - "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) - - # The 'A::B::f' function must be found via 'A::f' as 'B' is an inline - # namespace. - self.expect("expr A::f()", substrs=['$0 = 3']) - # But we should still find the function when we pretend the inline - # namespace is not inline. - self.expect("expr A::B::f()", substrs=['$1 = 3']) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/inline-namespace/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/inline-namespace/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/inline-namespace/main.cpp @@ -1,10 +0,0 @@ -namespace A { - inline namespace B { - int f() { return 3; } - }; -} - -int main(int argc, char **argv) { - // Set break point at this line. - return A::f(); -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/ir-interpreter-phi-nodes/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/ir-interpreter-phi-nodes/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/ir-interpreter-phi-nodes/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/ir-interpreter-phi-nodes/TestIRInterpreterPHINodes.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/ir-interpreter-phi-nodes/TestIRInterpreterPHINodes.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/ir-interpreter-phi-nodes/TestIRInterpreterPHINodes.py @@ -1,41 +0,0 @@ -""" -Test PHI nodes work in the IR interpreter. -""" - - -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 = self.getBuildArtifact("a.out") - self.runCmd('file ' + exe, CURRENT_EXECUTABLE_SET) - - # Break on the first assignment to i - line = line_number('main.cpp', 'i = 5') - lldbutil.run_break_set_by_file_and_line( - self, 'main.cpp', line, num_expected_locations=1, loc_exact=True) - - self.runCmd('run', RUN_SUCCEEDED) - - # The stop reason of the thread should be breakpoint - self.expect('thread list', STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', 'stop reason = breakpoint']) - - self.runCmd('s') - - # The logical 'or' causes a PHI node to be generated. Execute without JIT - # to test that the interpreter can handle this - self.expect('expr -j 0 -- i == 3 || i == 5', substrs=['true']) - - self.runCmd('s') - self.expect('expr -j 0 -- i == 3 || i == 5', substrs=['false']) - self.runCmd('s') - self.expect('expr -j 0 -- i == 3 || i == 5', substrs=['true']) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/ir-interpreter-phi-nodes/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/ir-interpreter-phi-nodes/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/ir-interpreter-phi-nodes/main.cpp @@ -1,16 +0,0 @@ -//===-- main.cpp ------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -int main() -{ - int i; - i = 5; - i = 2; - i = 3; - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/ir-interpreter/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/ir-interpreter/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/ir-interpreter/Makefile @@ -1,7 +0,0 @@ -LEVEL = ../../make - -default: a.out - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/ir-interpreter/TestIRInterpreter.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/ir-interpreter/TestIRInterpreter.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/ir-interpreter/TestIRInterpreter.py @@ -1,94 +0,0 @@ -""" -Test the IR interpreter -""" - -from __future__ import print_function - -import unittest2 - -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__) - NO_DEBUG_INFO_TESTCASE = True - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to break for main.c. - self.line = line_number('main.c', - '// Set breakpoint here') - - # Disable confirmation prompt to avoid infinite wait - self.runCmd("settings set auto-confirm true") - self.addTearDownHook( - lambda: self.runCmd("settings clear auto-confirm")) - - def build_and_run(self): - """Test the IR interpreter""" - self.build() - - self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) - - lldbutil.run_break_set_by_file_and_line( - self, "main.c", self.line, num_expected_locations=1, loc_exact=False) - - self.runCmd("run", RUN_SUCCEEDED) - - @add_test_categories(['pyapi']) - # getpid() is POSIX, among other problems, see bug - @expectedFailureAll( - oslist=['windows'], - bugnumber="http://llvm.org/pr21765") - @expectedFailureNetBSD - @expectedFailureAll( - oslist=['linux'], - archs=['arm'], - bugnumber="llvm.org/pr27868") - def test_ir_interpreter(self): - self.build_and_run() - - options = lldb.SBExpressionOptions() - options.SetLanguage(lldb.eLanguageTypeC_plus_plus) - - set_up_expressions = ["int $i = 9", "int $j = 3", "int $k = 5"] - - expressions = ["$i + $j", - "$i - $j", - "$i * $j", - "$i / $j", - "$i % $k", - "$i << $j", - "$i & $j", - "$i | $j", - "$i ^ $j"] - - for expression in set_up_expressions: - self.frame().EvaluateExpression(expression, options) - - for expression in expressions: - interp_expression = expression - jit_expression = "(int)getpid(); " + expression - - interp_result = self.frame().EvaluateExpression( - interp_expression, options).GetValueAsSigned() - jit_result = self.frame().EvaluateExpression( - jit_expression, options).GetValueAsSigned() - - self.assertEqual( - interp_result, - jit_result, - "While evaluating " + - expression) - - def test_type_conversions(self): - target = self.dbg.GetDummyTarget() - short_val = target.EvaluateExpression("(short)-1") - self.assertEqual(short_val.GetValueAsSigned(), -1) - long_val = target.EvaluateExpression("(long) "+ short_val.GetName()) - self.assertEqual(long_val.GetValueAsSigned(), -1) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/ir-interpreter/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/ir-interpreter/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/ir-interpreter/main.c @@ -1,7 +0,0 @@ -#include - -int main() -{ - printf("This is a dummy\n"); // Set breakpoint here - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/issue_11588/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/issue_11588/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/issue_11588/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/issue_11588/Test11588.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/issue_11588/Test11588.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/issue_11588/Test11588.py @@ -1,67 +0,0 @@ -""" -Test the solution to issue 11581. -valobj.AddressOf() returns None when an address is -expected in a SyntheticChildrenProvider -""" - -from __future__ import print_function - - -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__) - - @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24778") - def test_11581_commands(self): - # This is the function to remove the custom commands in order to have a - # clean slate for the next test case. - 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() - - (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, - 'Set breakpoint here.', - lldb.SBFileSpec("main.cpp", False)) - self.runCmd("command script import --allow-reload s11588.py") - 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 = "]) - - # 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 = self.dbg.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)]) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/issue_11588/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/issue_11588/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/issue_11588/main.cpp @@ -1,54 +0,0 @@ -// -// 11588.cpp -// - -#include - -class StgInfoTable {}; - -class StgHeader -{ -private: - StgInfoTable* info; -public: - StgHeader() - { - info = new StgInfoTable(); - } - ~StgHeader() - { - delete info; - } -}; - -class StgClosure -{ -private: - StgHeader header; - StgClosure* payload[1]; -public: - StgClosure(bool make_payload = true) - { - if (make_payload) - payload[0] = new StgClosure(false); - else - payload[0] = NULL; - } - ~StgClosure() - { - if (payload[0]) - delete payload[0]; - } -}; - -typedef unsigned long long int ptr_type; - -int main() -{ - StgClosure* r14_ = new StgClosure(); - r14_ = (StgClosure*)(((ptr_type)r14_ | 0x01)); // set the LSB to 1 for tagging - ptr_type r14 = (ptr_type)r14_; - int x = 0; - x = 3; - return (x-1); // Set breakpoint here. -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/issue_11588/s11588.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/issue_11588/s11588.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/issue_11588/s11588.py @@ -1,28 +0,0 @@ -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 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 Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/macros/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/macros/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/macros/Makefile @@ -1,8 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -DEBUG_INFO_FLAG = -g3 - - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/macros/TestMacros.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/macros/TestMacros.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/macros/TestMacros.py @@ -1,131 +0,0 @@ -from __future__ import print_function - - -import lldb -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') - def test_expr_with_macros(self): - self.build() - - # Get main source file - src_file = "main.cpp" - hdr_file = "macro1.h" - src_file_spec = lldb.SBFileSpec(src_file) - self.assertTrue(src_file_spec.IsValid(), "Main source file") - - (target, process, thread, bp1) = lldbutil.run_to_source_breakpoint( - self, "Break here", src_file_spec) - - # Get frame for current thread - frame = thread.GetSelectedFrame() - - result = frame.EvaluateExpression("MACRO_1") - 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") - - result = frame.EvaluateExpression("ONE") - self.assertTrue( - result.IsValid() and result.GetValue() == "1", - "ONE = 1") - - result = frame.EvaluateExpression("TWO") - self.assertTrue( - result.IsValid() and result.GetValue() == "2", - "TWO = 2") - - result = frame.EvaluateExpression("THREE") - self.assertTrue( - result.IsValid() and result.GetValue() == "3", - "THREE = 3") - - result = frame.EvaluateExpression("FOUR") - self.assertTrue( - result.IsValid() and result.GetValue() == "4", - "FOUR = 4") - - result = frame.EvaluateExpression("HUNDRED") - self.assertTrue( - result.IsValid() and result.GetValue() == "100", - "HUNDRED = 100") - - result = frame.EvaluateExpression("THOUSAND") - self.assertTrue( - result.IsValid() and result.GetValue() == "1000", - "THOUSAND = 1000") - - result = frame.EvaluateExpression("MILLION") - 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") - - result = frame.EvaluateExpression("MAX(THREE, TWO)") - self.assertTrue( - result.IsValid() and result.GetValue() == "3", - "MAX(THREE, TWO) = 3") - - # Get the thread of the process - thread.StepOver() - - # Get frame for current thread - frame = thread.GetSelectedFrame() - - result = frame.EvaluateExpression("MACRO_2") - 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") - - thread.StepInto() - - # Get frame for current thread - frame = thread.GetSelectedFrame() - - result = frame.EvaluateExpression("ONE") - 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") - - # 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") - - result = frame.EvaluateExpression("MACRO_2") - self.assertTrue(result.GetError().Fail(), - "Printing MACRO_2 fails in the header file") Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/macros/macro1.h =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/macros/macro1.h +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/macros/macro1.h @@ -1,17 +0,0 @@ - -#include "macro2.h" - -#define ONE 1 -#define TWO 2 -#define THREE 3 -#define FOUR 4 - -class Simple -{ -public: - int - Method() - { - return ONE + TWO; - }; -}; Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/macros/macro2.h =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/macros/macro2.h +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/macros/macro2.h @@ -1,8 +0,0 @@ -#define HUNDRED 100 -#define THOUSAND 1000 -#define MILLION 1000000 - -#define MAX(a, b)\ -((a) > (b) ?\ - (a):\ - (b)) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/macros/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/macros/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/macros/main.cpp @@ -1,15 +0,0 @@ -#include "macro1.h" - -#define MACRO_1 100 -#define MACRO_2 200 - -int -main () -{ - int a = ONE + TWO; // Break here - - #undef MACRO_2 - #undef FOUR - - return Simple().Method(); -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/multiline-completion/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/multiline-completion/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/multiline-completion/Makefile @@ -1,3 +0,0 @@ -LEVEL = ../../make -C_SOURCES := main.c -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/multiline-completion/TestMultilineCompletion.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/multiline-completion/TestMultilineCompletion.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/multiline-completion/TestMultilineCompletion.py @@ -1,30 +0,0 @@ -""" -Test completion for multiline expressions. -""" - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test.lldbpexpect import PExpectTest - -class MultilineCompletionTest(PExpectTest): - - mydir = TestBase.compute_mydir(__file__) - - def test_basic_completion(self): - """Test that we can complete a simple multiline expression""" - self.build() - - self.launch(executable=self.getBuildArtifact("a.out")) - self.expect("b main", substrs=["Breakpoint 1", "address ="]) - self.expect("run", substrs=["stop reason ="]) - - self.child.sendline("expr") - self.child.expect_exact("terminate with an empty line to evaluate") - self.child.send("to_\t") - self.child.expect_exact("to_complete") - - self.child.send("\n\n") - self.expect_prompt() - - self.quit() Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/multiline-completion/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/multiline-completion/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/multiline-completion/main.c @@ -1,5 +0,0 @@ -int main(int argc, char **argv) { - lldb_enable_attach(); - int to_complete = 0; - return to_complete; -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/namespace_local_var_same_name_cpp_and_c/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/namespace_local_var_same_name_cpp_and_c/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/namespace_local_var_same_name_cpp_and_c/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/namespace_local_var_same_name_cpp_and_c/TestNamespaceLocalVarSameNameCppAndC.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/namespace_local_var_same_name_cpp_and_c/TestNamespaceLocalVarSameNameCppAndC.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/namespace_local_var_same_name_cpp_and_c/TestNamespaceLocalVarSameNameCppAndC.py @@ -1,24 +0,0 @@ -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class TestNamespaceLocalVarSameNameCppAndC(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @skipUnlessDarwin - @add_test_categories(["gmodules"]) - def test_namespace_local_var_same_name_cpp_and_c(self): - self.build() - - (self.target, self.process, _, bkpt) = lldbutil.run_to_source_breakpoint(self, '// break here', - lldb.SBFileSpec("main.cpp", False)) - - self.expect("expr error", - substrs=['(int) $0 = 1']) - - lldbutil.continue_to_breakpoint(self.process, bkpt) - - self.expect("expr error", - substrs=['(int) $1 = 1']) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/namespace_local_var_same_name_cpp_and_c/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/namespace_local_var_same_name_cpp_and_c/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/namespace_local_var_same_name_cpp_and_c/main.cpp @@ -1,21 +0,0 @@ -namespace error { -int x; -} - -struct A { - void foo() { - int error = 1; - - return; // break here - } -}; - -int main() { - int error = 1; - - A a; - - a.foo(); - - return 0; // break here -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/namespace_local_var_same_name_obj_c/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/namespace_local_var_same_name_obj_c/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/namespace_local_var_same_name_obj_c/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make -OBJCXX_SOURCES := main.mm util.mm -include $(LEVEL)/Makefile.rules - -LDFLAGS += -framework Foundation Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/namespace_local_var_same_name_obj_c/TestNamespaceLocalVarSameNameObjC.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/namespace_local_var_same_name_obj_c/TestNamespaceLocalVarSameNameObjC.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/namespace_local_var_same_name_obj_c/TestNamespaceLocalVarSameNameObjC.py @@ -1,24 +0,0 @@ -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class TestNamespaceLocalVarSameNameObjC(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @skipUnlessDarwin - @add_test_categories(["gmodules"]) - def test_namespace_local_var_same_name_obj_c(self): - self.build() - - (self.target, self.process, _, bkpt) = lldbutil.run_to_source_breakpoint(self, '// break here', - lldb.SBFileSpec("util.mm", False)) - - self.expect("expr error", - substrs=['(NSError *) $0 =']) - - lldbutil.continue_to_breakpoint(self.process, bkpt) - - self.expect("expr error", - substrs=['(NSError *) $1 =']) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/namespace_local_var_same_name_obj_c/main.mm =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/namespace_local_var_same_name_obj_c/main.mm +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/namespace_local_var_same_name_obj_c/main.mm @@ -1,16 +0,0 @@ -#import -@interface Util : NSObject -+ (void)debugPrintErrorStatic; -- (void)debugPrintError; -@end - -int main(int argc, const char * argv[]) { - [Util debugPrintErrorStatic]; - - Util *u = [[Util alloc] init]; - - [u debugPrintError]; - - return 0; -} - Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/namespace_local_var_same_name_obj_c/util.mm =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/namespace_local_var_same_name_obj_c/util.mm +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/namespace_local_var_same_name_obj_c/util.mm @@ -1,22 +0,0 @@ -#import - -namespace error { -int blah; -} - -@interface Util : NSObject -+ (void)debugPrintErrorStatic; -- (void)debugPrintError; -@end - -@implementation Util -+ (void)debugPrintErrorStatic { - NSError* error = [NSError errorWithDomain:NSURLErrorDomain code:-1 userInfo:nil]; - NSLog(@"xxx, error = %@", error); // break here -} - -- (void)debugPrintError { - NSError* error = [NSError errorWithDomain:NSURLErrorDomain code:-1 userInfo:nil]; - NSLog(@"xxx, error = %@", error); // break here -} -@end Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp foo.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py @@ -1,91 +0,0 @@ -""" -Test expression command options. - -Test cases: - -o test_expr_options: - Test expression command options. -""" - -from __future__ import print_function - - -import lldb -import lldbsuite.test.lldbutil as lldbutil -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * - - -class ExprOptionsTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - - self.main_source = "main.cpp" - self.main_source_spec = lldb.SBFileSpec(self.main_source) - self.line = line_number('main.cpp', '// breakpoint_in_main') - self.exe = self.getBuildArtifact("a.out") - - def test_expr_options(self): - """These expression command options should work as expected.""" - self.build() - - # Set debugger into synchronous mode - self.dbg.SetAsync(False) - - (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( - self, '// breakpoint_in_main', self.main_source_spec) - - frame = thread.GetFrameAtIndex(0) - options = lldb.SBExpressionOptions() - - # test --language on C++ expression using the SB API's - - # Make sure we can evaluate a C++11 expression. - val = frame.EvaluateExpression('foo != nullptr') - self.assertTrue(val.IsValid()) - self.assertTrue(val.GetError().Success()) - self.DebugSBValue(val) - - # Make sure it still works if language is set to C++11: - options.SetLanguage(lldb.eLanguageTypeC_plus_plus_11) - val = frame.EvaluateExpression('foo != nullptr', options) - self.assertTrue(val.IsValid()) - self.assertTrue(val.GetError().Success()) - self.DebugSBValue(val) - - # Make sure it fails if language is set to C: - options.SetLanguage(lldb.eLanguageTypeC) - val = frame.EvaluateExpression('foo != nullptr', options) - self.assertTrue(val.IsValid()) - self.assertFalse(val.GetError().Success()) - - @skipIfDarwin - def test_expr_options_lang(self): - """These expression language options should work as expected.""" - self.build() - - # Set debugger into synchronous mode - self.dbg.SetAsync(False) - - (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( - self, '// breakpoint_in_main', self.main_source_spec) - - frame = thread.GetFrameAtIndex(0) - options = lldb.SBExpressionOptions() - - # Make sure we can retrieve `id` variable if language is set to C++11: - options.SetLanguage(lldb.eLanguageTypeC_plus_plus_11) - val = frame.EvaluateExpression('id == 0', options) - self.assertTrue(val.IsValid()) - self.assertTrue(val.GetError().Success()) - self.DebugSBValue(val) - - # Make sure we can't retrieve `id` variable if language is set to ObjC: - options.SetLanguage(lldb.eLanguageTypeObjC) - val = frame.EvaluateExpression('id == 0', options) - self.assertTrue(val.IsValid()) - self.assertFalse(val.GetError().Success()) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/foo.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/foo.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/foo.cpp @@ -1,11 +0,0 @@ -namespace ns { - int func(void) - { - return 0; - } -} - -extern "C" int foo(void) -{ - return ns::func(); -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/main.cpp @@ -1,17 +0,0 @@ -extern "C" int foo(void); -static int static_value = 0; -static int id = 1234; - -int -bar() -{ - static_value++; - id++; - return static_value + id; -} - -int main (int argc, char const *argv[]) -{ - bar(); // breakpoint_in_main - return foo(); -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/persist_objc_pointeetype/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/persist_objc_pointeetype/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/persist_objc_pointeetype/Makefile @@ -1,7 +0,0 @@ -LEVEL = ../../make - -OBJC_SOURCES := main.m - -include $(LEVEL)/Makefile.rules -LDFLAGS += -framework Foundation -framework CloudKit - Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/persist_objc_pointeetype/TestPersistObjCPointeeType.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/persist_objc_pointeetype/TestPersistObjCPointeeType.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/persist_objc_pointeetype/TestPersistObjCPointeeType.py @@ -1,51 +0,0 @@ -""" -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__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to break for main.cpp. - self.line = line_number('main.m', '// break here') - - @skipUnlessDarwin - @skipIf(archs=["i386", "i686"]) - @skipIf(debug_info="gmodules", archs=['arm64', 'armv7', 'armv7k']) # compile error with gmodules for iOS - def test_with(self): - """Test that we can p *objcObject""" - self.build() - - def cleanup(): - pass - - # Execute the cleanup function during test case tear down. - self.addTearDownHook(cleanup) - - self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) - - 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']) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/persist_objc_pointeetype/main.m =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/persist_objc_pointeetype/main.m +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/persist_objc_pointeetype/main.m @@ -1,80 +0,0 @@ -/* -clang -g ExtendSuperclass.m -o ExtendSuperclass -framework Foundation -framework ProtectedCloudStorage -F/System/Library/PrivateFrameworks/ -framework CloudKit && ./ExtendSuperclass -*/ -#include -#import -#import - -#define SuperClass CKDatabase - -@interface SubClass : SuperClass -@end - -// class extension -@interface SuperClass () -@property (nonatomic, strong) NSString *_sc_name; -@property (nonatomic, strong) NSString *_sc_name2; -@property (nonatomic, strong) NSString *_sc_name3; -@property (nonatomic, strong) NSString *_sc_name4; -@property (nonatomic, strong) NSString *_sc_name5; -@property (nonatomic, strong) NSString *_sc_name6; -@property (nonatomic, strong) NSString *_sc_name7; -@property (nonatomic, strong) NSString *_sc_name8; -@end - -@implementation SuperClass (MySuperClass) -- (id)initThatDoesNotAssert -{ - return [super init]; -} -@end - -@implementation SubClass -- (id)initThatDoesNotAssert -{ - assert(_sc_name == nil); - assert(_sc_name2 == nil); - assert(_sc_name3 == nil); - assert(_sc_name4 == nil); - assert(_sc_name5 == nil); - assert(_sc_name6 == nil); - assert(_sc_name7 == nil); - assert(_sc_name8 == nil); // break here - - if ((self = [super _initWithContainer:(CKContainer*)@"foo" scope:0xff])) { - assert(_sc_name == nil); - assert(_sc_name2 == nil); - assert(_sc_name3 == nil); - assert(_sc_name4 == nil); - assert(_sc_name5 == nil); - assert(_sc_name6 == nil); - assert(_sc_name7 == nil); - assert(_sc_name8 == nil); - - _sc_name = @"empty"; - } - return self; -} -@synthesize _sc_name; -@synthesize _sc_name2; -@synthesize _sc_name3; -@synthesize _sc_name4; -@synthesize _sc_name5; -@synthesize _sc_name6; -@synthesize _sc_name7; -@synthesize _sc_name8; -- (void)foo:(NSString*)bar { self._sc_name = bar; } -- (NSString*)description { return [NSString stringWithFormat:@"%p: %@", self, self._sc_name]; } -@end - -int main() -{ - SubClass *sc = [[SubClass alloc] initThatDoesNotAssert]; - NSLog(@"%@", sc); - [sc foo:@"bar"]; - NSLog(@"%@", sc); - sc._sc_name = @"bar2"; - NSLog(@"%@", sc); - NSLog(@"%@", sc._sc_name); - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_ptr_update/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_ptr_update/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_ptr_update/Makefile @@ -1,7 +0,0 @@ -LEVEL = ../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules - - Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_ptr_update/TestPersistentPtrUpdate.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_ptr_update/TestPersistentPtrUpdate.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_ptr_update/TestPersistentPtrUpdate.py @@ -1,41 +0,0 @@ -""" -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__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - - def test(self): - """Test that we can have persistent pointer variables""" - self.build() - - def cleanup(): - pass - - # Execute the cleanup function during test case tear down. - self.addTearDownHook(cleanup) - - self.runCmd("file " + self.getBuildArtifact("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']) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_ptr_update/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_ptr_update/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_ptr_update/main.c @@ -1,11 +0,0 @@ -void* foo(void *p) -{ - return p; // break here -} - -int main() { - while (1) { - foo(0); - } - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_types/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_types/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_types/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_types/TestNestedPersistentTypes.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_types/TestNestedPersistentTypes.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_types/TestNestedPersistentTypes.py @@ -1,42 +0,0 @@ -""" -Test that nested persistent types work. -""" - -from __future__ import print_function - - -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__) - - def test_persistent_types(self): - """Test that nested persistent types work.""" - self.build() - - self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) - - self.runCmd("breakpoint set --name main") - - self.runCmd("run", RUN_SUCCEEDED) - - 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 $my_bar = {{ 2, 3 }, { 4, 5 }};") - - self.expect("expression $my_bar", - substrs=['a = 2', 'b = 3', 'a = 4', 'b = 5']) - - self.expect("expression $my_bar.start.b", - substrs=['(int)', '3']) - - self.expect("expression $my_bar.end.b", - substrs=['(int)', '5']) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_types/TestPersistentTypes.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_types/TestPersistentTypes.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_types/TestPersistentTypes.py @@ -1,93 +0,0 @@ -""" -Test that lldb persistent types works correctly. -""" - -from __future__ import print_function - - -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__) - - def test_persistent_types(self): - """Test that lldb persistent types works correctly.""" - self.build() - - self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) - - self.runCmd("breakpoint set --name main") - - self.runCmd("run", RUN_SUCCEEDED) - - 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 $my_foo", - substrs=['a = 2', 'b = 3']) - - self.runCmd("expression typedef int $bar") - - self.expect("expression $bar i = 5; i", - startstr="($bar) $1 = 5") - - 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 -x c", - 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']) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_types/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_types/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_types/main.c @@ -1,13 +0,0 @@ -//===-- main.c --------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -int main (int argc, char const *argv[]) -{ - const char* foo = "Hello world"; - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_variables/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_variables/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_variables/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_variables/TestPersistentVariables.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_variables/TestPersistentVariables.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_variables/TestPersistentVariables.py @@ -1,53 +0,0 @@ -""" -Test that lldb persistent variables works correctly. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.lldbtest import * - - -class PersistentVariablesTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def test_persistent_variables(self): - """Test that lldb persistent variables works correctly.""" - self.build() - - self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) - - self.runCmd("breakpoint set --source-pattern-regexp break") - - self.runCmd("run", RUN_SUCCEEDED) - - self.runCmd("expression int $i = i") - - self.expect("expression $i == i", - startstr="(bool) $0 = true") - - self.expect("expression $i + 1", - startstr="(int) $1 = 6") - - self.expect("expression $i + 3", - startstr="(int) $2 = 8") - - self.expect("expression $2 + $1", - startstr="(int) $3 = 14") - - self.expect("expression $3", - startstr="(int) $3 = 14") - - self.expect("expression $2", - startstr="(int) $2 = 8") - - self.expect("expression (int)-2", - startstr="(int) $4 = -2") - - self.expect("expression $4 > (int)31", - startstr="(bool) $5 = false") - - self.expect("expression (long)$4", - startstr="(long) $6 = -2") Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_variables/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_variables/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/persistent_variables/main.c @@ -1,13 +0,0 @@ -//===-- main.c --------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -int main (int argc, char const *argv[]) -{ - int i = 5; - return 0; // Set breakpoint here -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/po_verbosity/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/po_verbosity/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/po_verbosity/Makefile @@ -1,6 +0,0 @@ -LEVEL = ../../make - -OBJC_SOURCES := main.m - -include $(LEVEL)/Makefile.rules -LDFLAGS += -framework Foundation Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/po_verbosity/TestPoVerbosity.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/po_verbosity/TestPoVerbosity.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/po_verbosity/TestPoVerbosity.py @@ -1,63 +0,0 @@ -""" -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__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to break for main.cpp. - self.line = line_number('main.m', - '// Stop here') - - @skipUnlessDarwin - 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 " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) - - 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;']) - self.expect("expr -O -vfull -- foo", - 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", - substrs=['22']) - - self.expect("expr -O -vfull -- 22", - substrs=['(int) $', ' = 22']) - - self.expect("expr -O -v -- 22", - substrs=['(int) $', ' = 22']) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/po_verbosity/main.m =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/po_verbosity/main.m +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/po_verbosity/main.m @@ -1,9 +0,0 @@ -#import - -int main() -{ - [NSString initialize]; - id foo = @{@1 : @2, @2 : @3}; - int x = 34; - return 0; // Stop here -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/pr35310/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/pr35310/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/pr35310/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/pr35310/TestExprsBug35310.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/pr35310/TestExprsBug35310.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/pr35310/TestExprsBug35310.py @@ -1,39 +0,0 @@ -from __future__ import print_function - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class ExprBug35310(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - - self.main_source = "main.cpp" - self.main_source_spec = lldb.SBFileSpec(self.main_source) - - def test_issue35310(self): - """Test invoking functions with non-standard linkage names. - - The GNU abi_tag extension used by libstdc++ is a common source - of these, but they could originate from other reasons as well. - """ - self.build() - - (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, - '// Break here', self.main_source_spec) - frame = thread.GetFrameAtIndex(0) - - value = frame.EvaluateExpression("a.test_abi_tag()") - self.assertTrue(value.IsValid()) - self.assertTrue(value.GetError().Success()) - self.assertEqual(value.GetValueAsSigned(0), 1) - - value = frame.EvaluateExpression("a.test_asm_name()") - self.assertTrue(value.IsValid()) - self.assertTrue(value.GetError().Success()) - self.assertEqual(value.GetValueAsSigned(0), 2) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/pr35310/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/pr35310/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/pr35310/main.cpp @@ -1,19 +0,0 @@ -#include - -class A { -public: - int __attribute__((abi_tag("cxx11"))) test_abi_tag() { - return 1; - } - int test_asm_name() asm("A_test_asm") { - return 2; - } -}; - -int main(int argc, char **argv) { - A a; - // Break here - a.test_abi_tag(); - a.test_asm_name(); - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_8638051/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_8638051/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_8638051/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_8638051/Test8638051.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_8638051/Test8638051.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_8638051/Test8638051.py @@ -1,38 +0,0 @@ -""" -Test the robustness of lldb expression parser. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.lldbtest import * - - -class Radar8638051TestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def test_expr_commands(self): - """The following expression commands should not crash.""" - self.build() - - self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) - - self.runCmd("breakpoint set -n c") - - self.runCmd("run", RUN_SUCCEEDED) - - self.expect("expression val", - startstr="(int) $0 = 1") - # (int) $0 = 1 - - self.expect("expression *(&val)", - 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 = ") - # (int *) $2 = 0x.... Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_8638051/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_8638051/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_8638051/main.c @@ -1,53 +0,0 @@ -//===-- main.c --------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -#include - -// This simple program is to demonstrate the capability of the lldb command -// "breakpoint command add" to add a set of commands to a breakpoint to be -// executed when the breakpoint is hit. -// -// In particular, we want to break within c(), but only if the immediate caller -// is a(). - -int a(int); -int b(int); -int c(int); - -int a(int val) -{ - if (val <= 1) - return b(val); - else if (val >= 3) - return c(val); // Find the line number where c's parent frame is a here. - - return val; -} - -int b(int val) -{ - return c(val); -} - -int c(int val) -{ - return val + 3; -} - -int main (int argc, char const *argv[]) -{ - int A1 = a(1); // a(1) -> b(1) -> c(1) - printf("a(1) returns %d\n", A1); - - int B2 = b(2); // b(2) -> c(2) - printf("b(2) returns %d\n", B2); - - int A3 = a(3); // a(3) -> c(3) - printf("a(3) returns %d\n", A3); - - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_9531204/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_9531204/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_9531204/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_9531204/TestPrintfAfterUp.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_9531204/TestPrintfAfterUp.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_9531204/TestPrintfAfterUp.py @@ -1,43 +0,0 @@ -""" -The evaluating printf(...) after break stop and then up a stack frame. -""" - -from __future__ import print_function - - -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__) - - # rdar://problem/9531204 - @expectedFailureNetBSD - def test_expr_commands(self): - """The evaluating printf(...) after break stop and then up a stack frame.""" - self.build() - - self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) - - lldbutil.run_break_set_by_symbol( - self, 'foo', sym_exact=True, num_expected_locations=1) - - self.runCmd("run", RUN_SUCCEEDED) - - self.runCmd("frame variable") - - # This works fine. - self.runCmd('expression (int)printf("value is: %d.\\n", value);') - - # rdar://problem/9531204 - # "Error dematerializing struct" error when evaluating expressions "up" on the stack - self.runCmd('up') # frame select -r 1 - - self.runCmd("frame variable") - - # This does not currently. - self.runCmd('expression (int)printf("argc is: %d.\\n", argc)') Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_9531204/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_9531204/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_9531204/main.c @@ -1,24 +0,0 @@ -//===-- main.c --------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -#include - -// breakpoint set -n foo -// -// -int foo (int value) -{ - printf ("I got the value: %d.\n", value); - return 0; -} - -int main (int argc, char **argv) -{ - foo (argc); - printf ("Hello there: %d.\n", argc); - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_9673664/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_9673664/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_9673664/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_9673664/TestExprHelpExamples.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_9673664/TestExprHelpExamples.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_9673664/TestExprHelpExamples.py @@ -1,45 +0,0 @@ -""" -Test example snippets from the lldb 'help expression' output. -""" - -from __future__ import print_function - - -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__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to break inside main(). - self.main_source = "main.c" - self.line = line_number(self.main_source, '// Set breakpoint here.') - - def test_expr_commands(self): - """The following expression commands should just work.""" - self.build() - - self.runCmd("file " + self.getBuildArtifact("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) - - self.runCmd("run", RUN_SUCCEEDED) - - # rdar://problem/9673664 lldb expression evaluation problem - - self.expect('expr char str[] = "foo"; str[0]', - substrs=["'f'"]) - # runCmd: expr char c[] = "foo"; c[0] - # output: (char) $0 = 'f' Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_9673664/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_9673664/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/radar_9673664/main.c @@ -1,15 +0,0 @@ -//===-- main.c --------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -#include - -int main (int argc, char const *argv[]) -{ - printf("Hello, world.\n"); // Set breakpoint here. - - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/rdar42038760/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/rdar42038760/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/rdar42038760/Makefile @@ -1,3 +0,0 @@ -LEVEL = ../../make -C_SOURCES := main.c -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/rdar42038760/TestScalarURem.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/rdar42038760/TestScalarURem.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/rdar42038760/TestScalarURem.py @@ -1,4 +0,0 @@ -from lldbsuite.test import lldbinline -from lldbsuite.test import decorators - -lldbinline.MakeInlineTest(__file__, globals(), None) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/rdar42038760/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/rdar42038760/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/rdar42038760/main.c @@ -1,19 +0,0 @@ -// Make sure we IR-interpret the expression correctly. - -typedef unsigned int uint32_t; -struct S0 { - signed f2; -}; -static g_463 = 0x1561983AL; -void func_1(void) -{ - struct S0 l_19; - l_19.f2 = 419; - uint32_t l_4037 = 4294967295UL; - l_19.f2 = g_463; //%self.expect("expr ((l_4037 % (-(g_463))) | l_19.f2)", substrs=['(unsigned int) $0 = 358717883']) -} -int main() -{ - func_1(); - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/rdar44436068/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/rdar44436068/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/rdar44436068/Makefile @@ -1,3 +0,0 @@ -LEVEL = ../../make -C_SOURCES := main.c -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/rdar44436068/Test128BitsInteger.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/rdar44436068/Test128BitsInteger.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/rdar44436068/Test128BitsInteger.py @@ -1,6 +0,0 @@ -from lldbsuite.test import lldbinline -from lldbsuite.test import decorators - -lldbinline.MakeInlineTest(__file__, globals(), - decorators.skipIf(archs=["armv7k"])) - Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/rdar44436068/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/rdar44436068/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/rdar44436068/main.c @@ -1,8 +0,0 @@ -int main(void) -{ - __int128_t n = 1; - n = n + n; - return n; //%self.expect("p n", substrs=['(__int128_t) $0 = 2']) - //%self.expect("p n + 6", substrs=['(__int128) $1 = 8']) - //%self.expect("p n + n", substrs=['(__int128) $2 = 4']) -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/save_jit_objects/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/save_jit_objects/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/save_jit_objects/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/save_jit_objects/TestSaveJITObjects.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/save_jit_objects/TestSaveJITObjects.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/save_jit_objects/TestSaveJITObjects.py @@ -1,53 +0,0 @@ -""" -Test that LLDB can emit JIT objects when the appropriate setting is enabled -""" - -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 SaveJITObjectsTestCase(TestBase): - mydir = TestBase.compute_mydir(__file__) - - def enumerateJITFiles(self): - return [f for f in os.listdir(self.getBuildDir()) if f.startswith("jit")] - - def countJITFiles(self): - return len(self.enumerateJITFiles()) - - def cleanJITFiles(self): - for j in self.enumerateJITFiles(): - os.remove(j) - return - - @expectedFailureAll(oslist=["windows"]) - @expectedFailureNetBSD - def test_save_jit_objects(self): - self.build() - os.chdir(self.getBuildDir()) - src_file = "main.c" - src_file_spec = lldb.SBFileSpec(src_file) - - (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( - self, "break", src_file_spec) - - frame = thread.frames[0] - - self.cleanJITFiles() - frame.EvaluateExpression("(void*)malloc(0x1)") - self.assertTrue(self.countJITFiles() == 0, - "No files emitted with save-jit-objects=false") - - self.runCmd("settings set target.save-jit-objects true") - frame.EvaluateExpression("(void*)malloc(0x1)") - jit_files_count = self.countJITFiles() - self.cleanJITFiles() - self.assertTrue(jit_files_count != 0, - "At least one file emitted with save-jit-objects=true") - - process.Kill() - os.chdir(self.getSourceDir()) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/save_jit_objects/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/save_jit_objects/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/save_jit_objects/main.c @@ -1,13 +0,0 @@ -//===-- main.c --------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -int main (int argc, char const *argv[]) -{ - const char* foo = "Hello world"; // break here - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/scoped_enums/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/scoped_enums/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/scoped_enums/Makefile @@ -1,6 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp -CXXFLAGS += -std=c++11 - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/scoped_enums/TestScopedEnumType.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/scoped_enums/TestScopedEnumType.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/scoped_enums/TestScopedEnumType.py @@ -1,45 +0,0 @@ -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class ScopedEnumType(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @skipIf(dwarf_version=['<', '4']) - def test(self): - self.build() - - self.main_source = "main.cpp" - self.main_source_spec = lldb.SBFileSpec(self.main_source) - (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, - '// Set break point at this line.', self.main_source_spec) - frame = thread.GetFrameAtIndex(0) - - self.expect("expr f == Foo::FooBar", - substrs=['(bool) $0 = true']) - - value = frame.EvaluateExpression("f == Foo::FooBar") - self.assertTrue(value.IsValid()) - self.assertTrue(value.GetError().Success()) - self.assertEqual(value.GetValueAsUnsigned(), 1) - - value = frame.EvaluateExpression("b == BarBar") - self.assertTrue(value.IsValid()) - self.assertTrue(value.GetError().Success()) - self.assertEqual(value.GetValueAsUnsigned(), 1) - - ## b is not a Foo - value = frame.EvaluateExpression("b == Foo::FooBar") - self.assertTrue(value.IsValid()) - self.assertFalse(value.GetError().Success()) - - ## integral is not implicitly convertible to a scoped enum - value = frame.EvaluateExpression("1 == Foo::FooBar") - self.assertTrue(value.IsValid()) - self.assertFalse(value.GetError().Success()) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/scoped_enums/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/scoped_enums/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/scoped_enums/main.cpp @@ -1,16 +0,0 @@ -enum class Foo { - FooBar = 42 -}; - -enum Bar { - BarBar = 3, - BarBarBar = 42 -}; - -int main(int argc, const char **argv) { - Foo f = Foo::FooBar; - Bar b = BarBar; - bool b1 = f == Foo::FooBar; - bool b2 = b == BarBar; - return 0; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/test/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/test/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/test/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/test/TestExprs.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/test/TestExprs.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/test/TestExprs.py @@ -1,253 +0,0 @@ -""" -Test many basic expression commands and SBFrame.EvaluateExpression() API. - -Test cases: - -o test_many_expr_commands: - Test many basic expression commands. -o test_evaluate_expression_python: - Use Python APIs (SBFrame.EvaluateExpression()) to evaluate expressions. -o test_expr_commands_can_handle_quotes: - Throw some expression commands with quotes at lldb. -""" - -from __future__ import print_function - - -import unittest2 - -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__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to break for main.c. - self.line = line_number( - 'main.cpp', - '// 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")) - - def build_and_run(self): - """These basic expression commands should work as expected.""" - self.build() - - self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) - - lldbutil.run_break_set_by_file_and_line( - self, "main.cpp", self.line, num_expected_locations=1, loc_exact=False) - - self.runCmd("run", RUN_SUCCEEDED) - - @unittest2.expectedFailure( - "llvm.org/pr17135 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"]) - # (float) $2 = 2.234 - - def test_many_expr_commands(self): - self.build_and_run() - - self.expect("expression 2", - patterns=["\(int\) \$.* = 2"]) - # (int) $0 = 1 - - self.expect("expression 2ull", - patterns=["\(unsigned long long\) \$.* = 2"]) - # (unsigned long long) $1 = 2 - - self.expect("expression 0.5f", - patterns=["\(float\) \$.* = 0\.5"]) - # (float) $2 = 0.5 - - self.expect("expression 2.234", - patterns=["\(double\) \$.* = 2\.234"]) - # (double) $3 = 2.234 - - self.expect("expression 2+3", - patterns=["\(int\) \$.* = 5"]) - # (int) $4 = 5 - - self.expect("expression argc", - patterns=["\(int\) \$.* = 1"]) - # (int) $5 = 1 - - self.expect("expression argc + 22", - patterns=["\(int\) \$.* = 23"]) - # (int) $6 = 23 - - self.expect("expression argv", - patterns=["\(const char \*\*\) \$.* = 0x"]) - # (const char *) $7 = ... - - self.expect("expression argv[0]", - substrs=["(const char *)", - "a.out"]) - # (const char *) $8 = 0x... "/Volumes/data/lldb/svn/trunk/test/expression_command/test/a.out" - - @add_test_categories(['pyapi']) - @expectedFlakeyNetBSD - def test_evaluate_expression_python(self): - """Test SBFrame.EvaluateExpression() API for evaluating an expression.""" - self.build() - - exe = self.getBuildArtifact("a.out") - - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, VALID_TARGET) - - # Create the breakpoint. - filespec = lldb.SBFileSpec("main.cpp", False) - breakpoint = target.BreakpointCreateByLocation(filespec, self.line) - self.assertTrue(breakpoint, VALID_BREAKPOINT) - - # Verify the breakpoint just created. - self.expect(str(breakpoint), BREAKPOINT_CREATED, exe=False, - 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()) - - if not process: - self.fail("SBTarget.LaunchProcess() failed") - - if process.GetState() != lldb.eStateStopped: - self.fail("Process should be in the 'stopped' state, " - "instead the actual state is: '%s'" % - lldbutil.state_type_to_str(process.GetState())) - - thread = lldbutil.get_one_thread_stopped_at_breakpoint( - process, breakpoint) - self.assertIsNotNone( - thread, "Expected one thread to be stopped at the breakpoint") - - # 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") - self.expect(lldbutil.get_function_names(thread)[0], - "Break correctly at main()", exe=False, - startstr="main") - - # We should be stopped on the breakpoint with a hit count of 1. - self.assertTrue(breakpoint.GetHitCount() == 1, BREAKPOINT_HIT_ONCE) - - # - # Use Python API to evaluate expressions while stopped in a stack frame. - # - frame = thread.GetFrameAtIndex(0) - - val = frame.EvaluateExpression("2.234") - self.expect(val.GetValue(), "2.345 evaluated correctly", exe=False, - startstr="2.234") - self.expect(val.GetTypeName(), "2.345 evaluated correctly", exe=False, - startstr="double") - self.DebugSBValue(val) - - val = frame.EvaluateExpression("argc") - self.expect(val.GetValue(), "Argc evaluated correctly", exe=False, - startstr="4") - self.DebugSBValue(val) - - val = frame.EvaluateExpression("*argv[1]") - self.expect(val.GetValue(), "Argv[1] evaluated correctly", exe=False, - startstr="'X'") - self.DebugSBValue(val) - - val = frame.EvaluateExpression("*argv[2]") - self.expect(val.GetValue(), "Argv[2] evaluated correctly", exe=False, - startstr="'Y'") - self.DebugSBValue(val) - - val = frame.EvaluateExpression("*argv[3]") - self.expect(val.GetValue(), "Argv[3] evaluated correctly", exe=False, - startstr="'Z'") - self.DebugSBValue(val) - - 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) - - # 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) - - # rdar://problem/8686536 - # CommandInterpreter::HandleCommand is stripping \'s from input for - # WantsRawCommand commands - @expectedFailureNetBSD - def test_expr_commands_can_handle_quotes(self): - """Throw some expression commands with quotes at lldb.""" - self.build() - - self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) - - lldbutil.run_break_set_by_file_and_line( - self, "main.cpp", self.line, num_expected_locations=1, loc_exact=False) - - self.runCmd("run", RUN_SUCCEEDED) - - # runCmd: expression 'a' - # output: (char) $0 = 'a' - self.expect("expression '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']) - - # runCmd: expression (int) printf("\t\x68\n") - # output: (int) $2 = 3 - self.expect(r'''expression (int) printf("\t\x68\n")''', - substrs=['(int) $', - '3']) - - # runCmd: expression (int) printf("\"\n") - # output: (int) $3 = 2 - self.expect(r'''expression (int) printf("\"\n")''', - substrs=['(int) $', - '2']) - - # runCmd: expression (int) printf("'\n") - # output: (int) $4 = 2 - self.expect(r'''expression (int) printf("'\n")''', - 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")''') - # This fails currently. - self.expect('print_hi', - substrs=['(int) $', - '6']) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/test/TestExprs2.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/test/TestExprs2.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/test/TestExprs2.py @@ -1,74 +0,0 @@ -""" -Test some more expression commands. -""" - -from __future__ import print_function - - -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__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to break for main.c. - self.line = line_number( - 'main.cpp', - '// Please test many expressions while stopped at this line:') - - def test_more_expr_commands(self): - """Test some more expression commands.""" - self.build() - - self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) - - lldbutil.run_break_set_by_file_and_line( - self, "main.cpp", self.line, num_expected_locations=1, loc_exact=False) - - self.runCmd("run", RUN_SUCCEEDED) - - # Does static casting work? - self.expect("expression (int*)argv", - startstr="(int *) $0 = 0x") - # (int *) $0 = 0x00007fff5fbff258 - - # Do return values containing the contents of expression locals work? - self.expect("expression int i = 5; i", - startstr="(int) $1 = 5") - # (int) $2 = 5 - self.expect("expression $1 + 1", - startstr="(int) $2 = 6") - # (int) $3 = 6 - - # Do return values containing the results of static expressions work? - self.expect("expression 20 + 3", - startstr="(int) $3 = 23") - # (int) $4 = 5 - self.expect("expression $3 + 1", - startstr="(int) $4 = 24") - # (int) $5 = 6 - - @skipIfLinux - @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24489") - def test_expr_symbols(self): - """Test symbols.""" - self.build() - - self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) - - lldbutil.run_break_set_by_file_and_line( - self, "main.cpp", self.line, num_expected_locations=1, loc_exact=False) - - self.runCmd("run", RUN_SUCCEEDED) - - # Do anonymous symbols work? - self.expect("expression ((char**)environ)[0]", - startstr="(char *) $0 = 0x") - # (char *) $1 = 0x00007fff5fbff298 "Apple_PubSub_Socket_Render=/tmp/launch-7AEsUD/Render" Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/test/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/test/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/test/main.cpp @@ -1,44 +0,0 @@ -#include - -static int static_value = 0; - -int -a_function_to_call() -{ - static_value++; - return static_value; -} - -int main (int argc, char const *argv[]) -{ - printf ("Hello world!\n"); - puts ("hello"); - // Please test many expressions while stopped at this line: -#if 0 - expression 'a' // make sure character constant makes it down (this is broken: ) - expression 2 // Test int - expression 2ull // Test unsigned long long - expression 2.234f // Test float constants - expression 2.234 // Test double constants - expression 2+3 - expression argc - expression argc + 22 - expression argv - expression argv[0] - expression argv[1] - expression argv[-1] - expression puts("bonjour") // Test constant strings... - expression printf("\t\x68\n") // Test constant strings that contain the \xXX (TAB, 'h', '\n' should be printed) (this is broken: ) - expression printf("\"\n") // Test constant strings that contains an escaped double quote char (this is broken: ) - expression printf("\'\n") // Test constant strings that contains an escaped single quote char (this is broken: ) - expression printf ("one: %i\n", 1) - expression printf ("1.234 as float: %f\n", 1.234f) - expression printf ("1.234 as double: %g\n", 1.234) - expression printf ("one: %i, two: %llu\n", 1, 2ull) - expression printf ("two: %llu, one: %i\n", 2ull, 1) - expression random() % 255l -#endif - - a_function_to_call(); - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/timeout/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/timeout/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/timeout/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := wait-a-while.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/timeout/TestCallWithTimeout.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/timeout/TestCallWithTimeout.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/timeout/TestCallWithTimeout.py @@ -1,80 +0,0 @@ -""" -Test calling a function that waits a while, and make sure the timeout option to expr works. -""" - -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__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - - self.main_source = "wait-a-while.cpp" - self.main_source_spec = lldb.SBFileSpec(self.main_source) - - @expectedFlakeyFreeBSD("llvm.org/pr19605") - @expectedFailureAll( - oslist=[ - "windows"], - bugnumber="llvm.org/pr21765") - def test(self): - """Test calling std::String member function.""" - self.build() - - (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( - self, 'stop here in main.', self.main_source_spec) - - # 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()) - - # 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) - - # Okay, now do it again with long enough time outs: - - options.SetTimeoutInMicroSeconds(1000000) - value = frame.EvaluateExpression("wait_a_while (1000)", options) - self.assertTrue(value.IsValid()) - 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) - self.assertTrue(return_value == lldb.eReturnStatusSuccessFinishResult) - - # 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) - self.assertTrue(value.IsValid()) - self.assertTrue(value.GetError().Success()) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/timeout/wait-a-while.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/timeout/wait-a-while.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/timeout/wait-a-while.cpp @@ -1,35 +0,0 @@ -#include -#include - -#include -#include - - -int -wait_a_while (int microseconds) -{ - int num_times = 0; - auto end_time = std::chrono::system_clock::now() + std::chrono::microseconds(microseconds); - - while (1) - { - num_times++; - auto wait_time = end_time - std::chrono::system_clock::now(); - - std::this_thread::sleep_for(wait_time); - if (std::chrono::system_clock::now() > end_time) - break; - } - return num_times; -} - -int -main (int argc, char **argv) -{ - printf ("stop here in main.\n"); - int num_times = wait_a_while (argc * 1000); - printf ("Done, took %d times.\n", num_times); - - return 0; - -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/top-level/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/top-level/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/top-level/Makefile @@ -1,13 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp test.cpp - -include $(LEVEL)/Makefile.rules - -a.out: dummy - -dummy: - $(MAKE) VPATH=$(VPATH) -I $(SRCDIR) -f $(SRCDIR)/dummy.mk - -clean:: - $(MAKE) VPATH=$(VPATH) -I $(SRCDIR) -f $(SRCDIR)/dummy.mk clean Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/top-level/TestTopLevelExprs.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/top-level/TestTopLevelExprs.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/top-level/TestTopLevelExprs.py @@ -1,94 +0,0 @@ -""" -Test top-level expressions. -""" - -from __future__ import print_function - - -import unittest2 - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TopLevelExpressionsTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to break for main.c. - self.line = line_number('main.cpp', - '// Set breakpoint here') - self.dummy_line = line_number('dummy.cpp', - '// Set breakpoint here') - - # Disable confirmation prompt to avoid infinite wait - self.runCmd("settings set auto-confirm true") - self.addTearDownHook( - lambda: self.runCmd("settings clear auto-confirm")) - - def build_and_run(self): - """Test top-level expressions.""" - self.build() - - self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) - - lldbutil.run_break_set_by_file_and_line( - self, "main.cpp", self.line, num_expected_locations=1, loc_exact=False) - - self.runCmd("run", RUN_SUCCEEDED) - - def run_dummy(self): - self.runCmd("file " + self.getBuildArtifact("dummy"), - CURRENT_EXECUTABLE_SET) - - lldbutil.run_break_set_by_file_and_line( - self, - "dummy.cpp", - self.dummy_line, - num_expected_locations=1, - loc_exact=False) - - self.runCmd("run", RUN_SUCCEEDED) - - @add_test_categories(['pyapi']) - @skipIf(debug_info="gmodules") # not relevant - @skipIf(oslist=["windows"]) # Error in record layout on Windows - def test_top_level_expressions(self): - self.build_and_run() - - resultFromCode = self.frame().EvaluateExpression("doTest()").GetValueAsUnsigned() - - self.runCmd("kill") - - self.run_dummy() - - codeFile = open('test.cpp', 'r') - - expressions = [] - current_expression = "" - - for line in codeFile: - if line.startswith("// --"): - expressions.append(current_expression) - current_expression = "" - else: - current_expression += line - - options = lldb.SBExpressionOptions() - options.SetLanguage(lldb.eLanguageTypeC_plus_plus) - options.SetTopLevel(True) - - for expression in expressions: - self.frame().EvaluateExpression(expression, options) - - resultFromTopLevel = self.frame().EvaluateExpression("doTest()") - - self.assertTrue(resultFromTopLevel.IsValid()) - self.assertEqual( - resultFromCode, - resultFromTopLevel.GetValueAsUnsigned()) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/top-level/dummy.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/top-level/dummy.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/top-level/dummy.cpp @@ -1,15 +0,0 @@ -#include - -// These are needed to make sure that the linker does not strip the parts of the -// C++ abi library that are necessary to execute the expressions in the -// debugger. It would be great if we did not need to do this, but the fact that -// LLDB cannot conjure up the abi library on demand is not relevant for testing -// top level expressions. -struct DummyA {}; -struct DummyB : public virtual DummyA {}; - -int main() { - DummyB b; - printf("This is a dummy\n"); // Set breakpoint here - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/top-level/dummy.mk =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/top-level/dummy.mk +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/top-level/dummy.mk @@ -1,6 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := dummy.cpp -EXE := dummy - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/top-level/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/top-level/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/top-level/main.cpp @@ -1,9 +0,0 @@ -#include - -extern int doTest(); - -int main() -{ - printf("%d\n", doTest()); // Set breakpoint here - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/top-level/test.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/top-level/test.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/top-level/test.cpp @@ -1,107 +0,0 @@ -class MyClass -{ -public: - int memberResult() - { - return 1; - } - static int staticResult() - { - return 1; - } - int externResult(); -}; - -// -- - -int MyClass::externResult() -{ - return 1; -} - -// -- - -MyClass m; - -// -- - -enum MyEnum { - myEnumOne = 1, - myEnumTwo, - myEnumThree -}; - -// -- - -class AnotherClass -{ -public: - __attribute__ ((always_inline)) int complicatedFunction() - { - struct { - int i; - } s = { 15 }; - - int numbers[4] = { 2, 3, 4, 5 }; - - for (signed char number: numbers) - { - s.i -= number; - } - - return s.i; - } -}; - -// -- - -class DiamondA -{ -private: - struct { - int m_i; - }; -public: - DiamondA(int i) : m_i(i) { } - int accessor() { return m_i; } -}; - -// -- - -class DiamondB : public virtual DiamondA -{ -public: - DiamondB(int i) : DiamondA(i) { } -}; - -// -- - -class DiamondC : public virtual DiamondA -{ -public: - DiamondC(int i) : DiamondA(i) { } -}; - -// -- - -class DiamondD : public DiamondB, public DiamondC -{ -public: - DiamondD(int i) : DiamondA(i), DiamondB(i), DiamondC(i) { } -}; - -// -- - -int doTest() -{ - int accumulator = m.memberResult(); - accumulator += MyClass::staticResult(); - accumulator += m.externResult(); - accumulator += MyEnum::myEnumThree; - accumulator += myEnumOne; - accumulator += AnotherClass().complicatedFunction(); - accumulator += DiamondD(3).accessor(); - return accumulator; -} - -// -- Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/two-files/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/two-files/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/two-files/Makefile @@ -1,7 +0,0 @@ -LEVEL = ../../make - -OBJC_SOURCES := main.m foo.m - -include $(LEVEL)/Makefile.rules - -LDFLAGS += -framework Foundation \ No newline at end of file Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/two-files/TestObjCTypeQueryFromOtherCompileUnit.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/two-files/TestObjCTypeQueryFromOtherCompileUnit.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/two-files/TestObjCTypeQueryFromOtherCompileUnit.py @@ -1,41 +0,0 @@ -""" -Regression test for : - -The expression parser's type search only looks in the current compilation unit for types. -""" - -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__) - - def setUp(self): - # 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'.") - - @skipUnlessDarwin - def test(self): - """The expression parser's type search should be wider than the current compilation unit.""" - self.build() - self.runCmd("file " + self.getBuildArtifact("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) - - 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']) - # (NSArray *) $0 = 0x00007fff70118398 Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/two-files/foo.m =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/two-files/foo.m +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/two-files/foo.m @@ -1,28 +0,0 @@ -#import - -NSMutableArray * -GetArray () -{ - static NSMutableArray *the_array = NULL; - if (the_array == NULL) - the_array = [[NSMutableArray alloc] init]; - return the_array; -} - -int -AddElement (char *value) -{ - NSString *element = [NSString stringWithUTF8String: value]; - int cur_elem = [GetArray() count]; - [GetArray() addObject: element]; - return cur_elem; -} - -const char * -GetElement (int idx) -{ - if (idx >= [GetArray() count]) - return NULL; - else - return [[GetArray() objectAtIndex: idx] UTF8String]; -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/two-files/main.m =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/two-files/main.m +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/two-files/main.m @@ -1,22 +0,0 @@ -#import -#include - -extern int AddElement (char *value); -extern char *GetElement (int idx); -extern void *GetArray(); - -int -main () -{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - int idx = AddElement ("some string"); - void *array_token = GetArray(); - - char *string = GetElement (0); // Set breakpoint here, then do 'expr (NSArray*)array_token'. - if (string) - printf ("This: %s.\n", string); - - [pool release]; - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/unicode-in-variable/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/unicode-in-variable/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/unicode-in-variable/Makefile @@ -1,4 +0,0 @@ -LEVEL = ../../make -CXX_SOURCES := main.cpp -CXX_FLAGS_EXTRA := -finput-charset=UTF-8 -fextended-identifiers -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/unicode-in-variable/TestUnicodeInVariable.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/unicode-in-variable/TestUnicodeInVariable.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/unicode-in-variable/TestUnicodeInVariable.py @@ -1,4 +0,0 @@ -from lldbsuite.test import lldbinline -from lldbsuite.test import decorators - -lldbinline.MakeInlineTest(__file__, globals(), None) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/unicode-in-variable/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/unicode-in-variable/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/unicode-in-variable/main.cpp @@ -1,17 +0,0 @@ -// Make sure we correctly handle unicode in variable names. - -struct A { - // We need a member variable in the context that could shadow our local - // variable. If our optimization code fails to handle this, then we won't - // correctly inject our local variable so that it won't get shadowed. - int foob\u00E1r = 2; - int foo() { - int foob\u00E1r = 3; - return foob\u00E1r; //%self.expect("expr foobár", substrs=['(int)', ' = 3']) - } -}; - -int main() { - A a; - return a.foo(); -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/unwind_expression/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/unwind_expression/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/unwind_expression/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/unwind_expression/TestUnwindExpression.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/unwind_expression/TestUnwindExpression.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/unwind_expression/TestUnwindExpression.py @@ -1,101 +0,0 @@ -""" -Test stopping at a breakpoint in an expression, and unwinding from there. -""" - -from __future__ import print_function - - -import unittest2 - -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__) - main_spec = lldb.SBFileSpec("main.cpp", False) - - def build_and_run_to_bkpt(self): - self.build() - - (target, process, self.thread, bkpt) = lldbutil.run_to_source_breakpoint(self, - "// Set a breakpoint here to get started", self.main_spec) - - # Next set a breakpoint in this function, set up Expression options to stop on - # breakpoint hits, and call the function. - self.fun_bkpt = self.target().BreakpointCreateBySourceRegex( - "// Stop inside the function here.", self.main_spec) - self.assertTrue(self.fun_bkpt, VALID_BREAKPOINT) - - - @no_debug_info_test - @expectedFailureAll(bugnumber="llvm.org/pr33164") - def test_conditional_bktp(self): - """ - Test conditional breakpoint handling in the IgnoreBreakpoints = False case - """ - self.build_and_run_to_bkpt() - - self.fun_bkpt.SetCondition("0") # Should not get hit - options = lldb.SBExpressionOptions() - options.SetIgnoreBreakpoints(False) - options.SetUnwindOnError(False) - - main_frame = self.thread.GetFrameAtIndex(0) - val = main_frame.EvaluateExpression("second_function(47)", options) - self.assertTrue( - val.GetError().Success(), - "We did complete the execution.") - self.assertEquals(47, val.GetValueAsSigned()) - - - @add_test_categories(['pyapi']) - @expectedFlakeyNetBSD - def test_unwind_expression(self): - """Test unwinding from an expression.""" - self.build_and_run_to_bkpt() - - # Run test with varying one thread timeouts to also test the halting - # logic in the IgnoreBreakpoints = False case - self.do_unwind_test(self.thread, self.fun_bkpt, 1000) - self.do_unwind_test(self.thread, self.fun_bkpt, 100000) - - def do_unwind_test(self, thread, bkpt, timeout): - # - # Use Python API to evaluate expressions while stopped in a stack frame. - # - main_frame = thread.GetFrameAtIndex(0) - - options = lldb.SBExpressionOptions() - options.SetIgnoreBreakpoints(False) - options.SetUnwindOnError(False) - options.SetOneThreadTimeoutInMicroSeconds(timeout) - - val = main_frame.EvaluateExpression("a_function_to_call()", options) - - self.assertTrue( - val.GetError().Fail(), - "We did not complete the execution.") - error_str = val.GetError().GetCString() - self.assertTrue( - "Execution was interrupted, reason: breakpoint" in error_str, - "And the reason was right.") - - thread = lldbutil.get_one_thread_stopped_at_breakpoint( - self.process(), 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.") Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/unwind_expression/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/unwind_expression/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/unwind_expression/main.cpp @@ -1,22 +0,0 @@ -static int static_value = 0; - -int -a_function_to_call() -{ - static_value++; // Stop inside the function here. - return static_value; -} - -int second_function(int x){ - for(int i=0; i<10; ++i) { - a_function_to_call(); - } - return x; -} - -int main (int argc, char const *argv[]) -{ - a_function_to_call(); // Set a breakpoint here to get started - second_function(1); - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/vector_of_enums/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/vector_of_enums/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/vector_of_enums/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/vector_of_enums/TestVectorOfEnums.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/vector_of_enums/TestVectorOfEnums.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/vector_of_enums/TestVectorOfEnums.py @@ -1,29 +0,0 @@ -""" -Test Expression Parser regression test to ensure that we handle enums -correctly, in this case specifically std::vector of enums. -""" - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class TestVectorOfEnums(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @add_test_categories(["libc++"]) - def test_vector_of_enums(self): - self.build() - - lldbutil.run_to_source_breakpoint(self, '// break here', - lldb.SBFileSpec("main.cpp", False)) - - self.expect("expr v", substrs=[ - 'size=3', - '[0] = a', - '[1] = b', - '[2] = c', - '}' - ]) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/vector_of_enums/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/vector_of_enums/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/vector_of_enums/main.cpp @@ -1,14 +0,0 @@ -#include - -enum E { -a, -b, -c, -d -} ; - -int main() { - std::vector v = {E::a, E::b, E::c}; - - return v.size(); // break here -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/weak_symbols/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/weak_symbols/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/weak_symbols/Makefile @@ -1,26 +0,0 @@ -LEVEL = ../../make -CFLAGS_EXTRAS += -std=c99 -LD_FLAGS := -dynamiclib -include $(LEVEL)/Makefile.rules - -all: a.out dylib missing - -dylib: dylib.o - $(CC) $(LD_FLAGS) -o libdylib.dylib dylib.o - -missing: dylib2.o - mkdir hidden - $(CC) $(LD_FLAGS) -o hidden/libdylib.dylib dylib2.o - -a.out: main.o dylib missing - $(CC) $(CFLAGS) -L. -ldylib main.o - -dylib.o: dylib.h $(SRCDIR)/dylib.c - $(CC) -DHAS_THEM $(CFLAGS) -c $(SRCDIR)/dylib.c - -dylib2.o: dylib.h $(SRCDIR)/dylib.c - $(CC) $(CFLAGS) -c $(SRCDIR)/dylib.c -o dylib2.o - -main.o: dylib.h $(SRCDIR)/main.c - $(CC) $(CFLAGS) -c $(SRCDIR)/main.c -fmodules -fmodules-cache-path=$(CLANG_MODULE_CACHE_DIR) - Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/weak_symbols/TestWeakSymbols.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/weak_symbols/TestWeakSymbols.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/weak_symbols/TestWeakSymbols.py @@ -1,81 +0,0 @@ -""" -Test that we can compile expressions referring to -absent weak symbols from a dylib. -""" - -from __future__ import print_function - - -import os -import lldb -from lldbsuite.test import decorators -import lldbsuite.test.lldbutil as lldbutil -from lldbsuite.test.lldbtest import * - - -class TestWeakSymbolsInExpressions(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - NO_DEBUG_INFO_TESTCASE = True - - @decorators.skipUnlessDarwin - def test_weak_symbol_in_expr(self): - """Tests that we can refer to weak symbols in expressions.""" - self.build() - self.main_source_file = lldb.SBFileSpec("main.c") - self.do_test() - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - - def run_weak_var_check (self, weak_varname, present): - # The expression will modify present_weak_int to signify which branch - # was taken. Set it to so we don't get confused by a previous run. - value = self.target.FindFirstGlobalVariable("present_weak_int") - value.SetValueFromCString("0") - if present: - correct_value = 10 - else: - correct_value = 20 - - # Note, I'm adding the "; 10" at the end of the expression to work around - # the bug that expressions with no result currently return False for Success()... - expr = "if (&" + weak_varname + " != NULL) { present_weak_int = 10; } else { present_weak_int = 20;}; 10" - result = self.frame.EvaluateExpression(expr) - self.assertTrue(result.GetError().Success(), "absent_weak_int expr failed: %s"%(result.GetError().GetCString())) - self.assertEqual(value.GetValueAsSigned(), correct_value, "Didn't change present_weak_int correctly.") - - def do_test(self): - hidden_dir = os.path.join(self.getBuildDir(), "hidden") - - launch_info = lldb.SBLaunchInfo(None) - launch_info.SetWorkingDirectory(self.getBuildDir()) - # We have to point to the hidden directory to pick up the - # version of the dylib without the weak symbols: - env_expr = self.platformContext.shlib_environment_var + "=" + hidden_dir - launch_info.SetEnvironmentEntries([env_expr], True) - - (self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, - "Set a breakpoint here", self.main_source_file, - launch_info = launch_info) - # First we have to import the Dylib module so we get the type info - # for the weak symbol. We need to add the source dir to the module - # search paths, and then run @import to introduce it into the expression - # context: - self.dbg.HandleCommand("settings set target.clang-module-search-paths " + self.getSourceDir()) - - self.frame = thread.frames[0] - self.assertTrue(self.frame.IsValid(), "Got a good frame") - options = lldb.SBExpressionOptions() - options.SetLanguage(lldb.eLanguageTypeObjC) - result = self.frame.EvaluateExpression("@import Dylib", options) - - # Now run an expression that references an absent weak symbol: - self.run_weak_var_check("absent_weak_int", False) - self.run_weak_var_check("absent_weak_function", False) - - # Make sure we can do the same thing with present weak symbols - self.run_weak_var_check("present_weak_int", True) - self.run_weak_var_check("present_weak_function", True) Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/weak_symbols/dylib.h =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/weak_symbols/dylib.h +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/weak_symbols/dylib.h @@ -1,8 +0,0 @@ -extern int absent_weak_int __attribute__((weak_import)); - -extern int present_weak_int __attribute__((weak_import)); - -extern int absent_weak_function() __attribute__((weak_import)); - -extern int present_weak_function() __attribute__((weak_import)); - Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/weak_symbols/dylib.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/weak_symbols/dylib.c +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/weak_symbols/dylib.c @@ -1,14 +0,0 @@ -#include "dylib.h" - -int present_weak_int = 10; -int present_weak_function() -{ - return present_weak_int; -} - -#if defined HAS_THEM -int absent_weak_int = 10; -int absent_weak_function() { - return absent_weak_int; -} -#endif Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/weak_symbols/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/weak_symbols/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/weak_symbols/main.c @@ -1,23 +0,0 @@ -#include "dylib.h" -#include - -int -doSomething() -{ - // Set a breakpoint here. - if (&absent_weak_int != NULL) - printf("In absent_weak_int: %d\n", absent_weak_int); - if (absent_weak_function != NULL) - printf("In absent_weak_func: %p\n", absent_weak_function); - if (&present_weak_int != NULL) - printf("In present_weak_int: %d\n", present_weak_int); - if (present_weak_function != NULL) - printf("In present_weak_func: %p\n", present_weak_function); - -} - -int -main() -{ - return doSomething(); -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/weak_symbols/module.modulemap =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/weak_symbols/module.modulemap +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/weak_symbols/module.modulemap @@ -1,3 +0,0 @@ -module Dylib { - header "dylib.h" -} Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/xvalue/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/xvalue/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/xvalue/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/xvalue/TestXValuePrinting.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/xvalue/TestXValuePrinting.py +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/xvalue/TestXValuePrinting.py @@ -1,37 +0,0 @@ -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class ExprXValuePrintingTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - - self.main_source = "main.cpp" - self.main_source_spec = lldb.SBFileSpec(self.main_source) - - def do_test(self, dictionary=None): - """Printing an xvalue should work.""" - self.build(dictionary=dictionary) - - (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, - '// Break here', self.main_source_spec) - frame = thread.GetFrameAtIndex(0) - - value = frame.EvaluateExpression("foo().data") - self.assertTrue(value.IsValid()) - self.assertTrue(value.GetError().Success()) - self.assertEqual(value.GetValueAsSigned(), 1234) - - @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765") - def test(self): - self.do_test() - Index: lldb/trunk/packages/Python/lldbsuite/test/expression_command/xvalue/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/xvalue/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/xvalue/main.cpp @@ -1,12 +0,0 @@ -struct Tmp -{ - int data = 1234; -}; - -Tmp foo() { return Tmp(); } - -int main(int argc, char const *argv[]) -{ - int something = foo().data; - return 0; // Break here -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/apropos/TestApropos.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/apropos/TestApropos.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/apropos/TestApropos.py @@ -1,29 +0,0 @@ -import lldb -from lldbsuite.test.lldbtest import * -from lldbsuite.test.decorators import * - -class AproposTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - TestBase.setUp(self) - - @no_debug_info_test - def test_apropos(self): - self.expect("apropos", error=True, - substrs=[' must be called with exactly one argument']) - self.expect("apropos a b", error=True, - substrs=[' must be called with exactly one argument']) - self.expect("apropos ''", error=True, - substrs=['\'\' is not a valid search word']) - - @no_debug_info_test - def test_apropos_variable(self): - """Test that 'apropos variable' prints the fully qualified command name""" - self.expect( - 'apropos variable', - substrs=[ - 'frame variable', - 'target variable', - 'watchpoint set variable']) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/apropos_with_process/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/apropos_with_process/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/apropos_with_process/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/apropos_with_process/TestAproposWithProcess.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/apropos_with_process/TestAproposWithProcess.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/apropos_with_process/TestAproposWithProcess.py @@ -1,43 +0,0 @@ -""" -Test that apropos env doesn't crash trying to touch the process plugin command -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil - - -class AproposWithProcessTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to break inside main(). - self.line = line_number('main.cpp', '// break here') - - def test_apropos_with_process(self): - """Test that apropos env doesn't crash trying to touch the process plugin command.""" - self.build() - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # Break in main() after the variables are assigned values. - 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) - - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', 'stop reason = breakpoint']) - - # The breakpoint should have a hit count of 1. - self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, - substrs=[' resolved, hit count = 1']) - - self.runCmd('apropos env') Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/apropos_with_process/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/apropos_with_process/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/apropos_with_process/main.cpp @@ -1,14 +0,0 @@ -//===-- main.cpp ------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -#include - -int main (int argc, char const *argv[]) -{ - return 0; // break here -} - Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/attach_resume/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/attach_resume/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/attach_resume/Makefile @@ -1,7 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp -ENABLE_THREADS := YES -EXE := AttachResume - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/attach_resume/TestAttachResume.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/attach_resume/TestAttachResume.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/attach_resume/TestAttachResume.py @@ -1,93 +0,0 @@ -""" -Test process attach/resume. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -exe_name = "AttachResume" # Must match Makefile - - -class AttachResumeTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @skipIfRemote - @expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr19310') - @expectedFailureNetBSD - @skipIfWindows # llvm.org/pr24778, llvm.org/pr21753 - def test_attach_continue_interrupt_detach(self): - """Test attach/continue/interrupt/detach""" - self.build() - self.process_attach_continue_interrupt_detach() - - def process_attach_continue_interrupt_detach(self): - """Test attach/continue/interrupt/detach""" - - exe = self.getBuildArtifact(exe_name) - - popen = self.spawnSubprocess(exe) - self.addTearDownHook(self.cleanupSubprocesses) - - self.runCmd("process attach -p " + str(popen.pid)) - - self.setAsync(True) - listener = self.dbg.GetListener() - process = self.dbg.GetSelectedTarget().GetProcess() - - self.runCmd("c") - lldbutil.expect_state_changes( - self, listener, process, [ - lldb.eStateRunning]) - - self.runCmd("process interrupt") - lldbutil.expect_state_changes( - self, listener, process, [ - lldb.eStateStopped]) - - # be sure to continue/interrupt/continue (r204504) - self.runCmd("c") - lldbutil.expect_state_changes( - self, listener, process, [ - lldb.eStateRunning]) - - self.runCmd("process interrupt") - lldbutil.expect_state_changes( - self, listener, process, [ - lldb.eStateStopped]) - - # Second interrupt should have no effect. - self.expect( - "process interrupt", - patterns=["Process is not running"], - error=True) - - # check that this breakpoint is auto-cleared on detach (r204752) - self.runCmd("br set -f main.cpp -l %u" % - (line_number('main.cpp', '// Set breakpoint here'))) - - self.runCmd("c") - lldbutil.expect_state_changes( - self, listener, process, [ - lldb.eStateRunning, lldb.eStateStopped]) - self.expect('br list', 'Breakpoint not hit', - substrs=['hit count = 1']) - - # Make sure the breakpoint is not hit again. - self.expect("expr debugger_flag = false", substrs=[" = false"]) - - self.runCmd("c") - lldbutil.expect_state_changes( - self, listener, process, [ - lldb.eStateRunning]) - - # make sure to detach while in running state (r204759) - self.runCmd("detach") - lldbutil.expect_state_changes( - self, listener, process, [ - lldb.eStateDetached]) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/attach_resume/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/attach_resume/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/attach_resume/main.cpp @@ -1,35 +0,0 @@ -#include -#include - -#include -#include - -volatile bool debugger_flag = true; // The debugger will flip this to false - -void *start(void *data) -{ - int i; - size_t idx = (size_t)data; - for (i=0; i<30; i++) - { - if ( idx == 0 && debugger_flag) - std::this_thread::sleep_for(std::chrono::microseconds(1)); // Set breakpoint here - std::this_thread::sleep_for(std::chrono::seconds(1)); - } - return 0; -} - -int main(int argc, char const *argv[]) -{ - lldb_enable_attach(); - - static const size_t nthreads = 16; - std::thread threads[nthreads]; - size_t i; - - for (i=0; i= 1, - VALID_BREAKPOINT) - - # Get the breakpoint location from breakpoint after we verified that, - # indeed, it has one location. - location = breakpoint.GetLocationAtIndex(0) - self.assertTrue(location and - location.IsEnabled(), - VALID_BREAKPOINT_LOCATION) - - # Next get the address from the location, and create an address breakpoint using - # that address: - - address = location.GetAddress() - target.BreakpointDelete(breakpoint.GetID()) - - breakpoint = target.BreakpointCreateBySBAddress(address) - - # Disable ASLR. This will allow us to actually test (on platforms that support this flag) - # that the breakpoint was able to track the module. - - launch_info = lldb.SBLaunchInfo(None) - flags = launch_info.GetLaunchFlags() - flags &= ~lldb.eLaunchFlagDisableASLR - launch_info.SetLaunchFlags(flags) - - error = lldb.SBError() - - process = target.Launch(launch_info, error) - self.assertTrue(process, PROCESS_IS_VALID) - - # Did we hit our breakpoint? - from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint - threads = get_threads_stopped_at_breakpoint(process, breakpoint) - self.assertTrue( - len(threads) == 1, - "There should be a thread stopped at our breakpoint") - - # The hit count for the breakpoint should be 1. - self.assertTrue(breakpoint.GetHitCount() == 1) - - process.Kill() - - # Now re-launch and see that we hit the breakpoint again: - launch_info.Clear() - launch_info.SetLaunchFlags(flags) - - process = target.Launch(launch_info, error) - self.assertTrue(process, PROCESS_IS_VALID) - - thread = get_threads_stopped_at_breakpoint(process, breakpoint) - self.assertTrue( - len(threads) == 1, - "There should be a thread stopped at our breakpoint") - - # The hit count for the breakpoint should now be 2. - self.assertTrue(breakpoint.GetHitCount() == 2) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/address_breakpoints/TestBadAddressBreakpoints.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/address_breakpoints/TestBadAddressBreakpoints.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/address_breakpoints/TestBadAddressBreakpoints.py @@ -1,47 +0,0 @@ -""" -Test that breakpoints set on a bad address say they are bad. -""" - -from __future__ import print_function - - -import lldb -import lldbsuite.test.lldbutil as lldbutil -from lldbsuite.test.lldbtest import * - - -class BadAddressBreakpointTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - NO_DEBUG_INFO_TESTCASE = True - - def test_bad_address_breakpoints(self): - """Test that breakpoints set on a bad address say they are bad.""" - self.build() - self.address_breakpoints() - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - - def address_breakpoints(self): - """Test that breakpoints set on a bad address say they are bad.""" - target, process, thread, bkpt = \ - lldbutil.run_to_source_breakpoint(self, - "Set a breakpoint here", - lldb.SBFileSpec("main.c")) - - # Now see if we can read from 0. If I can't do that, I don't - # have a good way to know what an illegal address is... - error = lldb.SBError() - - ptr = process.ReadPointerFromMemory(0x0, error) - - if not error.Success(): - bkpt = target.BreakpointCreateByAddress(0x0) - for bp_loc in bkpt: - self.assertTrue(bp_loc.IsResolved() == False) - else: - self.fail( - "Could not find an illegal address at which to set a bad breakpoint.") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/address_breakpoints/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/address_breakpoints/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/address_breakpoints/main.c @@ -1,8 +0,0 @@ -#include - -int -main() -{ - printf ("Set a breakpoint here.\n"); - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/auto_continue/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/auto_continue/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/auto_continue/Makefile @@ -1,6 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c -CFLAGS_EXTRAS += -std=c99 - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/auto_continue/TestBreakpointAutoContinue.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/auto_continue/TestBreakpointAutoContinue.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/auto_continue/TestBreakpointAutoContinue.py @@ -1,101 +0,0 @@ -""" -Test that the breakpoint auto-continue flag works correctly. -""" - -from __future__ import print_function - - -import lldb -import lldbsuite.test.lldbutil as lldbutil -from lldbsuite.test.lldbtest import * - - -class BreakpointAutoContinue(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - NO_DEBUG_INFO_TESTCASE = True - - def test_breakpoint_auto_continue(self): - """Make sure the auto continue continues with no other complications""" - self.build() - self.simple_auto_continue() - - def test_auto_continue_with_command(self): - """Add a command, make sure the command gets run""" - self.build() - self.auto_continue_with_command() - - def test_auto_continue_on_location(self): - """Set auto-continue on a location and make sure only that location continues""" - self.build() - self.auto_continue_location() - - def make_target_and_bkpt(self, additional_options=None, num_expected_loc=1, - pattern="Set a breakpoint here"): - exe = self.getBuildArtifact("a.out") - self.target = self.dbg.CreateTarget(exe) - self.assertTrue(self.target.IsValid(), "Target is not valid") - - extra_options_txt = "--auto-continue 1 " - if additional_options: - extra_options_txt += additional_options - bpno = lldbutil.run_break_set_by_source_regexp(self, pattern, - extra_options = extra_options_txt, - num_expected_locations = num_expected_loc) - return bpno - - def launch_it (self, expected_state): - error = lldb.SBError() - launch_info = lldb.SBLaunchInfo(None) - launch_info.SetWorkingDirectory(self.get_process_working_directory()) - - process = self.target.Launch(launch_info, error) - self.assertTrue(error.Success(), "Launch failed.") - - state = process.GetState() - self.assertEqual(state, expected_state, "Didn't get expected state") - - return process - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - - def simple_auto_continue(self): - bpno = self.make_target_and_bkpt() - process = self.launch_it(lldb.eStateExited) - - bkpt = self.target.FindBreakpointByID(bpno) - self.assertEqual(bkpt.GetHitCount(), 2, "Should have run through the breakpoint twice") - - def auto_continue_with_command(self): - bpno = self.make_target_and_bkpt("-N BKPT -C 'break modify --auto-continue 0 BKPT'") - process = self.launch_it(lldb.eStateStopped) - state = process.GetState() - self.assertEqual(state, lldb.eStateStopped, "Process should be stopped") - bkpt = self.target.FindBreakpointByID(bpno) - threads = lldbutil.get_threads_stopped_at_breakpoint(process, bkpt) - self.assertEqual(len(threads), 1, "There was a thread stopped at our breakpoint") - self.assertEqual(bkpt.GetHitCount(), 2, "Should have hit the breakpoint twice") - - def auto_continue_location(self): - bpno = self.make_target_and_bkpt(pattern="Set a[^ ]* breakpoint here", num_expected_loc=2) - bkpt = self.target.FindBreakpointByID(bpno) - bkpt.SetAutoContinue(False) - - loc = lldb.SBBreakpointLocation() - for i in range(0,2): - func_name = bkpt.location[i].GetAddress().function.name - if func_name == "main": - loc = bkpt.location[i] - - self.assertTrue(loc.IsValid(), "Didn't find a location in main") - loc.SetAutoContinue(True) - - process = self.launch_it(lldb.eStateStopped) - - threads = lldbutil.get_threads_stopped_at_breakpoint(process, bkpt) - self.assertEqual(len(threads), 1, "Didn't get one thread stopped at our breakpoint") - func_name = threads[0].frame[0].function.name - self.assertEqual(func_name, "call_me") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/auto_continue/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/auto_continue/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/auto_continue/main.c @@ -1,19 +0,0 @@ -#include - -void -call_me() -{ - printf("Set another breakpoint here.\n"); -} - -int -main() -{ - int change_me = 0; - for (int i = 0; i < 2; i++) - { - printf ("Set a breakpoint here: %d with: %d.\n", i, change_me); - } - call_me(); - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_by_line_and_column/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_by_line_and_column/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_by_line_and_column/Makefile @@ -1,6 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c -CFLAGS_EXTRAS += -std=c99 -gcolumn-info - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_by_line_and_column/TestBreakpointByLineAndColumn.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_by_line_and_column/TestBreakpointByLineAndColumn.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_by_line_and_column/TestBreakpointByLineAndColumn.py @@ -1,45 +0,0 @@ -""" -Test setting a breakpoint by line and column. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class BreakpointByLineAndColumnTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - ## Skip gcc version less 7.1 since it doesn't support -gcolumn-info - @skipIf(compiler="gcc", compiler_version=['<', '7.1']) - def testBreakpointByLineAndColumn(self): - self.build() - main_c = lldb.SBFileSpec("main.c") - _, _, _, breakpoint = lldbutil.run_to_line_breakpoint(self, - main_c, 19, 50) - self.expect("fr v did_call", substrs='1') - in_then = False - for i in range(breakpoint.GetNumLocations()): - b_loc = breakpoint.GetLocationAtIndex(i).GetAddress().GetLineEntry() - self.assertEqual(b_loc.GetLine(), 19) - in_then |= b_loc.GetColumn() == 50 - self.assertTrue(in_then) - - ## Skip gcc version less 7.1 since it doesn't support -gcolumn-info - @skipIf(compiler="gcc", compiler_version=['<', '7.1']) - def testBreakpointByLine(self): - self.build() - main_c = lldb.SBFileSpec("main.c") - _, _, _, breakpoint = lldbutil.run_to_line_breakpoint(self, main_c, 19) - self.expect("fr v did_call", substrs='0') - in_condition = False - for i in range(breakpoint.GetNumLocations()): - b_loc = breakpoint.GetLocationAtIndex(i).GetAddress().GetLineEntry() - self.assertEqual(b_loc.GetLine(), 19) - in_condition |= b_loc.GetColumn() < 30 - self.assertTrue(in_condition) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_by_line_and_column/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_by_line_and_column/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_by_line_and_column/main.c @@ -1,22 +0,0 @@ -//===-- main.c --------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -int square(int x) -{ - return x * x; -} - -int main (int argc, char const *argv[]) -{ - int did_call = 0; - - // Line 20. v Column 50. - if(square(argc+1) != 0) { did_call = 1; return square(argc); } - // ^ - return square(0); -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c a.c b.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py @@ -1,285 +0,0 @@ -""" -Test lldb breakpoint command add/list/delete. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil -import side_effect - - -class BreakpointCommandTestCase(TestBase): - - NO_DEBUG_INFO_TESTCASE = True - mydir = TestBase.compute_mydir(__file__) - - @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24528") - def test_breakpoint_command_sequence(self): - """Test a sequence of breakpoint command add, list, and delete.""" - self.build() - self.breakpoint_command_sequence() - - def test_script_parameters(self): - """Test a sequence of breakpoint command add, list, and delete.""" - self.build() - self.breakpoint_command_script_parameters() - - def test_commands_on_creation(self): - self.build() - self.breakpoint_commands_on_creation() - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to break inside main(). - self.line = line_number('main.c', '// Set break point at this line.') - # disable "There is a running process, kill it and restart?" prompt - self.runCmd("settings set auto-confirm true") - self.addTearDownHook( - lambda: self.runCmd("settings clear auto-confirm")) - - def test_delete_all_breakpoints(self): - """Test that deleting all breakpoints works.""" - self.build() - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - lldbutil.run_break_set_by_symbol(self, "main") - lldbutil.run_break_set_by_file_and_line( - self, "main.c", self.line, num_expected_locations=1, loc_exact=True) - - self.runCmd("run", RUN_SUCCEEDED) - - self.runCmd("breakpoint delete") - self.runCmd("process continue") - self.expect("process status", PROCESS_STOPPED, - patterns=['Process .* exited with status = 0']) - - - def breakpoint_command_sequence(self): - """Test a sequence of breakpoint command add, list, and delete.""" - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # Add three breakpoints on the same line. The first time we don't specify the file, - # since the default file is the one containing main: - lldbutil.run_break_set_by_file_and_line( - self, None, self.line, num_expected_locations=1, loc_exact=True) - lldbutil.run_break_set_by_file_and_line( - self, "main.c", self.line, num_expected_locations=1, loc_exact=True) - lldbutil.run_break_set_by_file_and_line( - self, "main.c", self.line, num_expected_locations=1, loc_exact=True) - # Breakpoint 4 - set at the same location as breakpoint 1 to test - # setting breakpoint commands on two breakpoints at a time - lldbutil.run_break_set_by_file_and_line( - self, None, self.line, num_expected_locations=1, loc_exact=True) - # Make sure relative path source breakpoints work as expected. We test - # with partial paths with and without "./" prefixes. - lldbutil.run_break_set_by_file_and_line( - self, "./main.c", self.line, - num_expected_locations=1, loc_exact=True) - lldbutil.run_break_set_by_file_and_line( - self, "breakpoint_command/main.c", self.line, - num_expected_locations=1, loc_exact=True) - lldbutil.run_break_set_by_file_and_line( - self, "./breakpoint_command/main.c", self.line, - num_expected_locations=1, loc_exact=True) - lldbutil.run_break_set_by_file_and_line( - self, "breakpoint/breakpoint_command/main.c", self.line, - num_expected_locations=1, loc_exact=True) - lldbutil.run_break_set_by_file_and_line( - self, "./breakpoint/breakpoint_command/main.c", self.line, - num_expected_locations=1, loc_exact=True) - # Test relative breakpoints with incorrect paths and make sure we get - # no breakpoint locations - lldbutil.run_break_set_by_file_and_line( - self, "invalid/main.c", self.line, - num_expected_locations=0, loc_exact=True) - lldbutil.run_break_set_by_file_and_line( - self, "./invalid/main.c", self.line, - num_expected_locations=0, loc_exact=True) - # Now add callbacks for the breakpoints just created. - self.runCmd( - "breakpoint command add -s command -o 'frame variable --show-types --scope' 1 4") - self.runCmd( - "breakpoint command add -s python -o 'import side_effect; side_effect.one_liner = \"one liner was here\"' 2") - self.runCmd( - "breakpoint command add --python-function bktptcmd.function 3") - - # Check that the breakpoint commands are correctly set. - - # The breakpoint list now only contains breakpoint 1. - self.expect( - "breakpoint list", "Breakpoints 1 & 2 created", substrs=[ - "2: file = 'main.c', line = %d, exact_match = 0, locations = 1" % - self.line], patterns=[ - "1: file = '.*main.c', line = %d, exact_match = 0, locations = 1" % - self.line]) - - self.expect( - "breakpoint list -f", - "Breakpoints 1 & 2 created", - substrs=[ - "2: file = 'main.c', line = %d, exact_match = 0, locations = 1" % - self.line], - patterns=[ - "1: file = '.*main.c', line = %d, exact_match = 0, locations = 1" % - self.line, - "1.1: .+at main.c:%d:?[0-9]*, .+unresolved, hit count = 0" % - self.line, - "2.1: .+at main.c:%d:?[0-9]*, .+unresolved, hit count = 0" % - self.line]) - - self.expect("breakpoint command list 1", "Breakpoint 1 command ok", - substrs=["Breakpoint commands:", - "frame variable --show-types --scope"]) - self.expect("breakpoint command list 2", "Breakpoint 2 command ok", - substrs=["Breakpoint commands (Python):", - "import side_effect", - "side_effect.one_liner"]) - self.expect("breakpoint command list 3", "Breakpoint 3 command ok", - substrs=["Breakpoint commands (Python):", - "bktptcmd.function(frame, bp_loc, internal_dict)"]) - - self.expect("breakpoint command list 4", "Breakpoint 4 command ok", - substrs=["Breakpoint commands:", - "frame variable --show-types --scope"]) - - self.runCmd("breakpoint delete 4") - - self.runCmd("command script import --allow-reload ./bktptcmd.py") - - # Next lets try some other breakpoint kinds. First break with a regular expression - # and then specify only one file. The first time we should get two locations, - # the second time only one: - - lldbutil.run_break_set_by_regexp( - self, r"._MyFunction", num_expected_locations=2) - - lldbutil.run_break_set_by_regexp( - self, - r"._MyFunction", - extra_options="-f a.c", - num_expected_locations=1) - - lldbutil.run_break_set_by_regexp( - self, - r"._MyFunction", - extra_options="-f a.c -f b.c", - num_expected_locations=2) - - # Now try a source regex breakpoint: - lldbutil.run_break_set_by_source_regexp( - self, - r"is about to return [12]0", - extra_options="-f a.c -f b.c", - num_expected_locations=2) - - lldbutil.run_break_set_by_source_regexp( - self, - r"is about to return [12]0", - extra_options="-f a.c", - num_expected_locations=1) - - # Reset our canary variables and run the program. - side_effect.one_liner = None - side_effect.bktptcmd = None - self.runCmd("run", RUN_SUCCEEDED) - - # Check the value of canary variables. - self.assertEquals("one liner was here", side_effect.one_liner) - self.assertEquals("function was here", side_effect.bktptcmd) - - # Finish the program. - self.runCmd("process continue") - - # Remove the breakpoint command associated with breakpoint 1. - self.runCmd("breakpoint command delete 1") - - # Remove breakpoint 2. - self.runCmd("breakpoint delete 2") - - self.expect( - "breakpoint command list 1", - startstr="Breakpoint 1 does not have an associated command.") - self.expect( - "breakpoint command list 2", - error=True, - startstr="error: '2' is not a currently valid breakpoint ID.") - - # The breakpoint list now only contains breakpoint 1. - self.expect( - "breakpoint list -f", - "Breakpoint 1 exists", - patterns=[ - "1: file = '.*main.c', line = %d, exact_match = 0, locations = 1, resolved = 1" % - self.line, - "hit count = 1"]) - - # Not breakpoint 2. - self.expect( - "breakpoint list -f", - "No more breakpoint 2", - matching=False, - substrs=[ - "2: file = 'main.c', line = %d, exact_match = 0, locations = 1, resolved = 1" % - self.line]) - - # Run the program again, with breakpoint 1 remaining. - self.runCmd("run", RUN_SUCCEEDED) - - # We should be stopped again due to breakpoint 1. - - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', - 'stop reason = breakpoint']) - - # The breakpoint should have a hit count of 2. - self.expect("breakpoint list -f", BREAKPOINT_HIT_TWICE, - substrs=['resolved, hit count = 2']) - - def breakpoint_command_script_parameters(self): - """Test that the frame and breakpoint location are being properly passed to the script breakpoint command function.""" - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # Add a breakpoint. - lldbutil.run_break_set_by_file_and_line( - self, "main.c", self.line, num_expected_locations=1, loc_exact=True) - - # Now add callbacks for the breakpoints just created. - self.runCmd("breakpoint command add -s python -o 'import side_effect; side_effect.frame = str(frame); side_effect.bp_loc = str(bp_loc)' 1") - - # Reset canary variables and run. - side_effect.frame = None - side_effect.bp_loc = None - self.runCmd("run", RUN_SUCCEEDED) - - self.expect(side_effect.frame, exe=False, startstr="frame #0:") - self.expect(side_effect.bp_loc, exe=False, - patterns=["1.* where = .*main .* resolved, hit count = 1"]) - - def breakpoint_commands_on_creation(self): - """Test that setting breakpoint commands when creating the breakpoint works""" - exe = self.getBuildArtifact("a.out") - target = self.dbg.CreateTarget(exe) - self.assertTrue(target.IsValid(), "Created an invalid target.") - - # Add a breakpoint. - lldbutil.run_break_set_by_file_and_line( - self, "main.c", self.line, num_expected_locations=1, loc_exact=True, - extra_options='-C bt -C "thread list" -C continue') - - bkpt = target.FindBreakpointByID(1) - self.assertTrue(bkpt.IsValid(), "Couldn't find breakpoint 1") - com_list = lldb.SBStringList() - bkpt.GetCommandLineCommands(com_list) - self.assertEqual(com_list.GetSize(), 3, "Got the wrong number of commands") - self.assertEqual(com_list.GetStringAtIndex(0), "bt", "First bt") - self.assertEqual(com_list.GetStringAtIndex(1), "thread list", "Next thread list") - self.assertEqual(com_list.GetStringAtIndex(2), "continue", "Last continue") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommandsFromPython.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommandsFromPython.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommandsFromPython.py @@ -1,99 +0,0 @@ -""" -Test that you can set breakpoint commands successfully with the Python API's: -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil -import side_effect - - -class PythonBreakpointCommandSettingTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - NO_DEBUG_INFO_TESTCASE = True - - @add_test_categories(['pyapi']) - def test_step_out_python(self): - """Test stepping out using avoid-no-debug with dsyms.""" - self.build() - self.do_set_python_command_from_python() - - def setUp(self): - TestBase.setUp(self) - self.main_source = "main.c" - self.main_source_spec = lldb.SBFileSpec(self.main_source) - - def do_set_python_command_from_python(self): - exe = self.getBuildArtifact("a.out") - error = lldb.SBError() - - self.target = self.dbg.CreateTarget(exe) - self.assertTrue(self.target, VALID_TARGET) - - body_bkpt = self.target.BreakpointCreateBySourceRegex( - "Set break point at this line.", self.main_source_spec) - self.assertTrue(body_bkpt, VALID_BREAKPOINT) - - func_bkpt = self.target.BreakpointCreateBySourceRegex( - "Set break point at this line.", self.main_source_spec) - self.assertTrue(func_bkpt, VALID_BREAKPOINT) - - # Also test that setting a source regex breakpoint with an empty file - # spec list sets it on all files: - no_files_bkpt = self.target.BreakpointCreateBySourceRegex( - "Set a breakpoint here", lldb.SBFileSpecList(), lldb.SBFileSpecList()) - self.assertTrue(no_files_bkpt, VALID_BREAKPOINT) - num_locations = no_files_bkpt.GetNumLocations() - self.assertTrue( - num_locations >= 2, - "Got at least two breakpoint locations") - got_one_in_A = False - got_one_in_B = False - for idx in range(0, num_locations): - comp_unit = no_files_bkpt.GetLocationAtIndex(idx).GetAddress().GetSymbolContext( - lldb.eSymbolContextCompUnit).GetCompileUnit().GetFileSpec() - print("Got comp unit: ", comp_unit.GetFilename()) - if comp_unit.GetFilename() == "a.c": - got_one_in_A = True - elif comp_unit.GetFilename() == "b.c": - got_one_in_B = True - - self.assertTrue(got_one_in_A, "Failed to match the pattern in A") - self.assertTrue(got_one_in_B, "Failed to match the pattern in B") - self.target.BreakpointDelete(no_files_bkpt.GetID()) - - error = lldb.SBError() - error = body_bkpt.SetScriptCallbackBody( - "import side_effect; side_effect.callback = 'callback was here'") - self.assertTrue( - error.Success(), - "Failed to set the script callback body: %s." % - (error.GetCString())) - - self.dbg.HandleCommand( - "command script import --allow-reload ./bktptcmd.py") - func_bkpt.SetScriptCallbackFunction("bktptcmd.function") - - # Clear out canary variables - side_effect.bktptcmd = None - side_effect.callback = None - - # Now launch the process, and do not stop at entry point. - self.process = self.target.LaunchSimple( - None, None, self.get_process_working_directory()) - - self.assertTrue(self.process, PROCESS_IS_VALID) - - # Now finish, and make sure the return value is correct. - threads = lldbutil.get_threads_stopped_at_breakpoint( - self.process, body_bkpt) - self.assertTrue(len(threads) == 1, "Stopped at inner breakpoint.") - self.thread = threads[0] - - self.assertEquals("callback was here", side_effect.callback) - self.assertEquals("function was here", side_effect.bktptcmd) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestRegexpBreakCommand.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestRegexpBreakCommand.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestRegexpBreakCommand.py @@ -1,71 +0,0 @@ -""" -Test _regexp-break command which uses regular expression matching to dispatch to other built in breakpoint commands. -""" - -from __future__ import print_function - - -import os -import lldb -from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil - - -class RegexpBreakCommandTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def test(self): - """Test _regexp-break command.""" - self.build() - self.regexp_break_command() - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to break inside main(). - self.source = 'main.c' - self.line = line_number( - self.source, '// Set break point at this line.') - - def regexp_break_command(self): - """Test the super consie "b" command, which is analias for _regexp-break.""" - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - break_results = lldbutil.run_break_set_command( - self, "b %d" % - self.line) - lldbutil.check_breakpoint_result( - self, - break_results, - file_name='main.c', - line_number=self.line, - num_locations=1) - - break_results = lldbutil.run_break_set_command( - self, "b %s:%d" % (self.source, self.line)) - lldbutil.check_breakpoint_result( - self, - break_results, - file_name='main.c', - line_number=self.line, - num_locations=1) - - # Check breakpoint with full file path. - full_path = os.path.join(self.getSourceDir(), self.source) - break_results = lldbutil.run_break_set_command( - self, "b %s:%d" % (full_path, self.line)) - lldbutil.check_breakpoint_result( - self, - break_results, - file_name='main.c', - line_number=self.line, - num_locations=1) - - 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']) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/a.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/a.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/a.c @@ -1,9 +0,0 @@ -#include - -int -a_MyFunction () -{ - // Set a breakpoint here. - printf ("a is about to return 10.\n"); - return 10; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/b.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/b.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/b.c @@ -1,9 +0,0 @@ -#include - -int -b_MyFunction () -{ - // Set a breakpoint here. - printf ("b is about to return 20.\n"); - return 20; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/bktptcmd.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/bktptcmd.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/bktptcmd.py @@ -1,5 +0,0 @@ -from __future__ import print_function -import side_effect - -def function(frame, bp_loc, dict): - side_effect.bktptcmd = "function was here" Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/main.c @@ -1,16 +0,0 @@ -//===-- main.c --------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -int main (int argc, char const *argv[]) -{ - // Add a body to the function, so we can set more than one - // breakpoint in it. - static volatile int var = 0; - var++; - return 0; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/side_effect.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/side_effect.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/side_effect.py @@ -1,5 +0,0 @@ -""" -A dummy module for testing the execution of various breakpoint commands. A -command will modify a global variable in this module and test will check its -value. -""" Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_conditions/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_conditions/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_conditions/Makefile @@ -1,6 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c -CFLAGS_EXTRAS += -std=c99 - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py @@ -1,226 +0,0 @@ -""" -Test breakpoint conditions with 'breakpoint modify -c id'. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class BreakpointConditionsTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def test_breakpoint_condition_and_run_command(self): - """Exercise breakpoint condition with 'breakpoint modify -c id'.""" - self.build() - self.breakpoint_conditions() - - def test_breakpoint_condition_inline_and_run_command(self): - """Exercise breakpoint condition inline with 'breakpoint set'.""" - self.build() - self.breakpoint_conditions(inline=True) - - @add_test_categories(['pyapi']) - def test_breakpoint_condition_and_python_api(self): - """Use Python APIs to set breakpoint conditions.""" - self.build() - self.breakpoint_conditions_python() - - @add_test_categories(['pyapi']) - def test_breakpoint_invalid_condition_and_python_api(self): - """Use Python APIs to set breakpoint conditions.""" - self.build() - self.breakpoint_invalid_conditions_python() - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to of function 'c'. - self.line1 = line_number( - 'main.c', '// Find the line number of function "c" here.') - self.line2 = line_number( - 'main.c', "// Find the line number of c's parent call here.") - - def breakpoint_conditions(self, inline=False): - """Exercise breakpoint condition with 'breakpoint modify -c id'.""" - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - if inline: - # Create a breakpoint by function name 'c' and set the condition. - lldbutil.run_break_set_by_symbol( - self, - "c", - extra_options="-c 'val == 3'", - num_expected_locations=1, - sym_exact=True) - else: - # Create a breakpoint by function name 'c'. - lldbutil.run_break_set_by_symbol( - self, "c", num_expected_locations=1, sym_exact=True) - - # And set a condition on the breakpoint to stop on when 'val == 3'. - self.runCmd("breakpoint modify -c 'val == 3' 1") - - # Now run the program. - self.runCmd("run", RUN_SUCCEEDED) - - # The process should be stopped at this point. - self.expect("process status", PROCESS_STOPPED, - patterns=['Process .* stopped']) - - # 'frame variable --show-types val' should return 3 due to breakpoint condition. - self.expect( - "frame variable --show-types val", - VARIABLES_DISPLAYED_CORRECTLY, - startstr='(int) val = 3') - - # Also check the hit count, which should be 3, by design. - self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, - substrs=["resolved = 1", - "Condition: val == 3", - "hit count = 1"]) - - # The frame #0 should correspond to main.c:36, the executable statement - # in function name 'c'. And the parent frame should point to - # main.c:24. - self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT_CONDITION, - #substrs = ["stop reason = breakpoint"], - patterns=["frame #0.*main.c:%d" % self.line1, - "frame #1.*main.c:%d" % self.line2]) - - # Test that "breakpoint modify -c ''" clears the condition for the last - # created breakpoint, so that when the breakpoint hits, val == 1. - self.runCmd("process kill") - self.runCmd("breakpoint modify -c ''") - self.expect( - "breakpoint list -f", - BREAKPOINT_STATE_CORRECT, - matching=False, - substrs=["Condition:"]) - - # Now run the program again. - self.runCmd("run", RUN_SUCCEEDED) - - # The process should be stopped at this point. - self.expect("process status", PROCESS_STOPPED, - patterns=['Process .* stopped']) - - # 'frame variable --show-types val' should return 1 since it is the first breakpoint hit. - self.expect( - "frame variable --show-types val", - VARIABLES_DISPLAYED_CORRECTLY, - startstr='(int) val = 1') - - self.runCmd("process kill") - - def breakpoint_conditions_python(self): - """Use Python APIs to set breakpoint conditions.""" - exe = self.getBuildArtifact("a.out") - - # Create a target by the debugger. - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, VALID_TARGET) - - # Now create a breakpoint on main.c by name 'c'. - breakpoint = target.BreakpointCreateByName('c', 'a.out') - #print("breakpoint:", breakpoint) - self.assertTrue(breakpoint and - breakpoint.GetNumLocations() == 1, - VALID_BREAKPOINT) - - # We didn't associate a thread index with the breakpoint, so it should - # be invalid. - self.assertTrue(breakpoint.GetThreadIndex() == lldb.UINT32_MAX, - "The thread index should be invalid") - # The thread name should be invalid, too. - self.assertTrue(breakpoint.GetThreadName() is None, - "The thread name should be invalid") - - # Let's set the thread index for this breakpoint and verify that it is, - # indeed, being set correctly. - # There's only one thread for the process. - breakpoint.SetThreadIndex(1) - self.assertTrue(breakpoint.GetThreadIndex() == 1, - "The thread index has been set correctly") - - # Get the breakpoint location from breakpoint after we verified that, - # indeed, it has one location. - location = breakpoint.GetLocationAtIndex(0) - self.assertTrue(location and - location.IsEnabled(), - VALID_BREAKPOINT_LOCATION) - - # Set the condition on the breakpoint location. - location.SetCondition('val == 3') - self.expect(location.GetCondition(), exe=False, - startstr='val == 3') - - # Now launch the process, and do not stop at entry point. - process = target.LaunchSimple( - None, None, self.get_process_working_directory()) - self.assertTrue(process, PROCESS_IS_VALID) - - # Frame #0 should be on self.line1 and the break condition should hold. - from lldbsuite.test.lldbutil import get_stopped_thread - thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) - self.assertTrue( - thread.IsValid(), - "There should be a thread stopped due to breakpoint condition") - frame0 = thread.GetFrameAtIndex(0) - var = frame0.FindValue('val', lldb.eValueTypeVariableArgument) - self.assertTrue(frame0.GetLineEntry().GetLine() == self.line1 and - var.GetValue() == '3') - - # The hit count for the breakpoint should be 1. - self.assertTrue(breakpoint.GetHitCount() == 1) - - # Test that the condition expression didn't create a result variable: - options = lldb.SBExpressionOptions() - value = frame0.EvaluateExpression("$0", options) - self.assertTrue(value.GetError().Fail(), - "Conditions should not make result variables.") - process.Continue() - - def breakpoint_invalid_conditions_python(self): - """Use Python APIs to set breakpoint conditions.""" - exe = self.getBuildArtifact("a.out") - - # Create a target by the debugger. - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, VALID_TARGET) - - # Now create a breakpoint on main.c by name 'c'. - breakpoint = target.BreakpointCreateByName('c', 'a.out') - #print("breakpoint:", breakpoint) - self.assertTrue(breakpoint and - breakpoint.GetNumLocations() == 1, - VALID_BREAKPOINT) - - # Set the condition on the breakpoint. - breakpoint.SetCondition('no_such_variable == not_this_one_either') - self.expect(breakpoint.GetCondition(), exe=False, - startstr='no_such_variable == not_this_one_either') - - # Now launch the process, and do not stop at entry point. - process = target.LaunchSimple( - None, None, self.get_process_working_directory()) - self.assertTrue(process, PROCESS_IS_VALID) - - # Frame #0 should be on self.line1 and the break condition should hold. - from lldbsuite.test.lldbutil import get_stopped_thread - thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) - self.assertTrue( - thread.IsValid(), - "There should be a thread stopped due to breakpoint condition") - frame0 = thread.GetFrameAtIndex(0) - var = frame0.FindValue('val', lldb.eValueTypeVariableArgument) - self.assertTrue(frame0.GetLineEntry().GetLine() == self.line1) - - # The hit count for the breakpoint should be 1. - self.assertTrue(breakpoint.GetHitCount() == 1) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_conditions/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_conditions/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_conditions/main.c @@ -1,53 +0,0 @@ -//===-- main.c --------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -#include - -// This simple program is to demonstrate the capability of the lldb command -// "breakpoint modify -c 'val == 3' breakpt-id" to break within c(int val) only -// when the value of the arg is 3. - -int a(int); -int b(int); -int c(int); - -int a(int val) -{ - if (val <= 1) - return b(val); - else if (val >= 3) - return c(val); // Find the line number of c's parent call here. - - return val; -} - -int b(int val) -{ - return c(val); -} - -int c(int val) -{ - return val + 3; // Find the line number of function "c" here. -} - -int main (int argc, char const *argv[]) -{ - int A1 = a(1); // a(1) -> b(1) -> c(1) - printf("a(1) returns %d\n", A1); - - int B2 = b(2); // b(2) -> c(2) - printf("b(2) returns %d\n", B2); - - int A3 = a(3); // a(3) -> c(3) - printf("a(3) returns %d\n", A3); - - for (int i = 0; i < 2; ++i) - printf("Loop\n"); - - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/TestBreakpointHitCount.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/TestBreakpointHitCount.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/TestBreakpointHitCount.py @@ -1,134 +0,0 @@ -""" -Test breakpoint hit count features. -""" - -from __future__ import print_function - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class BreakpointHitCountTestCase(TestBase): - - NO_DEBUG_INFO_TESTCASE = True - - mydir = TestBase.compute_mydir(__file__) - - @add_test_categories(['pyapi']) - def test_breakpoint_location_hit_count(self): - """Use Python APIs to check breakpoint hit count.""" - self.build() - self.do_test_breakpoint_location_hit_count() - - def test_breakpoint_one_shot(self): - """Check that one-shot breakpoints trigger only once.""" - self.build() - - exe = self.getBuildArtifact("a.out") - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, VALID_TARGET) - - self.runCmd("tb a") - process = target.LaunchSimple( - None, None, self.get_process_working_directory()) - self.assertTrue(process, PROCESS_IS_VALID) - - from lldbsuite.test.lldbutil import get_stopped_thread - thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) - self.assertTrue( - thread.IsValid(), - "There should be a thread stopped due to breakpoint") - - frame0 = thread.GetFrameAtIndex(0) - self.assertTrue(frame0.GetFunctionName() == "a(int)" or frame0.GetFunctionName() == "int a(int)"); - - process.Continue() - self.assertEqual(process.GetState(), lldb.eStateExited) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - self.a_int_body_line_no = line_number( - 'main.cpp', '// Breakpoint Location 1') - self.a_float_body_line_no = line_number( - 'main.cpp', '// Breakpoint Location 2') - - def do_test_breakpoint_location_hit_count(self): - """Use Python APIs to check breakpoint hit count.""" - exe = self.getBuildArtifact("a.out") - - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, VALID_TARGET) - - # Create a breakpoint in main.cpp by name 'a', - # there should be two locations. - breakpoint = target.BreakpointCreateByName('a', 'a.out') - self.assertTrue(breakpoint and - breakpoint.GetNumLocations() == 2, - VALID_BREAKPOINT) - - # Verify all breakpoint locations are enabled. - location1 = breakpoint.GetLocationAtIndex(0) - self.assertTrue(location1 and - location1.IsEnabled(), - VALID_BREAKPOINT_LOCATION) - - location2 = breakpoint.GetLocationAtIndex(1) - self.assertTrue(location2 and - location2.IsEnabled(), - VALID_BREAKPOINT_LOCATION) - - # Launch the process, and do not stop at entry point. - process = target.LaunchSimple( - None, None, self.get_process_working_directory()) - self.assertTrue(process, PROCESS_IS_VALID) - - # Verify 1st breakpoint location is hit. - from lldbsuite.test.lldbutil import get_stopped_thread - thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) - self.assertTrue( - thread.IsValid(), - "There should be a thread stopped due to breakpoint") - - frame0 = thread.GetFrameAtIndex(0) - location1 = breakpoint.FindLocationByAddress(frame0.GetPC()) - self.assertTrue( - frame0.GetLineEntry().GetLine() == self.a_int_body_line_no, - "Stopped in int a(int)") - self.assertTrue(location1) - self.assertEqual(location1.GetHitCount(), 1) - self.assertEqual(breakpoint.GetHitCount(), 1) - - process.Continue() - - # Verify 2nd breakpoint location is hit. - thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) - self.assertTrue( - thread.IsValid(), - "There should be a thread stopped due to breakpoint") - - frame0 = thread.GetFrameAtIndex(0) - location2 = breakpoint.FindLocationByAddress(frame0.GetPC()) - self.assertTrue( - frame0.GetLineEntry().GetLine() == self.a_float_body_line_no, - "Stopped in float a(float)") - self.assertTrue(location2) - self.assertEqual(location2.GetHitCount(), 1) - self.assertEqual(location1.GetHitCount(), 1) - self.assertEqual(breakpoint.GetHitCount(), 2) - - process.Continue() - - # Verify 2nd breakpoint location is hit again. - thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) - self.assertTrue( - thread.IsValid(), - "There should be a thread stopped due to breakpoint") - - self.assertEqual(location2.GetHitCount(), 2) - self.assertEqual(location1.GetHitCount(), 1) - self.assertEqual(breakpoint.GetHitCount(), 3) - - process.Continue() Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/main.cpp @@ -1,26 +0,0 @@ -//===-- main.cpp ------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -int a(int val) -{ - return val; // Breakpoint Location 1 -} - -float a(float val) -{ - return val; // Breakpoint Location 2 -} - -int main (int argc, char const *argv[]) -{ - int A1 = a(1); - float A2 = a(2.0f); - float A3 = a(3.0f); - - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_ids/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_ids/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_ids/Makefile @@ -1,9 +0,0 @@ -LEVEL = ../../../make - -CXX_SOURCES := main.cpp - -ifneq (,$(findstring icc,$(CC))) - CXXFLAGS += -debug inline-debug-info -endif - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_ids/TestBreakpointIDs.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_ids/TestBreakpointIDs.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_ids/TestBreakpointIDs.py @@ -1,58 +0,0 @@ -""" -Test lldb breakpoint ids. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil - - -class BreakpointIDTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def test(self): - self.build() - - exe = self.getBuildArtifact("a.out") - self.expect("file " + exe, - patterns=["Current executable set to .*a.out"]) - - bpno = lldbutil.run_break_set_by_symbol( - self, 'product', num_expected_locations=-1, sym_exact=False) - self.assertTrue(bpno == 1, "First breakpoint number is 1.") - - bpno = lldbutil.run_break_set_by_symbol( - self, 'sum', num_expected_locations=-1, sym_exact=False) - self.assertTrue(bpno == 2, "Second breakpoint number is 2.") - - bpno = lldbutil.run_break_set_by_symbol( - self, 'junk', num_expected_locations=0, sym_exact=False) - self.assertTrue(bpno == 3, "Third breakpoint number is 3.") - - self.expect( - "breakpoint disable 1.1 - 2.2 ", - COMMAND_FAILED_AS_EXPECTED, - error=True, - startstr="error: Invalid range: Ranges that specify particular breakpoint locations must be within the same major breakpoint; you specified two different major breakpoints, 1 and 2.") - - self.expect( - "breakpoint disable 2 - 2.2", - COMMAND_FAILED_AS_EXPECTED, - error=True, - startstr="error: Invalid breakpoint id range: Either both ends of range must specify a breakpoint location, or neither can specify a breakpoint location.") - - self.expect( - "breakpoint disable 2.1 - 2", - COMMAND_FAILED_AS_EXPECTED, - error=True, - startstr="error: Invalid breakpoint id range: Either both ends of range must specify a breakpoint location, or neither can specify a breakpoint location.") - - self.expect("breakpoint disable 2.1 - 2.2", - startstr="2 breakpoints disabled.") - - self.expect("breakpoint enable 2.*", - patterns=[".* breakpoints enabled."]) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_ids/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_ids/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_ids/main.cpp @@ -1,64 +0,0 @@ -//===-- main.cpp ------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include -#include -#include -#include - - -#define INLINE inline __attribute__((always_inline)) - -INLINE int -product (int x, int y) -{ - int result = x * y; - return result; -} - -INLINE int -sum (int a, int b) -{ - int result = a + b; - return result; -} - -int -strange_max (int m, int n) -{ - if (m > n) - return m; - else if (n > m) - return n; - else - return 0; -} - -int -foo (int i, int j) -{ - if (strange_max (i, j) == i) - return product (i, j); - else if (strange_max (i, j) == j) - return sum (i, j); - else - return product (sum (i, i), sum (j, j)); -} - -int -main(int argc, char const *argv[]) -{ - - int array[3]; - - array[0] = foo (1238, 78392); - array[1] = foo (379265, 23674); - array[2] = foo (872934, 234); - - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_ignore_count/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_ignore_count/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_ignore_count/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_ignore_count/TestBreakpointIgnoreCount.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_ignore_count/TestBreakpointIgnoreCount.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_ignore_count/TestBreakpointIgnoreCount.py @@ -1,151 +0,0 @@ -""" -Test breakpoint ignore count features. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class BreakpointIgnoreCountTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @skipIfWindows # This test will hang on windows llvm.org/pr21753 - def test_with_run_command(self): - """Exercise breakpoint ignore count with 'breakpoint set -i '.""" - self.build() - self.breakpoint_ignore_count() - - @add_test_categories(['pyapi']) - @skipIfWindows # This test will hang on windows llvm.org/pr21753 - def test_with_python_api(self): - """Use Python APIs to set breakpoint ignore count.""" - self.build() - self.breakpoint_ignore_count_python() - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to of function 'c'. - self.line1 = line_number( - 'main.c', '// Find the line number of function "c" here.') - self.line2 = line_number( - 'main.c', '// b(2) -> c(2) Find the call site of b(2).') - self.line3 = line_number( - 'main.c', '// a(3) -> c(3) Find the call site of c(3).') - self.line4 = line_number( - 'main.c', '// a(3) -> c(3) Find the call site of a(3).') - self.line5 = line_number( - 'main.c', '// Find the call site of c in main.') - - def breakpoint_ignore_count(self): - """Exercise breakpoint ignore count with 'breakpoint set -i '.""" - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # Create a breakpoint in main.c at line1. - lldbutil.run_break_set_by_file_and_line( - self, - 'main.c', - self.line1, - extra_options='-i 1', - num_expected_locations=1, - loc_exact=True) - - # Now run the program. - self.runCmd("run", RUN_SUCCEEDED) - - # The process should be stopped at this point. - self.expect("process status", PROCESS_STOPPED, - patterns=['Process .* stopped']) - - # Also check the hit count, which should be 2, due to ignore count of - # 1. - self.expect("breakpoint list -f", BREAKPOINT_HIT_THRICE, - substrs=["resolved = 1", - "hit count = 2"]) - - # The frame #0 should correspond to main.c:37, the executable statement - # in function name 'c'. And frame #2 should point to main.c:45. - self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT_IGNORE_COUNT, - #substrs = ["stop reason = breakpoint"], - patterns=["frame #0.*main.c:%d" % self.line1, - "frame #2.*main.c:%d" % self.line2]) - - # continue -i 1 is the same as setting the ignore count to 1 again, try that: - # Now run the program. - self.runCmd("process continue -i 1", RUN_SUCCEEDED) - - # The process should be stopped at this point. - self.expect("process status", PROCESS_STOPPED, - patterns=['Process .* stopped']) - - # Also check the hit count, which should be 2, due to ignore count of - # 1. - self.expect("breakpoint list -f", BREAKPOINT_HIT_THRICE, - substrs=["resolved = 1", - "hit count = 4"]) - - # The frame #0 should correspond to main.c:37, the executable statement - # in function name 'c'. And frame #2 should point to main.c:45. - self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT_IGNORE_COUNT, - #substrs = ["stop reason = breakpoint"], - patterns=["frame #0.*main.c:%d" % self.line1, - "frame #1.*main.c:%d" % self.line5]) - - def breakpoint_ignore_count_python(self): - """Use Python APIs to set breakpoint ignore count.""" - exe = self.getBuildArtifact("a.out") - - # Create a target by the debugger. - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, VALID_TARGET) - - # Now create a breakpoint on main.c by name 'c'. - breakpoint = target.BreakpointCreateByName('c', 'a.out') - self.assertTrue(breakpoint and - breakpoint.GetNumLocations() == 1, - VALID_BREAKPOINT) - - # Get the breakpoint location from breakpoint after we verified that, - # indeed, it has one location. - location = breakpoint.GetLocationAtIndex(0) - self.assertTrue(location and - location.IsEnabled(), - VALID_BREAKPOINT_LOCATION) - - # Set the ignore count on the breakpoint location. - location.SetIgnoreCount(2) - self.assertTrue(location.GetIgnoreCount() == 2, - "SetIgnoreCount() works correctly") - - # Now launch the process, and do not stop at entry point. - process = target.LaunchSimple( - None, None, self.get_process_working_directory()) - self.assertTrue(process, PROCESS_IS_VALID) - - # Frame#0 should be on main.c:37, frame#1 should be on main.c:25, and - # frame#2 should be on main.c:48. - # lldbutil.print_stacktraces(process) - from lldbsuite.test.lldbutil import get_stopped_thread - thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) - self.assertTrue( - thread.IsValid(), - "There should be a thread stopped due to breakpoint") - frame0 = thread.GetFrameAtIndex(0) - frame1 = thread.GetFrameAtIndex(1) - frame2 = thread.GetFrameAtIndex(2) - self.assertTrue(frame0.GetLineEntry().GetLine() == self.line1 and - frame1.GetLineEntry().GetLine() == self.line3 and - frame2.GetLineEntry().GetLine() == self.line4, - STOPPED_DUE_TO_BREAKPOINT_IGNORE_COUNT) - - # The hit count for the breakpoint should be 3. - self.assertTrue(breakpoint.GetHitCount() == 3) - - process.Continue() Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_ignore_count/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_ignore_count/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_ignore_count/main.c @@ -1,53 +0,0 @@ -//===-- main.c --------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -#include - -// This simple program is to demonstrate the capability of the lldb command -// "breakpoint modify -i breakpt-id" to set the number of times a -// breakpoint is skipped before stopping. Ignore count can also be set upon -// breakpoint creation by 'breakpoint set ... -i '. - -int a(int); -int b(int); -int c(int); - -int a(int val) -{ - if (val <= 1) - return b(val); - else if (val >= 3) - return c(val); // a(3) -> c(3) Find the call site of c(3). - - return val; -} - -int b(int val) -{ - return c(val); -} - -int c(int val) -{ - return val + 3; // Find the line number of function "c" here. -} - -int main (int argc, char const *argv[]) -{ - int A1 = a(1); // a(1) -> b(1) -> c(1) - printf("a(1) returns %d\n", A1); - - int B2 = b(2); // b(2) -> c(2) Find the call site of b(2). - printf("b(2) returns %d\n", B2); - - int A3 = a(3); // a(3) -> c(3) Find the call site of a(3). - printf("a(3) returns %d\n", A3); - - int C1 = c(5); // Find the call site of c in main. - printf ("c(5) returns %d\n", C1); - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/Makefile @@ -1,6 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules - Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/TestAvoidBreakpointInDelaySlot.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/TestAvoidBreakpointInDelaySlot.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/TestAvoidBreakpointInDelaySlot.py @@ -1,87 +0,0 @@ -""" -Test specific to MIPS -""" - -from __future__ import print_function - -import re -import unittest2 -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class AvoidBreakpointInDelaySlotAPITestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @skipIf(archs=no_match(re.compile('mips*'))) - def test(self): - self.build() - exe = self.getBuildArtifact("a.out") - self.expect("file " + exe, - patterns=["Current executable set to .*a.out.*"]) - - # Create a target by the debugger. - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, VALID_TARGET) - - breakpoint = target.BreakpointCreateByName('main', 'a.out') - self.assertTrue(breakpoint and - breakpoint.GetNumLocations() == 1, - VALID_BREAKPOINT) - - # Now launch the process, and do not stop at entry point. - process = target.LaunchSimple( - None, None, self.get_process_working_directory()) - self.assertTrue(process, PROCESS_IS_VALID) - - list = target.FindFunctions('foo', lldb.eFunctionNameTypeAuto) - self.assertTrue(list.GetSize() == 1) - sc = list.GetContextAtIndex(0) - self.assertTrue(sc.GetSymbol().GetName() == "foo") - function = sc.GetFunction() - self.assertTrue(function) - self.function(function, target) - - def function(self, function, target): - """Iterate over instructions in function and place a breakpoint on delay slot instruction""" - # Get the list of all instructions in the function - insts = function.GetInstructions(target) - print(insts) - i = 0 - for inst in insts: - if (inst.HasDelaySlot()): - # Remember the address of branch instruction. - branchinstaddress = inst.GetAddress().GetLoadAddress(target) - - # Get next instruction i.e delay slot instruction. - delayinst = insts.GetInstructionAtIndex(i + 1) - delayinstaddr = delayinst.GetAddress().GetLoadAddress(target) - - # Set breakpoint on delay slot instruction - breakpoint = target.BreakpointCreateByAddress(delayinstaddr) - - # Verify the breakpoint. - self.assertTrue(breakpoint and - breakpoint.GetNumLocations() == 1, - VALID_BREAKPOINT) - # Get the location from breakpoint - location = breakpoint.GetLocationAtIndex(0) - - # Get the address where breakpoint is actually set. - bpaddr = location.GetLoadAddress() - - # Breakpoint address should be adjusted to the address of - # branch instruction. - self.assertTrue(branchinstaddress == bpaddr) - i += 1 - else: - i += 1 - -if __name__ == '__main__': - import atexit - lldb.SBDebugger.Initialize() - atexit.register(lambda: lldb.SBDebugger.Terminate()) - unittest2.main() Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/main.c @@ -1,21 +0,0 @@ -#include - -foo (int a, int b) -{ - int c; - if (a<=b) - c=b-a; - else - c=b+a; - return c; -} - -int main() -{ - int a=7, b=8, c; - - c = foo(a, b); - -return 0; -} - Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_language/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_language/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_language/Makefile @@ -1,6 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := a.c -CXX_SOURCES := main.cpp b.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_language/TestBreakpointLanguage.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_language/TestBreakpointLanguage.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_language/TestBreakpointLanguage.py @@ -1,133 +0,0 @@ -""" -Test that the language option for breakpoints works correctly -parser. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil - - -class TestBreakpointLanguage(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to break inside main(). - - def check_location_file(self, bp, loc, test_name): - bp_loc = bp.GetLocationAtIndex(loc) - addr = bp_loc.GetAddress() - comp_unit = addr.GetCompileUnit() - comp_name = comp_unit.GetFileSpec().GetFilename() - return comp_name == test_name - - def test_regex_breakpoint_language(self): - """Test that the name regex breakpoint commands obey the language filter.""" - - self.build() - # Create a target by the debugger. - exe = self.getBuildArtifact("a.out") - error = lldb.SBError() - # Don't read in dependencies so we don't come across false matches that - # add unwanted breakpoint hits. - self.target = self.dbg.CreateTarget(exe, None, None, False, error) - self.assertTrue(self.target, VALID_TARGET) - - cpp_bp = self.target.BreakpointCreateByRegex( - "func_from", - lldb.eLanguageTypeC_plus_plus, - lldb.SBFileSpecList(), - lldb.SBFileSpecList()) - self.assertTrue( - cpp_bp.GetNumLocations() == 1, - "Only one C++ symbol matches") - self.assertTrue(self.check_location_file(cpp_bp, 0, "b.cpp")) - - c_bp = self.target.BreakpointCreateByRegex( - "func_from", - lldb.eLanguageTypeC, - lldb.SBFileSpecList(), - lldb.SBFileSpecList()) - self.assertTrue( - c_bp.GetNumLocations() == 1, - "Only one C symbol matches") - self.assertTrue(self.check_location_file(c_bp, 0, "a.c")) - - objc_bp = self.target.BreakpointCreateByRegex( - "func_from", - lldb.eLanguageTypeObjC, - lldb.SBFileSpecList(), - lldb.SBFileSpecList()) - self.assertTrue( - objc_bp.GetNumLocations() == 0, - "No ObjC symbol matches") - - def test_by_name_breakpoint_language(self): - """Test that the name regex breakpoint commands obey the language filter.""" - - self.build() - # Create a target by the debugger. - exe = self.getBuildArtifact("a.out") - error = lldb.SBError() - # Don't read in dependencies so we don't come across false matches that - # add unwanted breakpoint hits. - self.target = self.dbg.CreateTarget(exe, None, None, False, error) - self.assertTrue(self.target, VALID_TARGET) - - cpp_bp = self.target.BreakpointCreateByName( - "func_from_cpp", - lldb.eFunctionNameTypeAuto, - lldb.eLanguageTypeC_plus_plus, - lldb.SBFileSpecList(), - lldb.SBFileSpecList()) - self.assertTrue( - cpp_bp.GetNumLocations() == 1, - "Only one C++ symbol matches") - self.assertTrue(self.check_location_file(cpp_bp, 0, "b.cpp")) - - no_cpp_bp = self.target.BreakpointCreateByName( - "func_from_c", - lldb.eFunctionNameTypeAuto, - lldb.eLanguageTypeC_plus_plus, - lldb.SBFileSpecList(), - lldb.SBFileSpecList()) - self.assertTrue( - no_cpp_bp.GetNumLocations() == 0, - "And the C one doesn't match") - - c_bp = self.target.BreakpointCreateByName( - "func_from_c", - lldb.eFunctionNameTypeAuto, - lldb.eLanguageTypeC, - lldb.SBFileSpecList(), - lldb.SBFileSpecList()) - self.assertTrue( - c_bp.GetNumLocations() == 1, - "Only one C symbol matches") - self.assertTrue(self.check_location_file(c_bp, 0, "a.c")) - - no_c_bp = self.target.BreakpointCreateByName( - "func_from_cpp", - lldb.eFunctionNameTypeAuto, - lldb.eLanguageTypeC, - lldb.SBFileSpecList(), - lldb.SBFileSpecList()) - self.assertTrue( - no_c_bp.GetNumLocations() == 0, - "And the C++ one doesn't match") - - objc_bp = self.target.BreakpointCreateByName( - "func_from_cpp", - lldb.eFunctionNameTypeAuto, - lldb.eLanguageTypeObjC, - lldb.SBFileSpecList(), - lldb.SBFileSpecList()) - self.assertTrue( - objc_bp.GetNumLocations() == 0, - "No ObjC symbol matches") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_language/a.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_language/a.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_language/a.c @@ -1,5 +0,0 @@ -int -func_from_c () -{ - return 5; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_language/b.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_language/b.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_language/b.cpp @@ -1,5 +0,0 @@ -int -func_from_cpp() -{ - return 10; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_language/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_language/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_language/main.cpp @@ -1,11 +0,0 @@ -#include -extern "C" int func_from_c(); -extern int func_from_cpp(); - -int -main() -{ - func_from_c(); - func_from_cpp(); - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_locations/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_locations/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_locations/Makefile @@ -1,9 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c - -ifneq (,$(findstring icc,$(CC))) - CFLAGS += -debug inline-debug-info -endif - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_locations/TestBreakpointLocations.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_locations/TestBreakpointLocations.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_locations/TestBreakpointLocations.py @@ -1,198 +0,0 @@ -""" -Test breakpoint commands for a breakpoint ID with multiple locations. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class BreakpointLocationsTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24528") - def test_enable(self): - """Test breakpoint enable/disable for a breakpoint ID with multiple locations.""" - self.build() - self.breakpoint_locations_test() - - def test_shadowed_cond_options(self): - """Test that options set on the breakpoint and location behave correctly.""" - self.build() - self.shadowed_bkpt_cond_test() - - - def test_shadowed_command_options(self): - """Test that options set on the breakpoint and location behave correctly.""" - self.build() - self.shadowed_bkpt_command_test() - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to break inside main(). - self.line = line_number('main.c', '// Set break point at this line.') - - def set_breakpoint (self): - exe = self.getBuildArtifact("a.out") - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, "Target %s is not valid"%(exe)) - - # This should create a breakpoint with 3 locations. - - bkpt = target.BreakpointCreateByLocation("main.c", self.line) - - # The breakpoint list should show 3 locations. - self.assertEqual(bkpt.GetNumLocations(), 3, "Wrong number of locations") - - self.expect( - "breakpoint list -f", - "Breakpoint locations shown correctly", - substrs=[ - "1: file = 'main.c', line = %d, exact_match = 0, locations = 3" % - self.line], - patterns=[ - "where = a.out`func_inlined .+unresolved, hit count = 0", - "where = a.out`main .+\[inlined\].+unresolved, hit count = 0"]) - - return bkpt - - def shadowed_bkpt_cond_test(self): - """Test that options set on the breakpoint and location behave correctly.""" - # Breakpoint option propagation from bkpt to loc used to be done the first time - # a breakpoint location option was specifically set. After that the other options - # on that location would stop tracking the breakpoint. That got fixed, and this test - # makes sure only the option touched is affected. - - bkpt = self.set_breakpoint() - bkpt_cond = "1 == 0" - bkpt.SetCondition(bkpt_cond) - self.assertEqual(bkpt.GetCondition(), bkpt_cond,"Successfully set condition") - self.assertTrue(bkpt.location[0].GetCondition() == bkpt.GetCondition(), "Conditions are the same") - - # Now set a condition on the locations, make sure that this doesn't effect the bkpt: - bkpt_loc_1_cond = "1 == 1" - bkpt.location[0].SetCondition(bkpt_loc_1_cond) - self.assertEqual(bkpt.location[0].GetCondition(), bkpt_loc_1_cond, "Successfully changed location condition") - self.assertNotEqual(bkpt.GetCondition(), bkpt_loc_1_cond, "Changed location changed Breakpoint condition") - self.assertEqual(bkpt.location[1].GetCondition(), bkpt_cond, "Changed another location's condition") - - # Now make sure that setting one options doesn't fix the value of another: - bkpt.SetIgnoreCount(10) - self.assertEqual(bkpt.GetIgnoreCount(), 10, "Set the ignore count successfully") - self.assertEqual(bkpt.location[0].GetIgnoreCount(), 10, "Location doesn't track top-level bkpt.") - - # Now make sure resetting the condition to "" resets the tracking: - bkpt.location[0].SetCondition("") - bkpt_new_cond = "1 == 3" - bkpt.SetCondition(bkpt_new_cond) - self.assertEqual(bkpt.location[0].GetCondition(), bkpt_new_cond, "Didn't go back to tracking condition") - - def shadowed_bkpt_command_test(self): - """Test that options set on the breakpoint and location behave correctly.""" - # Breakpoint option propagation from bkpt to loc used to be done the first time - # a breakpoint location option was specifically set. After that the other options - # on that location would stop tracking the breakpoint. That got fixed, and this test - # makes sure only the option touched is affected. - - bkpt = self.set_breakpoint() - commands = ["AAAAAA", "BBBBBB", "CCCCCC"] - str_list = lldb.SBStringList() - str_list.AppendList(commands, len(commands)) - - bkpt.SetCommandLineCommands(str_list) - cmd_list = lldb.SBStringList() - bkpt.GetCommandLineCommands(cmd_list) - list_size = str_list.GetSize() - self.assertEqual(cmd_list.GetSize() , list_size, "Added the right number of commands") - for i in range(0,list_size): - self.assertEqual(str_list.GetStringAtIndex(i), cmd_list.GetStringAtIndex(i), "Mismatched commands.") - - commands = ["DDDDDD", "EEEEEE", "FFFFFF", "GGGGGG"] - loc_list = lldb.SBStringList() - loc_list.AppendList(commands, len(commands)) - bkpt.location[1].SetCommandLineCommands(loc_list) - loc_cmd_list = lldb.SBStringList() - bkpt.location[1].GetCommandLineCommands(loc_cmd_list) - - loc_list_size = loc_list.GetSize() - - # Check that the location has the right commands: - self.assertEqual(loc_cmd_list.GetSize() , loc_list_size, "Added the right number of commands to location") - for i in range(0,loc_list_size): - self.assertEqual(loc_list.GetStringAtIndex(i), loc_cmd_list.GetStringAtIndex(i), "Mismatched commands.") - - # Check that we didn't mess up the breakpoint level commands: - self.assertEqual(cmd_list.GetSize() , list_size, "Added the right number of commands") - for i in range(0,list_size): - self.assertEqual(str_list.GetStringAtIndex(i), cmd_list.GetStringAtIndex(i), "Mismatched commands.") - - # And check we didn't mess up another location: - untouched_loc_cmds = lldb.SBStringList() - bkpt.location[0].GetCommandLineCommands(untouched_loc_cmds) - self.assertEqual(untouched_loc_cmds.GetSize() , 0, "Changed the wrong location") - - def breakpoint_locations_test(self): - """Test breakpoint enable/disable for a breakpoint ID with multiple locations.""" - self.set_breakpoint() - - # The 'breakpoint disable 3.*' command should fail gracefully. - self.expect("breakpoint disable 3.*", - "Disabling an invalid breakpoint should fail gracefully", - error=True, - startstr="error: '3' is not a valid breakpoint ID.") - - # The 'breakpoint disable 1.*' command should disable all 3 locations. - self.expect( - "breakpoint disable 1.*", - "All 3 breakpoint locatons disabled correctly", - startstr="3 breakpoints disabled.") - - # Run the program. - self.runCmd("run", RUN_SUCCEEDED) - - # We should not stopped on any breakpoint at all. - self.expect("process status", "No stopping on any disabled breakpoint", - patterns=["^Process [0-9]+ exited with status = 0"]) - - # The 'breakpoint enable 1.*' command should enable all 3 breakpoints. - self.expect( - "breakpoint enable 1.*", - "All 3 breakpoint locatons enabled correctly", - startstr="3 breakpoints enabled.") - - # The 'breakpoint disable 1.1' command should disable 1 location. - self.expect( - "breakpoint disable 1.1", - "1 breakpoint locatons disabled correctly", - startstr="1 breakpoints disabled.") - - # Run the program again. We should stop on the two breakpoint - # locations. - self.runCmd("run", RUN_SUCCEEDED) - - # Stopped once. - self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, - substrs=["stop reason = breakpoint 1."]) - - # Continue the program, there should be another stop. - self.runCmd("process continue") - - # Stopped again. - self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, - substrs=["stop reason = breakpoint 1."]) - - # At this point, 1.1 has a hit count of 0 and the other a hit count of - # 1". - self.expect( - "breakpoint list -f", - "The breakpoints should report correct hit counts", - patterns=[ - "1\.1: .+ unresolved, hit count = 0 +Options: disabled", - "1\.2: .+ resolved, hit count = 1", - "1\.3: .+ resolved, hit count = 1"]) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_locations/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_locations/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_locations/main.c @@ -1,43 +0,0 @@ -#include - -#define INLINE inline __attribute__((always_inline)) - -int -func_not_inlined (void) -{ - printf ("Called func_not_inlined.\n"); - return 0; -} - -INLINE int -func_inlined (void) -{ - static int func_inline_call_count = 0; - printf ("Called func_inlined.\n"); - ++func_inline_call_count; - printf ("Returning func_inlined call count: %d.\n", func_inline_call_count); - return func_inline_call_count; // Set break point at this line. -} - -extern int func_inlined (void); - -int -main (int argc, char **argv) -{ - printf ("Starting...\n"); - - int (*func_ptr) (void); - func_ptr = func_inlined; - - int a = func_inlined(); - printf("First call to func_inlined() returns: %d.\n", a); - - func_not_inlined (); - - func_ptr (); - - printf("Last call to func_inlined() returns: %d.\n", func_inlined ()); - return 0; -} - - Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_names/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_names/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_names/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_names/TestBreakpointNames.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_names/TestBreakpointNames.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_names/TestBreakpointNames.py @@ -1,365 +0,0 @@ -""" -Test breakpoint names. -""" - -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 BreakpointNames(TestBase): - - mydir = TestBase.compute_mydir(__file__) - NO_DEBUG_INFO_TESTCASE = True - - @add_test_categories(['pyapi']) - def test_setting_names(self): - """Use Python APIs to test that we can set breakpoint names.""" - self.build() - self.setup_target() - self.do_check_names() - - def test_illegal_names(self): - """Use Python APIs to test that we don't allow illegal names.""" - self.build() - self.setup_target() - self.do_check_illegal_names() - - def test_using_names(self): - """Use Python APIs to test that operations on names works correctly.""" - self.build() - self.setup_target() - self.do_check_using_names() - - def test_configuring_names(self): - """Use Python APIs to test that configuring options on breakpoint names works correctly.""" - self.build() - self.make_a_dummy_name() - self.setup_target() - self.do_check_configuring_names() - - def test_configuring_permissions_sb(self): - """Use Python APIs to test that configuring permissions on names works correctly.""" - self.build() - self.setup_target() - self.do_check_configuring_permissions_sb() - - def test_configuring_permissions_cli(self): - """Use Python APIs to test that configuring permissions on names works correctly.""" - self.build() - self.setup_target() - self.do_check_configuring_permissions_cli() - - def setup_target(self): - exe = self.getBuildArtifact("a.out") - - # Create a targets we are making breakpoint in and copying to: - self.target = self.dbg.CreateTarget(exe) - self.assertTrue(self.target, VALID_TARGET) - self.main_file_spec = lldb.SBFileSpec(os.path.join(self.getSourceDir(), "main.c")) - - def check_name_in_target(self, bkpt_name): - name_list = lldb.SBStringList() - self.target.GetBreakpointNames(name_list) - found_it = False - for name in name_list: - if name == bkpt_name: - found_it = True - break - self.assertTrue(found_it, "Didn't find the name %s in the target's name list:"%(bkpt_name)) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - - # These are the settings we're going to be putting into names & breakpoints: - self.bp_name_string = "ABreakpoint" - self.is_one_shot = True - self.ignore_count = 1000 - self.condition = "1 == 2" - self.auto_continue = True - self.tid = 0xaaaa - self.tidx = 10 - self.thread_name = "Fooey" - self.queue_name = "Blooey" - self.cmd_list = lldb.SBStringList() - self.cmd_list.AppendString("frame var") - self.cmd_list.AppendString("bt") - self.help_string = "I do something interesting" - - - def do_check_names(self): - """Use Python APIs to check that we can set & retrieve breakpoint names""" - bkpt = self.target.BreakpointCreateByLocation(self.main_file_spec, 10) - bkpt_name = "ABreakpoint" - other_bkpt_name = "_AnotherBreakpoint" - - # Add a name and make sure we match it: - success = bkpt.AddName(bkpt_name) - self.assertTrue(success, "We couldn't add a legal name to a breakpoint.") - - matches = bkpt.MatchesName(bkpt_name) - self.assertTrue(matches, "We didn't match the name we just set") - - # Make sure we don't match irrelevant names: - matches = bkpt.MatchesName("NotABreakpoint") - self.assertTrue(not matches, "We matched a name we didn't set.") - - # Make sure the name is also in the target: - self.check_name_in_target(bkpt_name) - - # Add another name, make sure that works too: - bkpt.AddName(other_bkpt_name) - - matches = bkpt.MatchesName(bkpt_name) - self.assertTrue(matches, "Adding a name means we didn't match the name we just set") - self.check_name_in_target(other_bkpt_name) - - # Remove the name and make sure we no longer match it: - bkpt.RemoveName(bkpt_name) - matches = bkpt.MatchesName(bkpt_name) - self.assertTrue(not matches,"We still match a name after removing it.") - - # Make sure the name list has the remaining name: - name_list = lldb.SBStringList() - bkpt.GetNames(name_list) - num_names = name_list.GetSize() - self.assertTrue(num_names == 1, "Name list has %d items, expected 1."%(num_names)) - - name = name_list.GetStringAtIndex(0) - self.assertTrue(name == other_bkpt_name, "Remaining name was: %s expected %s."%(name, other_bkpt_name)) - - def do_check_illegal_names(self): - """Use Python APIs to check that we reject illegal names.""" - bkpt = self.target.BreakpointCreateByLocation(self.main_file_spec, 10) - bad_names = ["-CantStartWithADash", - "1CantStartWithANumber", - "^CantStartWithNonAlpha", - "CantHave-ADash", - "Cant Have Spaces"] - for bad_name in bad_names: - success = bkpt.AddName(bad_name) - self.assertTrue(not success,"We allowed an illegal name: %s"%(bad_name)) - bp_name = lldb.SBBreakpointName(self.target, bad_name) - self.assertFalse(bp_name.IsValid(), "We made a breakpoint name with an illegal name: %s"%(bad_name)); - - retval =lldb.SBCommandReturnObject() - self.dbg.GetCommandInterpreter().HandleCommand("break set -n whatever -N '%s'"%(bad_name), retval) - self.assertTrue(not retval.Succeeded(), "break set succeeded with: illegal name: %s"%(bad_name)) - - def do_check_using_names(self): - """Use Python APIs to check names work in place of breakpoint ID's.""" - - bkpt = self.target.BreakpointCreateByLocation(self.main_file_spec, 10) - bkpt_name = "ABreakpoint" - other_bkpt_name= "_AnotherBreakpoint" - - # Add a name and make sure we match it: - success = bkpt.AddName(bkpt_name) - self.assertTrue(success, "We couldn't add a legal name to a breakpoint.") - - bkpts = lldb.SBBreakpointList(self.target) - self.target.FindBreakpointsByName(bkpt_name, bkpts) - - self.assertTrue(bkpts.GetSize() == 1, "One breakpoint matched.") - found_bkpt = bkpts.GetBreakpointAtIndex(0) - self.assertTrue(bkpt.GetID() == found_bkpt.GetID(),"The right breakpoint.") - - retval = lldb.SBCommandReturnObject() - self.dbg.GetCommandInterpreter().HandleCommand("break disable %s"%(bkpt_name), retval) - self.assertTrue(retval.Succeeded(), "break disable failed with: %s."%(retval.GetError())) - self.assertTrue(not bkpt.IsEnabled(), "We didn't disable the breakpoint.") - - # Also make sure we don't apply commands to non-matching names: - self.dbg.GetCommandInterpreter().HandleCommand("break modify --one-shot 1 %s"%(other_bkpt_name), retval) - self.assertTrue(retval.Succeeded(), "break modify failed with: %s."%(retval.GetError())) - self.assertTrue(not bkpt.IsOneShot(), "We applied one-shot to the wrong breakpoint.") - - def check_option_values(self, bp_object): - self.assertEqual(bp_object.IsOneShot(), self.is_one_shot, "IsOneShot") - self.assertEqual(bp_object.GetIgnoreCount(), self.ignore_count, "IgnoreCount") - self.assertEqual(bp_object.GetCondition(), self.condition, "Condition") - self.assertEqual(bp_object.GetAutoContinue(), self.auto_continue, "AutoContinue") - self.assertEqual(bp_object.GetThreadID(), self.tid, "Thread ID") - self.assertEqual(bp_object.GetThreadIndex(), self.tidx, "Thread Index") - self.assertEqual(bp_object.GetThreadName(), self.thread_name, "Thread Name") - self.assertEqual(bp_object.GetQueueName(), self.queue_name, "Queue Name") - set_cmds = lldb.SBStringList() - bp_object.GetCommandLineCommands(set_cmds) - self.assertEqual(set_cmds.GetSize(), self.cmd_list.GetSize(), "Size of command line commands") - for idx in range(0, set_cmds.GetSize()): - self.assertEqual(self.cmd_list.GetStringAtIndex(idx), set_cmds.GetStringAtIndex(idx), "Command %d"%(idx)) - - def make_a_dummy_name(self): - "This makes a breakpoint name in the dummy target to make sure it gets copied over" - - dummy_target = self.dbg.GetDummyTarget() - self.assertTrue(dummy_target.IsValid(), "Dummy target was not valid.") - - def cleanup (): - self.dbg.GetDummyTarget().DeleteBreakpointName(self.bp_name_string) - - # Execute the cleanup function during test case tear down. - self.addTearDownHook(cleanup) - - # Now find it in the dummy target, and make sure these settings took: - bp_name = lldb.SBBreakpointName(dummy_target, self.bp_name_string) - # Make sure the name is right: - self.assertTrue (bp_name.GetName() == self.bp_name_string, "Wrong bp_name: %s"%(bp_name.GetName())) - bp_name.SetOneShot(self.is_one_shot) - bp_name.SetIgnoreCount(self.ignore_count) - bp_name.SetCondition(self.condition) - bp_name.SetAutoContinue(self.auto_continue) - bp_name.SetThreadID(self.tid) - bp_name.SetThreadIndex(self.tidx) - bp_name.SetThreadName(self.thread_name) - bp_name.SetQueueName(self.queue_name) - bp_name.SetCommandLineCommands(self.cmd_list) - - # Now look it up again, and make sure it got set correctly. - bp_name = lldb.SBBreakpointName(dummy_target, self.bp_name_string) - self.assertTrue(bp_name.IsValid(), "Failed to make breakpoint name.") - self.check_option_values(bp_name) - - def do_check_configuring_names(self): - """Use Python APIs to check that configuring breakpoint names works correctly.""" - other_bp_name_string = "AnotherBreakpointName" - cl_bp_name_string = "CLBreakpointName" - - # Now find the version copied in from the dummy target, and make sure these settings took: - bp_name = lldb.SBBreakpointName(self.target, self.bp_name_string) - self.assertTrue(bp_name.IsValid(), "Failed to make breakpoint name.") - self.check_option_values(bp_name) - - # Now add this name to a breakpoint, and make sure it gets configured properly - bkpt = self.target.BreakpointCreateByLocation(self.main_file_spec, 10) - success = bkpt.AddName(self.bp_name_string) - self.assertTrue(success, "Couldn't add this name to the breakpoint") - self.check_option_values(bkpt) - - # Now make a name from this breakpoint, and make sure the new name is properly configured: - new_name = lldb.SBBreakpointName(bkpt, other_bp_name_string) - self.assertTrue(new_name.IsValid(), "Couldn't make a valid bp_name from a breakpoint.") - self.check_option_values(bkpt) - - # Now change the name's option and make sure it gets propagated to - # the breakpoint: - new_auto_continue = not self.auto_continue - bp_name.SetAutoContinue(new_auto_continue) - self.assertEqual(bp_name.GetAutoContinue(), new_auto_continue, "Couldn't change auto-continue on the name") - self.assertEqual(bkpt.GetAutoContinue(), new_auto_continue, "Option didn't propagate to the breakpoint.") - - # Now make this same breakpoint name - but from the command line - cmd_str = "breakpoint name configure %s -o %d -i %d -c '%s' -G %d -t %d -x %d -T '%s' -q '%s' -H '%s'"%(cl_bp_name_string, - self.is_one_shot, - self.ignore_count, - self.condition, - self.auto_continue, - self.tid, - self.tidx, - self.thread_name, - self.queue_name, - self.help_string) - for cmd in self.cmd_list: - cmd_str += " -C '%s'"%(cmd) - - self.runCmd(cmd_str, check=True) - # Now look up this name again and check its options: - cl_name = lldb.SBBreakpointName(self.target, cl_bp_name_string) - self.check_option_values(cl_name) - # Also check the help string: - self.assertEqual(self.help_string, cl_name.GetHelpString(), "Help string didn't match") - # Change the name and make sure that works: - new_help = "I do something even more interesting" - cl_name.SetHelpString(new_help) - self.assertEqual(new_help, cl_name.GetHelpString(), "SetHelpString didn't") - - # We should have three names now, make sure the target can list them: - name_list = lldb.SBStringList() - self.target.GetBreakpointNames(name_list) - for name_string in [self.bp_name_string, other_bp_name_string, cl_bp_name_string]: - self.assertTrue(name_string in name_list, "Didn't find %s in names"%(name_string)) - - # Delete the name from the current target. Make sure that works and deletes the - # name from the breakpoint as well: - self.target.DeleteBreakpointName(self.bp_name_string) - name_list.Clear() - self.target.GetBreakpointNames(name_list) - self.assertTrue(self.bp_name_string not in name_list, "Didn't delete %s from a real target"%(self.bp_name_string)) - # Also make sure the name got removed from breakpoints holding it: - self.assertFalse(bkpt.MatchesName(self.bp_name_string), "Didn't remove the name from the breakpoint.") - - # Test that deleting the name we injected into the dummy target works (there's also a - # cleanup that will do this, but that won't test the result... - dummy_target = self.dbg.GetDummyTarget() - dummy_target.DeleteBreakpointName(self.bp_name_string) - name_list.Clear() - dummy_target.GetBreakpointNames(name_list) - self.assertTrue(self.bp_name_string not in name_list, "Didn't delete %s from the dummy target"%(self.bp_name_string)) - # Also make sure the name got removed from breakpoints holding it: - self.assertFalse(bkpt.MatchesName(self.bp_name_string), "Didn't remove the name from the breakpoint.") - - def check_permission_results(self, bp_name): - self.assertEqual(bp_name.GetAllowDelete(), False, "Didn't set allow delete.") - protected_bkpt = self.target.BreakpointCreateByLocation(self.main_file_spec, 10) - protected_id = protected_bkpt.GetID() - - unprotected_bkpt = self.target.BreakpointCreateByLocation(self.main_file_spec, 10) - unprotected_id = unprotected_bkpt.GetID() - - success = protected_bkpt.AddName(self.bp_name_string) - self.assertTrue(success, "Couldn't add this name to the breakpoint") - - self.target.DisableAllBreakpoints() - self.assertEqual(protected_bkpt.IsEnabled(), True, "Didnt' keep breakpoint from being disabled") - self.assertEqual(unprotected_bkpt.IsEnabled(), False, "Protected too many breakpoints from disabling.") - - # Try from the command line too: - unprotected_bkpt.SetEnabled(True) - result = lldb.SBCommandReturnObject() - self.dbg.GetCommandInterpreter().HandleCommand("break disable", result) - self.assertTrue(result.Succeeded()) - self.assertEqual(protected_bkpt.IsEnabled(), True, "Didnt' keep breakpoint from being disabled") - self.assertEqual(unprotected_bkpt.IsEnabled(), False, "Protected too many breakpoints from disabling.") - - self.target.DeleteAllBreakpoints() - bkpt = self.target.FindBreakpointByID(protected_id) - self.assertTrue(bkpt.IsValid(), "Didn't keep the breakpoint from being deleted.") - bkpt = self.target.FindBreakpointByID(unprotected_id) - self.assertFalse(bkpt.IsValid(), "Protected too many breakpoints from deletion.") - - # Remake the unprotected breakpoint and try again from the command line: - unprotected_bkpt = self.target.BreakpointCreateByLocation(self.main_file_spec, 10) - unprotected_id = unprotected_bkpt.GetID() - - self.dbg.GetCommandInterpreter().HandleCommand("break delete -f", result) - self.assertTrue(result.Succeeded()) - bkpt = self.target.FindBreakpointByID(protected_id) - self.assertTrue(bkpt.IsValid(), "Didn't keep the breakpoint from being deleted.") - bkpt = self.target.FindBreakpointByID(unprotected_id) - self.assertFalse(bkpt.IsValid(), "Protected too many breakpoints from deletion.") - - def do_check_configuring_permissions_sb(self): - bp_name = lldb.SBBreakpointName(self.target, self.bp_name_string) - - # Make a breakpoint name with delete disallowed: - bp_name = lldb.SBBreakpointName(self.target, self.bp_name_string) - self.assertTrue(bp_name.IsValid(), "Failed to make breakpoint name for valid name.") - - bp_name.SetAllowDelete(False) - bp_name.SetAllowDisable(False) - bp_name.SetAllowList(False) - self.check_permission_results(bp_name) - - def do_check_configuring_permissions_cli(self): - # Make the name with the right options using the command line: - self.runCmd("breakpoint name configure -L 0 -D 0 -A 0 %s"%(self.bp_name_string), check=True) - # Now look up the breakpoint we made, and check that it works. - bp_name = lldb.SBBreakpointName(self.target, self.bp_name_string) - self.assertTrue(bp_name.IsValid(), "Didn't make a breakpoint name we could find.") - self.check_permission_results(bp_name) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_names/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_names/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_names/main.c @@ -1,53 +0,0 @@ -//===-- main.c --------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -#include - -// This simple program is to demonstrate the capability of the lldb command -// "breakpoint modify -i breakpt-id" to set the number of times a -// breakpoint is skipped before stopping. Ignore count can also be set upon -// breakpoint creation by 'breakpoint set ... -i '. - -int a(int); -int b(int); -int c(int); - -int a(int val) -{ - if (val <= 1) - return b(val); - else if (val >= 3) - return c(val); // a(3) -> c(3) Find the call site of c(3). - - return val; -} - -int b(int val) -{ - return c(val); -} - -int c(int val) -{ - return val + 3; // Find the line number of function "c" here. -} - -int main (int argc, char const *argv[]) -{ - int A1 = a(1); // a(1) -> b(1) -> c(1) - printf("a(1) returns %d\n", A1); - - int B2 = b(2); // b(2) -> c(2) Find the call site of b(2). - printf("b(2) returns %d\n", B2); - - int A3 = a(3); // a(3) -> c(3) Find the call site of a(3). - printf("a(3) returns %d\n", A3); - - int C1 = c(5); // Find the call site of c in main. - printf ("c(5) returns %d\n", C1); - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_options/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_options/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_options/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -CXX_SOURCES := main.cpp foo.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_options/TestBreakpointOptions.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_options/TestBreakpointOptions.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_options/TestBreakpointOptions.py @@ -1,114 +0,0 @@ -""" -Test breakpoint command for different options. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil - - -class BreakpointOptionsTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def test(self): - """Test breakpoint command for different options.""" - self.build() - self.breakpoint_options_test() - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to break inside main(). - self.line = line_number('main.cpp', '// Set break point at this line.') - - def breakpoint_options_test(self): - """Test breakpoint command for different options.""" - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # This should create a breakpoint with 1 locations. - lldbutil.run_break_set_by_file_and_line( - self, - "main.cpp", - self.line, - extra_options="-K 1", - num_expected_locations=1) - lldbutil.run_break_set_by_file_and_line( - self, - "main.cpp", - self.line, - extra_options="-K 0", - num_expected_locations=1) - - # Run the program. - self.runCmd("run", RUN_SUCCEEDED) - - # Stopped once. - self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, - substrs=["stop reason = breakpoint 2."]) - - # Check the list of breakpoint. - self.expect( - "breakpoint list -f", - "Breakpoint locations shown correctly", - substrs=[ - "1: file = 'main.cpp', line = %d, exact_match = 0, locations = 1" % - self.line, - "2: file = 'main.cpp', line = %d, exact_match = 0, locations = 1" % - self.line]) - - # Continue the program, there should be another stop. - self.runCmd("process continue") - - # Stopped again. - self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, - substrs=["stop reason = breakpoint 1."]) - - # Continue the program, we should exit. - self.runCmd("process continue") - - # We should exit. - self.expect("process status", "Process exited successfully", - patterns=["^Process [0-9]+ exited with status = 0"]) - - def breakpoint_options_language_test(self): - """Test breakpoint command for language option.""" - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # This should create a breakpoint with 1 locations. - lldbutil.run_break_set_by_symbol( - self, - 'ns::func', - sym_exact=False, - extra_options="-L c++", - num_expected_locations=1) - - # This should create a breakpoint with 0 locations. - lldbutil.run_break_set_by_symbol( - self, - 'ns::func', - sym_exact=False, - extra_options="-L c", - num_expected_locations=0) - self.runCmd("settings set target.language c") - lldbutil.run_break_set_by_symbol( - self, 'ns::func', sym_exact=False, num_expected_locations=0) - - # Run the program. - self.runCmd("run", RUN_SUCCEEDED) - - # Stopped once. - self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, - substrs=["stop reason = breakpoint 1."]) - - # Continue the program, we should exit. - self.runCmd("process continue") - - # We should exit. - self.expect("process status", "Process exited successfully", - patterns=["^Process [0-9]+ exited with status = 0"]) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_options/foo.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_options/foo.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_options/foo.cpp @@ -1,12 +0,0 @@ - -namespace ns { - int func(void) - { - return 0; - } -} - -extern "C" int foo(void) -{ - return ns::func(); -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_options/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_options/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_options/main.cpp @@ -1,4 +0,0 @@ -extern "C" int foo(void); -int main (int argc, char **argv) { // Set break point at this line. - return foo(); -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_set_restart/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_set_restart/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_set_restart/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_set_restart/TestBreakpointSetRestart.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_set_restart/TestBreakpointSetRestart.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_set_restart/TestBreakpointSetRestart.py @@ -1,50 +0,0 @@ -""" -Test inferior restart when breakpoint is set on running target. -""" - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * - - -class BreakpointSetRestart(TestBase): - - mydir = TestBase.compute_mydir(__file__) - BREAKPOINT_TEXT = 'Set a breakpoint here' - - @skipIfNetBSD - def test_breakpoint_set_restart(self): - self.build() - - exe = self.getBuildArtifact("a.out") - - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, VALID_TARGET) - - self.dbg.SetAsync(True) - process = target.LaunchSimple( - None, None, self.get_process_working_directory()) - self.assertTrue(process, PROCESS_IS_VALID) - - event = lldb.SBEvent() - # Wait for inferior to transition to running state - while self.dbg.GetListener().WaitForEvent(2, event): - if lldb.SBProcess.GetStateFromEvent(event) == lldb.eStateRunning: - break - - bp = target.BreakpointCreateBySourceRegex( - self.BREAKPOINT_TEXT, lldb.SBFileSpec('main.cpp')) - self.assertTrue( - bp.IsValid() and bp.GetNumLocations() == 1, - VALID_BREAKPOINT) - - while self.dbg.GetListener().WaitForEvent(2, event): - if lldb.SBProcess.GetStateFromEvent( - event) == lldb.eStateStopped and lldb.SBProcess.GetRestartedFromEvent(event): - continue - if lldb.SBProcess.GetStateFromEvent(event) == lldb.eStateRunning: - continue - self.fail( - "Setting a breakpoint generated an unexpected event: %s" % - lldb.SBDebugger.StateAsCString( - lldb.SBProcess.GetStateFromEvent(event))) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_set_restart/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_set_restart/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_set_restart/main.cpp @@ -1,24 +0,0 @@ -//===-- main.cpp ------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include -#include -#include - - -int main(int argc, char const *argv[]) -{ - static bool done = false; - while (!done) - { - std::this_thread::sleep_for(std::chrono::milliseconds{100}); - } - printf("Set a breakpoint here.\n"); - return 0; -} - Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/comp_dir_symlink/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/comp_dir_symlink/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/comp_dir_symlink/Makefile @@ -1,14 +0,0 @@ -LEVEL = ../../../make - -CXX_SOURCES := relative.cpp - -EXE := CompDirSymLink - -include $(LEVEL)/Makefile.rules - -# Force relative filenames by copying it into the build directory. -relative.cpp: main.cpp - cp -f $< $@ - -clean:: - rm -rf relative.cpp Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/comp_dir_symlink/TestCompDirSymLink.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/comp_dir_symlink/TestCompDirSymLink.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/comp_dir_symlink/TestCompDirSymLink.py @@ -1,79 +0,0 @@ -""" -Test breakpoint command with AT_comp_dir set to symbolic link. -""" -from __future__ import print_function - - -import os -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -_EXE_NAME = 'CompDirSymLink' # Must match Makefile -_SRC_FILE = 'relative.cpp' -_COMP_DIR_SYM_LINK_PROP = 'plugin.symbol-file.dwarf.comp-dir-symlink-paths' - - -class CompDirSymLinkTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to break inside main(). - self.line = line_number( - os.path.join(self.getSourceDir(), "main.cpp"), - '// Set break point at this line.') - - @skipIf(hostoslist=["windows"]) - def test_symlink_paths_set(self): - pwd_symlink = self.create_src_symlink() - self.doBuild(pwd_symlink) - self.runCmd( - "settings set %s %s" % - (_COMP_DIR_SYM_LINK_PROP, pwd_symlink)) - src_path = self.getBuildArtifact(_SRC_FILE) - lldbutil.run_break_set_by_file_and_line(self, src_path, self.line) - - @skipIf(hostoslist=no_match(["linux"])) - def test_symlink_paths_set_procselfcwd(self): - os.chdir(self.getBuildDir()) - pwd_symlink = '/proc/self/cwd' - self.doBuild(pwd_symlink) - self.runCmd( - "settings set %s %s" % - (_COMP_DIR_SYM_LINK_PROP, pwd_symlink)) - src_path = self.getBuildArtifact(_SRC_FILE) - # /proc/self/cwd points to a realpath form of current directory. - src_path = os.path.realpath(src_path) - lldbutil.run_break_set_by_file_and_line(self, src_path, self.line) - - @skipIf(hostoslist=["windows"]) - def test_symlink_paths_unset(self): - pwd_symlink = self.create_src_symlink() - self.doBuild(pwd_symlink) - self.runCmd('settings clear ' + _COMP_DIR_SYM_LINK_PROP) - src_path = self.getBuildArtifact(_SRC_FILE) - self.assertRaises( - AssertionError, - lldbutil.run_break_set_by_file_and_line, - self, - src_path, - self.line) - - def create_src_symlink(self): - pwd_symlink = self.getBuildArtifact('pwd_symlink') - if os.path.exists(pwd_symlink): - os.unlink(pwd_symlink) - os.symlink(self.getBuildDir(), pwd_symlink) - self.addTearDownHook(lambda: os.remove(pwd_symlink)) - return pwd_symlink - - def doBuild(self, pwd_symlink): - self.build(None, None, {'PWD': pwd_symlink}) - - exe = self.getBuildArtifact(_EXE_NAME) - self.runCmd('file ' + exe, CURRENT_EXECUTABLE_SET) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/comp_dir_symlink/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/comp_dir_symlink/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/comp_dir_symlink/main.cpp @@ -1,12 +0,0 @@ -//===-- main.cpp ------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -int main (int argc, char const *argv[]) -{ - return 0; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/consecutive_breakpoints/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/consecutive_breakpoints/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/consecutive_breakpoints/Makefile @@ -1,9 +0,0 @@ -LEVEL = ../../../make - -CXX_SOURCES := main.cpp - -ifneq (,$(findstring icc,$(CC))) - CXXFLAGS += -debug inline-debug-info -endif - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/consecutive_breakpoints/TestConsecutiveBreakpoints.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/consecutive_breakpoints/TestConsecutiveBreakpoints.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/consecutive_breakpoints/TestConsecutiveBreakpoints.py @@ -1,104 +0,0 @@ -""" -Test that we handle breakpoints on consecutive instructions correctly. -""" - -from __future__ import print_function - - -import unittest2 -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class ConsecutiveBreakpointsTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def prepare_test(self): - self.build() - - (self.target, self.process, self.thread, bkpt) = lldbutil.run_to_source_breakpoint( - self, "Set breakpoint here", lldb.SBFileSpec("main.cpp")) - - # Set breakpoint to the next instruction - frame = self.thread.GetFrameAtIndex(0) - - address = frame.GetPCAddress() - instructions = self.target.ReadInstructions(address, 2) - self.assertTrue(len(instructions) == 2) - self.bkpt_address = instructions[1].GetAddress() - self.breakpoint2 = self.target.BreakpointCreateByAddress( - self.bkpt_address.GetLoadAddress(self.target)) - self.assertTrue( - self.breakpoint2 and self.breakpoint2.GetNumLocations() == 1, - VALID_BREAKPOINT) - - def finish_test(self): - # Run the process until termination - self.process.Continue() - self.assertEquals(self.process.GetState(), lldb.eStateExited) - - @no_debug_info_test - def test_continue(self): - """Test that continue stops at the second breakpoint.""" - self.prepare_test() - - self.process.Continue() - self.assertEquals(self.process.GetState(), lldb.eStateStopped) - # We should be stopped at the second breakpoint - self.thread = lldbutil.get_one_thread_stopped_at_breakpoint( - self.process, self.breakpoint2) - self.assertIsNotNone( - self.thread, - "Expected one thread to be stopped at breakpoint 2") - - self.finish_test() - - @no_debug_info_test - def test_single_step(self): - """Test that single step stops at the second breakpoint.""" - self.prepare_test() - - step_over = False - self.thread.StepInstruction(step_over) - - self.assertEquals(self.process.GetState(), lldb.eStateStopped) - self.assertEquals( - self.thread.GetFrameAtIndex(0).GetPCAddress().GetLoadAddress( - self.target), self.bkpt_address.GetLoadAddress( - self.target)) - self.thread = lldbutil.get_one_thread_stopped_at_breakpoint( - self.process, self.breakpoint2) - self.assertIsNotNone( - self.thread, - "Expected one thread to be stopped at breakpoint 2") - - self.finish_test() - - @no_debug_info_test - def test_single_step_thread_specific(self): - """Test that single step stops, even though the second breakpoint is not valid.""" - self.prepare_test() - - # Choose a thread other than the current one. A non-existing thread is - # fine. - thread_index = self.process.GetNumThreads() + 1 - self.assertFalse(self.process.GetThreadAtIndex(thread_index).IsValid()) - self.breakpoint2.SetThreadIndex(thread_index) - - step_over = False - self.thread.StepInstruction(step_over) - - self.assertEquals(self.process.GetState(), lldb.eStateStopped) - self.assertEquals( - self.thread.GetFrameAtIndex(0).GetPCAddress().GetLoadAddress( - self.target), self.bkpt_address.GetLoadAddress( - self.target)) - self.assertEquals( - self.thread.GetStopReason(), - lldb.eStopReasonPlanComplete, - "Stop reason should be 'plan complete'") - - self.finish_test() Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/consecutive_breakpoints/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/consecutive_breakpoints/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/consecutive_breakpoints/main.cpp @@ -1,18 +0,0 @@ -//===-- main.cpp ------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -int -main(int argc, char const *argv[]) -{ - int a = 0; - int b = 1; - a = b + 1; // Set breakpoint here - b = a + 1; - return 0; -} - Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/cpp/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/cpp/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/cpp/Makefile @@ -1,9 +0,0 @@ -LEVEL = ../../../make - -CXX_SOURCES := main.cpp - -ifneq (,$(findstring icc,$(CC))) - CXXFLAGS += -debug inline-debug-info -endif - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/cpp/TestCPPBreakpointLocations.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/cpp/TestCPPBreakpointLocations.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/cpp/TestCPPBreakpointLocations.py @@ -1,112 +0,0 @@ -""" -Test lldb breakpoint ids. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestCPPBreakpointLocations(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24764") - def test(self): - self.build() - self.breakpoint_id_tests() - - def verify_breakpoint_locations(self, target, bp_dict): - - name = bp_dict['name'] - names = bp_dict['loc_names'] - bp = target.BreakpointCreateByName(name) - self.assertEquals( - bp.GetNumLocations(), - len(names), - "Make sure we find the right number of breakpoint locations") - - bp_loc_names = list() - for bp_loc in bp: - bp_loc_names.append(bp_loc.GetAddress().GetFunction().GetName()) - - for name in names: - found = name in bp_loc_names - if not found: - print("Didn't find '%s' in: %s" % (name, bp_loc_names)) - self.assertTrue(found, "Make sure we find all required locations") - - def breakpoint_id_tests(self): - - # Create a target by the debugger. - exe = self.getBuildArtifact("a.out") - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, VALID_TARGET) - bp_dicts = [ - {'name': 'func1', 'loc_names': ['a::c::func1()', 'b::c::func1()']}, - {'name': 'func2', 'loc_names': ['a::c::func2()', 'c::d::func2()']}, - {'name': 'func3', 'loc_names': ['a::c::func3()', 'b::c::func3()', 'c::d::func3()']}, - {'name': 'c::func1', 'loc_names': ['a::c::func1()', 'b::c::func1()']}, - {'name': 'c::func2', 'loc_names': ['a::c::func2()']}, - {'name': 'c::func3', 'loc_names': ['a::c::func3()', 'b::c::func3()']}, - {'name': 'a::c::func1', 'loc_names': ['a::c::func1()']}, - {'name': 'b::c::func1', 'loc_names': ['b::c::func1()']}, - {'name': 'c::d::func2', 'loc_names': ['c::d::func2()']}, - {'name': 'a::c::func1()', 'loc_names': ['a::c::func1()']}, - {'name': 'b::c::func1()', 'loc_names': ['b::c::func1()']}, - {'name': 'c::d::func2()', 'loc_names': ['c::d::func2()']}, - ] - - for bp_dict in bp_dicts: - self.verify_breakpoint_locations(target, bp_dict) - - @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24764") - def test_destructors(self): - self.build() - exe = self.getBuildArtifact("a.out") - target = self.dbg.CreateTarget(exe) - - # Don't skip prologue, so we can check the breakpoint address more - # easily - self.runCmd("settings set target.skip-prologue false") - try: - names = ['~c', 'c::~c', 'c::~c()'] - loc_names = {'a::c::~c()', 'b::c::~c()'} - # TODO: For windows targets we should put windows mangled names - # here - symbols = [ - '_ZN1a1cD1Ev', - '_ZN1a1cD2Ev', - '_ZN1b1cD1Ev', - '_ZN1b1cD2Ev'] - - for name in names: - bp = target.BreakpointCreateByName(name) - - bp_loc_names = {bp_loc.GetAddress().GetFunction().GetName() - for bp_loc in bp} - self.assertEquals( - bp_loc_names, - loc_names, - "Breakpoint set on the correct symbol") - - bp_addresses = {bp_loc.GetLoadAddress() for bp_loc in bp} - symbol_addresses = set() - for symbol in symbols: - sc_list = target.FindSymbols(symbol, lldb.eSymbolTypeCode) - self.assertEquals( - sc_list.GetSize(), 1, "Found symbol " + symbol) - symbol = sc_list.GetContextAtIndex(0).GetSymbol() - symbol_addresses.add( - symbol.GetStartAddress().GetLoadAddress(target)) - - self.assertEquals( - symbol_addresses, - bp_addresses, - "Breakpoint set on correct address") - finally: - self.runCmd("settings clear target.skip-prologue") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/cpp/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/cpp/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/cpp/main.cpp @@ -1,82 +0,0 @@ -//===-- main.cpp ------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -#include -#include - -namespace a { - class c { - public: - c(); - ~c(); - void func1() - { - puts (__PRETTY_FUNCTION__); - } - void func2() - { - puts (__PRETTY_FUNCTION__); - } - void func3() - { - puts (__PRETTY_FUNCTION__); - } - }; - - c::c() {} - c::~c() {} -} - -namespace b { - class c { - public: - c(); - ~c(); - void func1() - { - puts (__PRETTY_FUNCTION__); - } - void func3() - { - puts (__PRETTY_FUNCTION__); - } - }; - - c::c() {} - c::~c() {} -} - -namespace c { - class d { - public: - d () {} - ~d() {} - void func2() - { - puts (__PRETTY_FUNCTION__); - } - void func3() - { - puts (__PRETTY_FUNCTION__); - } - }; -} - -int main (int argc, char const *argv[]) -{ - a::c ac; - b::c bc; - c::d cd; - ac.func1(); - ac.func2(); - ac.func3(); - bc.func1(); - bc.func3(); - cd.func2(); - cd.func3(); - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/cpp_exception/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/cpp_exception/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/cpp_exception/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/cpp_exception/TestCPPExceptionBreakpoint.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/cpp_exception/TestCPPExceptionBreakpoint.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/cpp_exception/TestCPPExceptionBreakpoint.py @@ -1,52 +0,0 @@ -""" -Test that you can set breakpoint and hit the C++ language exception breakpoint -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestCPPExceptionBreakpoint (TestBase): - - mydir = TestBase.compute_mydir(__file__) - my_var = 10 - - @add_test_categories(['pyapi']) - @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24538") - @expectedFailureNetBSD - def test_cpp_exception_breakpoint(self): - """Test setting and hitting the C++ exception breakpoint.""" - self.build() - self.do_cpp_exception_bkpt() - - def setUp(self): - TestBase.setUp(self) - self.main_source = "main.c" - self.main_source_spec = lldb.SBFileSpec(self.main_source) - - def do_cpp_exception_bkpt(self): - exe = self.getBuildArtifact("a.out") - error = lldb.SBError() - - self.target = self.dbg.CreateTarget(exe) - self.assertTrue(self.target, VALID_TARGET) - - exception_bkpt = self.target.BreakpointCreateForException( - lldb.eLanguageTypeC_plus_plus, False, True) - self.assertTrue( - exception_bkpt.IsValid(), - "Created exception breakpoint.") - - process = self.target.LaunchSimple( - None, None, self.get_process_working_directory()) - self.assertTrue(process, PROCESS_IS_VALID) - - thread_list = lldbutil.get_threads_stopped_at_breakpoint( - process, exception_bkpt) - self.assertTrue(len(thread_list) == 1, - "One thread stopped at the exception breakpoint.") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/cpp_exception/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/cpp_exception/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/cpp_exception/main.cpp @@ -1,13 +0,0 @@ -#include - -void -throws_int () -{ - throw 5; -} - -int -main () -{ - throws_int(); -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/debugbreak/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/debugbreak/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/debugbreak/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/debugbreak/TestDebugBreak.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/debugbreak/TestDebugBreak.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/debugbreak/TestDebugBreak.py @@ -1,58 +0,0 @@ -""" -Test embedded breakpoints, like `asm int 3;` in x86 or or `__debugbreak` on Windows. -""" - -from __future__ import print_function - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class DebugBreakTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @skipIf(archs=no_match(["i386", "i686", "x86_64"])) - @no_debug_info_test - def test_asm_int_3(self): - """Test that intrinsics like `__debugbreak();` and `asm {"int3"}` are treated like breakpoints.""" - self.build() - exe = self.getBuildArtifact("a.out") - - # Run the program. - target = self.dbg.CreateTarget(exe) - process = target.LaunchSimple( - None, None, self.get_process_working_directory()) - - # We've hit the first stop, so grab the frame. - self.assertEqual(process.GetState(), lldb.eStateStopped) - stop_reason = lldb.eStopReasonException if (lldbplatformutil.getPlatform( - ) == "windows" or lldbplatformutil.getPlatform() == "macosx") else lldb.eStopReasonSignal - thread = lldbutil.get_stopped_thread(process, stop_reason) - self.assertIsNotNone( - thread, "Unable to find thread stopped at the __debugbreak()") - frame = thread.GetFrameAtIndex(0) - - # We should be in funciton 'bar'. - self.assertTrue(frame.IsValid()) - function_name = frame.GetFunctionName() - self.assertTrue('bar' in function_name, - "Unexpected function name {}".format(function_name)) - - # We should be able to evaluate the parameter foo. - value = frame.EvaluateExpression('*foo') - self.assertEqual(value.GetValueAsSigned(), 42) - - # The counter should be 1 at the first stop and increase by 2 for each - # subsequent stop. - counter = 1 - while counter < 20: - value = frame.EvaluateExpression('count') - self.assertEqual(value.GetValueAsSigned(), counter) - counter += 2 - process.Continue() - - # The inferior should exit after the last iteration. - self.assertEqual(process.GetState(), lldb.eStateExited) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/debugbreak/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/debugbreak/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/debugbreak/main.c @@ -1,29 +0,0 @@ -#ifdef _MSC_VER -#include -#define BREAKPOINT_INTRINSIC() __debugbreak() -#else -#define BREAKPOINT_INTRINSIC() __asm__ __volatile__ ("int3") -#endif - -int -bar(int const *foo) -{ - int count = 0, i = 0; - for (; i < 10; ++i) - { - count += 1; - BREAKPOINT_INTRINSIC(); - count += 1; - } - return *foo; -} - -int -main(int argc, char **argv) -{ - int foo = 42; - bar(&foo); - return 0; -} - - Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/dummy_target_breakpoints/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/dummy_target_breakpoints/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/dummy_target_breakpoints/Makefile @@ -1,9 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c - -ifneq (,$(findstring icc,$(CC))) - CFLAGS += -debug inline-debug-info -endif - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/dummy_target_breakpoints/TestBreakpointsWithNoTargets.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/dummy_target_breakpoints/TestBreakpointsWithNoTargets.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/dummy_target_breakpoints/TestBreakpointsWithNoTargets.py @@ -1,72 +0,0 @@ -""" -Test breakpoint commands set before we have a target -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil - - -class BreakpointInDummyTarget (TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def test(self): - """Test breakpoint set before we have a target. """ - self.build() - self.dummy_breakpoint_test() - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to break inside main(). - self.line = line_number('main.c', 'Set a breakpoint on this line.') - self.line2 = line_number('main.c', 'Set another on this line.') - - def dummy_breakpoint_test(self): - """Test breakpoint set before we have a target. """ - - # This should create a breakpoint with 3 locations. - lldbutil.run_break_set_by_file_and_line( - self, "main.c", self.line, num_expected_locations=0) - lldbutil.run_break_set_by_file_and_line( - self, "main.c", self.line2, num_expected_locations=0) - - # This is the function to remove breakpoints from the dummy target - # to get a clean slate for the next test case. - def cleanup(): - self.runCmd('breakpoint delete -D -f', check=False) - self.runCmd('breakpoint list', check=False) - - # Execute the cleanup function during test case tear down. - self.addTearDownHook(cleanup) - - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # The breakpoint list should show 3 locations. - self.expect( - "breakpoint list -f", - "Breakpoint locations shown correctly", - substrs=[ - "1: file = 'main.c', line = %d, exact_match = 0, locations = 1" % - self.line, - "2: file = 'main.c', line = %d, exact_match = 0, locations = 1" % - self.line2]) - - # Run the program. - self.runCmd("run", RUN_SUCCEEDED) - - # Stopped once. - self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, - substrs=["stop reason = breakpoint 1."]) - - # Continue the program, there should be another stop. - self.runCmd("process continue") - - # Stopped again. - self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, - substrs=["stop reason = breakpoint 2."]) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/dummy_target_breakpoints/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/dummy_target_breakpoints/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/dummy_target_breakpoints/main.c @@ -1,11 +0,0 @@ -#include - -int -main (int argc, char **argv) -{ - printf ("Set a breakpoint on this line.\n"); - - return 0; // Set another on this line. -} - - Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/Makefile @@ -1,7 +0,0 @@ -LEVEL = ../../../make - -DYLIB_NAME := foo -DYLIB_CXX_SOURCES := foo.cpp -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/TestBreakpointInGlobalConstructor.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/TestBreakpointInGlobalConstructor.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/TestBreakpointInGlobalConstructor.py @@ -1,47 +0,0 @@ -""" -Test that we can hit breakpoints in global constructors -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestBreakpointInGlobalConstructors(TestBase): - - mydir = TestBase.compute_mydir(__file__) - NO_DEBUG_INFO_TESTCASE = True - - @expectedFailureNetBSD - def test(self): - self.build() - self.line_foo = line_number('foo.cpp', '// !BR_foo') - self.line_main = line_number('main.cpp', '// !BR_main') - - target = self.dbg.CreateTarget(self.getBuildArtifact("a.out")) - self.assertTrue(target, VALID_TARGET) - - env= self.registerSharedLibrariesWithTarget(target, ["foo"]) - - bp_main = lldbutil.run_break_set_by_file_and_line( - self, 'main.cpp', self.line_main) - - bp_foo = lldbutil.run_break_set_by_file_and_line( - self, 'foo.cpp', self.line_foo, num_expected_locations=-2) - - process = target.LaunchSimple( - None, env, self.get_process_working_directory()) - - self.assertIsNotNone( - lldbutil.get_one_thread_stopped_at_breakpoint_id( - self.process(), bp_foo)) - - self.runCmd("continue") - - self.assertIsNotNone( - lldbutil.get_one_thread_stopped_at_breakpoint_id( - self.process(), bp_main)) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/foo.h =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/foo.h +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/foo.h @@ -1,11 +0,0 @@ -#ifndef FOO_H -#define FOO_H - -struct LLDB_TEST_API Foo { - Foo(); - int x; -}; - -extern LLDB_TEST_API Foo FooObj; - -#endif Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/foo.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/foo.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/foo.cpp @@ -1,7 +0,0 @@ -#include "foo.h" - -Foo::Foo() : x(42) { - bool some_code = x == 42; // !BR_foo -} - -Foo FooObj; Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/main.cpp @@ -1,14 +0,0 @@ -#include "foo.h" - -struct Main { - Main(); - int x; -}; - -Main::Main() : x(47) { - bool some_code = x == 47; // !BR_main -} - -Main MainObj; - -int main() { return MainObj.x + FooObj.x; } Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/hardware_breakpoints/hardware_breakpoint_on_multiple_threads/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/hardware_breakpoints/hardware_breakpoint_on_multiple_threads/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/hardware_breakpoints/hardware_breakpoint_on_multiple_threads/Makefile @@ -1,6 +0,0 @@ -LEVEL = ../../../../make - -ENABLE_THREADS := YES -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/hardware_breakpoints/hardware_breakpoint_on_multiple_threads/TestHWBreakMultiThread.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/hardware_breakpoints/hardware_breakpoint_on_multiple_threads/TestHWBreakMultiThread.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/hardware_breakpoints/hardware_breakpoint_on_multiple_threads/TestHWBreakMultiThread.py @@ -1,105 +0,0 @@ -""" -Test hardware breakpoints for multiple threads. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -# Hardware breakpoints are supported only by platforms mentioned in oslist. -@skipUnlessPlatform(oslist=['linux']) -class HardwareBreakpointMultiThreadTestCase(TestBase): - NO_DEBUG_INFO_TESTCASE = True - - mydir = TestBase.compute_mydir(__file__) - - # LLDB supports hardware breakpoints for arm and aarch64 architectures. - @skipIf(archs=no_match(['arm', 'aarch64'])) - def test_hw_break_set_delete_multi_thread(self): - self.build() - self.setTearDownCleanup() - self.break_multi_thread('delete') - - # LLDB supports hardware breakpoints for arm and aarch64 architectures. - @skipIf(archs=no_match(['arm', 'aarch64'])) - def test_hw_break_set_disable_multi_thread(self): - self.build() - self.setTearDownCleanup() - self.break_multi_thread('disable') - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Our simple source filename. - self.source = 'main.cpp' - # Find the line number to break inside main(). - self.first_stop = line_number( - self.source, 'Starting thread creation with hardware breakpoint set') - - def break_multi_thread(self, removal_type): - """Test that lldb hardware breakpoints work for multiple threads.""" - self.runCmd("file " + self.getBuildArtifact("a.out"), - CURRENT_EXECUTABLE_SET) - - # Stop in main before creating any threads. - lldbutil.run_break_set_by_file_and_line( - self, None, self.first_stop, num_expected_locations=1) - - # Run the program. - self.runCmd("run", RUN_SUCCEEDED) - - # We should be stopped again due to the breakpoint. - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', - 'stop reason = breakpoint']) - - # Now set a hardware breakpoint in thread function. - self.expect("breakpoint set -b hw_break_function --hardware", - substrs=[ - 'Breakpoint', - 'hw_break_function', - 'address = 0x']) - - # We should stop in hw_break_function function for 4 threads. - count = 0 - - while count < 2 : - - self.runCmd("process continue") - - # We should be stopped in hw_break_function - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs=[ - 'stop reason = breakpoint', - 'hw_break_function']) - - # Continue the loop and test that we are stopped 4 times. - count += 1 - - if removal_type == 'delete': - self.runCmd("settings set auto-confirm true") - - # Now 'breakpoint delete' should just work fine without confirmation - # prompt from the command interpreter. - self.expect("breakpoint delete", - startstr="All breakpoints removed") - - # Restore the original setting of auto-confirm. - self.runCmd("settings clear auto-confirm") - - elif removal_type == 'disable': - self.expect("breakpoint disable", - startstr="All breakpoints disabled.") - - # Continue. Program should exit without stopping anywhere. - self.runCmd("process continue") - - # Process should have stopped and exited with status = 0 - self.expect("process status", PROCESS_STOPPED, - patterns=['Process .* exited with status = 0']) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/hardware_breakpoints/hardware_breakpoint_on_multiple_threads/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/hardware_breakpoints/hardware_breakpoint_on_multiple_threads/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/hardware_breakpoints/hardware_breakpoint_on_multiple_threads/main.cpp @@ -1,50 +0,0 @@ -//===-- main.cpp ------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include -#include -#include -#include -#include - -#define NUM_OF_THREADS 4 - -std::mutex hw_break_mutex; - -void -hw_break_function (uint32_t thread_index) { - printf ("%s called by Thread #%u...\n", __FUNCTION__, thread_index); -} - - -void -thread_func (uint32_t thread_index) { - printf ("%s (thread index = %u) starting...\n", __FUNCTION__, thread_index); - - hw_break_mutex.lock(); - - hw_break_function(thread_index); // Call hw_break_function - - hw_break_mutex.unlock(); -} - - -int main (int argc, char const *argv[]) -{ - std::thread threads[NUM_OF_THREADS]; - - printf ("Starting thread creation with hardware breakpoint set...\n"); - - for (auto &thread : threads) - thread = std::thread{thread_func, std::distance(threads, &thread)}; - - for (auto &thread : threads) - thread.join(); - - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/inlined_breakpoints/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/inlined_breakpoints/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/inlined_breakpoints/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -CXX_SOURCES := int.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/inlined_breakpoints/TestInlinedBreakpoints.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/inlined_breakpoints/TestInlinedBreakpoints.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/inlined_breakpoints/TestInlinedBreakpoints.py @@ -1,67 +0,0 @@ -""" -Test that inlined breakpoints (breakpoint set on a file/line included from -another source file) works correctly. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil - - -class InlinedBreakpointsTestCase(TestBase): - """Bug fixed: rdar://problem/8464339""" - - mydir = TestBase.compute_mydir(__file__) - - def test_with_run_command(self): - """Test 'b basic_types.cpp:176' does break (where int.cpp includes basic_type.cpp).""" - self.build() - self.inlined_breakpoints() - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to break inside basic_type.cpp. - self.line = line_number( - 'basic_type.cpp', - '// Set break point at this line.') - - def inlined_breakpoints(self): - """Test 'b basic_types.cpp:176' does break (where int.cpp includes basic_type.cpp).""" - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # With the inline-breakpoint-strategy, our file+line breakpoint should - # not resolve to a location. - self.runCmd('settings set target.inline-breakpoint-strategy headers') - - # Set a breakpoint and fail because it is in an inlined source - # implemenation file - lldbutil.run_break_set_by_file_and_line( - self, "basic_type.cpp", self.line, num_expected_locations=0) - - # Now enable breakpoints in implementation files and see the breakpoint - # set succeed - self.runCmd('settings set target.inline-breakpoint-strategy always') - # And add hooks to restore the settings during tearDown(). - self.addTearDownHook(lambda: self.runCmd( - "settings set target.inline-breakpoint-strategy always")) - - lldbutil.run_break_set_by_file_and_line( - self, - "basic_type.cpp", - self.line, - num_expected_locations=1, - loc_exact=True) - - self.runCmd("run", RUN_SUCCEEDED) - - # The stop reason of the thread should be breakpoint. - # And it should break at basic_type.cpp:176. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', - 'stop reason = breakpoint', - 'basic_type.cpp:%d' % self.line]) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/inlined_breakpoints/basic_type.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/inlined_breakpoints/basic_type.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/inlined_breakpoints/basic_type.cpp @@ -1,178 +0,0 @@ -// This file must have the following defined before it is included: -// T defined to the type to test (int, float, etc) -// T_CSTR a C string representation of the type T ("int", "float") -// T_VALUE_1 defined to a valid initializer value for TEST_TYPE (7 for int, 2.0 for float) -// T_VALUE_2, T_VALUE_3, T_VALUE_4 defined to a valid initializer value for TEST_TYPE that is different from TEST_VALUE_1 -// T_PRINTF_FORMAT defined if T can be printed with printf -// -// An example for integers is below -#if 0 - -#define T int -#define T_CSTR "int" -#define T_VALUE_1 11001110 -#define T_VALUE_2 22002220 -#define T_VALUE_3 33003330 -#define T_VALUE_4 44044440 -#define T_PRINTF_FORMAT "%i" - -#include "basic_type.cpp" - -#endif - -#include -#include - -class a_class -{ -public: - a_class (const T& a, const T& b) : - m_a (a), - m_b (b) - { - } - - ~a_class () - { - } - - const T& - get_a() - { - return m_a; - } - - void - set_a (const T& a) - { - m_a = a; - } - - const T& - get_b() - { - return m_b; - } - - void - set_b (const T& b) - { - m_b = b; - } - -protected: - T m_a; - T m_b; -}; - -typedef struct a_struct_tag { - T a; - T b; -} a_struct_t; - - -typedef union a_union_zero_tag { - T a; - double a_double; -} a_union_zero_t; - -typedef struct a_union_nonzero_tag { - double a_double; - a_union_zero_t u; -} a_union_nonzero_t; - - -void Puts(char const *msg) -{ - std::puts(msg); -} - -int -main (int argc, char const *argv[]) -{ - T a = T_VALUE_1; - T* a_ptr = &a; - T& a_ref = a; - T a_array_bounded[2] = { T_VALUE_1, T_VALUE_2 }; - T a_array_unbounded[] = { T_VALUE_1, T_VALUE_2 }; - - a_class a_class_instance (T_VALUE_1, T_VALUE_2); - a_class *a_class_ptr = &a_class_instance; - a_class &a_class_ref = a_class_instance; - - a_struct_t a_struct = { T_VALUE_1, T_VALUE_2 }; - a_struct_t *a_struct_ptr = &a_struct; - a_struct_t &a_struct_ref = a_struct; - - // Create a union with type T at offset zero - a_union_zero_t a_union_zero; - a_union_zero.a = T_VALUE_1; - a_union_zero_t *a_union_zero_ptr = &a_union_zero; - a_union_zero_t &a_union_zero_ref = a_union_zero; - - // Create a union with type T at a non-zero offset - a_union_nonzero_t a_union_nonzero; - a_union_nonzero.u.a = T_VALUE_1; - a_union_nonzero_t *a_union_nonzero_ptr = &a_union_nonzero; - a_union_nonzero_t &a_union_nonzero_ref = a_union_nonzero; - - a_struct_t a_struct_array_bounded[2] = {{ T_VALUE_1, T_VALUE_2 }, { T_VALUE_3, T_VALUE_4 }}; - a_struct_t a_struct_array_unbounded[] = {{ T_VALUE_1, T_VALUE_2 }, { T_VALUE_3, T_VALUE_4 }}; - a_union_zero_t a_union_zero_array_bounded[2]; - a_union_zero_array_bounded[0].a = T_VALUE_1; - a_union_zero_array_bounded[1].a = T_VALUE_2; - a_union_zero_t a_union_zero_array_unbounded[] = {{ T_VALUE_1 }, { T_VALUE_2 }}; - -#ifdef T_PRINTF_FORMAT - std::printf ("%s: a = '" T_PRINTF_FORMAT "'\n", T_CSTR, a); - std::printf ("%s*: %p => *a_ptr = '" T_PRINTF_FORMAT "'\n", T_CSTR, a_ptr, *a_ptr); - std::printf ("%s&: @%p => a_ref = '" T_PRINTF_FORMAT "'\n", T_CSTR, &a_ref, a_ref); - - std::printf ("%s[2]: a_array_bounded[0] = '" T_PRINTF_FORMAT "'\n", T_CSTR, a_array_bounded[0]); - std::printf ("%s[2]: a_array_bounded[1] = '" T_PRINTF_FORMAT "'\n", T_CSTR, a_array_bounded[1]); - - std::printf ("%s[]: a_array_unbounded[0] = '" T_PRINTF_FORMAT "'\n", T_CSTR, a_array_unbounded[0]); - std::printf ("%s[]: a_array_unbounded[1] = '" T_PRINTF_FORMAT "'\n", T_CSTR, a_array_unbounded[1]); - - std::printf ("(a_class) a_class_instance.m_a = '" T_PRINTF_FORMAT "'\n", a_class_instance.get_a()); - std::printf ("(a_class) a_class_instance.m_b = '" T_PRINTF_FORMAT "'\n", a_class_instance.get_b()); - std::printf ("(a_class*) a_class_ptr = %p, a_class_ptr->m_a = '" T_PRINTF_FORMAT "'\n", a_class_ptr, a_class_ptr->get_a()); - std::printf ("(a_class*) a_class_ptr = %p, a_class_ptr->m_b = '" T_PRINTF_FORMAT "'\n", a_class_ptr, a_class_ptr->get_b()); - std::printf ("(a_class&) a_class_ref = %p, a_class_ref.m_a = '" T_PRINTF_FORMAT "'\n", &a_class_ref, a_class_ref.get_a()); - std::printf ("(a_class&) a_class_ref = %p, a_class_ref.m_b = '" T_PRINTF_FORMAT "'\n", &a_class_ref, a_class_ref.get_b()); - - std::printf ("(a_struct_t) a_struct.a = '" T_PRINTF_FORMAT "'\n", a_struct.a); - std::printf ("(a_struct_t) a_struct.b = '" T_PRINTF_FORMAT "'\n", a_struct.b); - std::printf ("(a_struct_t*) a_struct_ptr = %p, a_struct_ptr->a = '" T_PRINTF_FORMAT "'\n", a_struct_ptr, a_struct_ptr->a); - std::printf ("(a_struct_t*) a_struct_ptr = %p, a_struct_ptr->b = '" T_PRINTF_FORMAT "'\n", a_struct_ptr, a_struct_ptr->b); - std::printf ("(a_struct_t&) a_struct_ref = %p, a_struct_ref.a = '" T_PRINTF_FORMAT "'\n", &a_struct_ref, a_struct_ref.a); - std::printf ("(a_struct_t&) a_struct_ref = %p, a_struct_ref.b = '" T_PRINTF_FORMAT "'\n", &a_struct_ref, a_struct_ref.b); - - std::printf ("(a_union_zero_t) a_union_zero.a = '" T_PRINTF_FORMAT "'\n", a_union_zero.a); - std::printf ("(a_union_zero_t*) a_union_zero_ptr = %p, a_union_zero_ptr->a = '" T_PRINTF_FORMAT "'\n", a_union_zero_ptr, a_union_zero_ptr->a); - std::printf ("(a_union_zero_t&) a_union_zero_ref = %p, a_union_zero_ref.a = '" T_PRINTF_FORMAT "'\n", &a_union_zero_ref, a_union_zero_ref.a); - - std::printf ("(a_union_nonzero_t) a_union_nonzero.u.a = '" T_PRINTF_FORMAT "'\n", a_union_nonzero.u.a); - std::printf ("(a_union_nonzero_t*) a_union_nonzero_ptr = %p, a_union_nonzero_ptr->u.a = '" T_PRINTF_FORMAT "'\n", a_union_nonzero_ptr, a_union_nonzero_ptr->u.a); - std::printf ("(a_union_nonzero_t&) a_union_nonzero_ref = %p, a_union_nonzero_ref.u.a = '" T_PRINTF_FORMAT "'\n", &a_union_nonzero_ref, a_union_nonzero_ref.u.a); - - std::printf ("(a_struct_t[2]) a_struct_array_bounded[0].a = '" T_PRINTF_FORMAT "'\n", a_struct_array_bounded[0].a); - std::printf ("(a_struct_t[2]) a_struct_array_bounded[0].b = '" T_PRINTF_FORMAT "'\n", a_struct_array_bounded[0].b); - std::printf ("(a_struct_t[2]) a_struct_array_bounded[1].a = '" T_PRINTF_FORMAT "'\n", a_struct_array_bounded[1].a); - std::printf ("(a_struct_t[2]) a_struct_array_bounded[1].b = '" T_PRINTF_FORMAT "'\n", a_struct_array_bounded[1].b); - - std::printf ("(a_struct_t[]) a_struct_array_unbounded[0].a = '" T_PRINTF_FORMAT "'\n", a_struct_array_unbounded[0].a); - std::printf ("(a_struct_t[]) a_struct_array_unbounded[0].b = '" T_PRINTF_FORMAT "'\n", a_struct_array_unbounded[0].b); - std::printf ("(a_struct_t[]) a_struct_array_unbounded[1].a = '" T_PRINTF_FORMAT "'\n", a_struct_array_unbounded[1].a); - std::printf ("(a_struct_t[]) a_struct_array_unbounded[1].b = '" T_PRINTF_FORMAT "'\n", a_struct_array_unbounded[1].b); - - std::printf ("(a_union_zero_t[2]) a_union_zero_array_bounded[0].a = '" T_PRINTF_FORMAT "'\n", a_union_zero_array_bounded[0].a); - std::printf ("(a_union_zero_t[2]) a_union_zero_array_bounded[1].a = '" T_PRINTF_FORMAT "'\n", a_union_zero_array_bounded[1].a); - - std::printf ("(a_union_zero_t[]) a_union_zero_array_unbounded[0].a = '" T_PRINTF_FORMAT "'\n", a_union_zero_array_unbounded[0].a); - std::printf ("(a_union_zero_t[]) a_union_zero_array_unbounded[1].a = '" T_PRINTF_FORMAT "'\n", a_union_zero_array_unbounded[1].a); - -#endif - Puts("About to exit, break here to check values..."); // Set break point at this line. - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/inlined_breakpoints/int.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/inlined_breakpoints/int.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/inlined_breakpoints/int.cpp @@ -1,9 +0,0 @@ -#define T int -#define T_CSTR "int" -#define T_VALUE_1 11001110 -#define T_VALUE_2 22002220 -#define T_VALUE_3 33003330 -#define T_VALUE_4 44004440 -#define T_PRINTF_FORMAT "%i" - -#include "basic_type.cpp" Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/Makefile @@ -1,7 +0,0 @@ -LEVEL = ../../../make - -DYLIB_NAME := foo -DYLIB_CXX_SOURCES := foo.cpp -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/TestMoveNearest.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/TestMoveNearest.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/TestMoveNearest.py @@ -1,69 +0,0 @@ -from __future__ import print_function - - -import unittest2 -import lldb -from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil - - -class TestMoveNearest(TestBase): - - mydir = TestBase.compute_mydir(__file__) - NO_DEBUG_INFO_TESTCASE = True - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to break inside main(). - self.line1 = line_number('foo.h', '// !BR1') - self.line2 = line_number('foo.h', '// !BR2') - self.line_between = line_number('main.cpp', "// BR_Between") - print("BR_Between found at", self.line_between) - self.line_main = line_number('main.cpp', '// !BR_main') - - def test(self): - """Test target.move-to-nearest logic""" - - self.build() - target = self.dbg.CreateTarget(self.getBuildArtifact("a.out")) - self.assertTrue(target, VALID_TARGET) - - lldbutil.run_break_set_by_symbol(self, 'main', sym_exact=True) - environment = self.registerSharedLibrariesWithTarget(target, ["foo"]) - process = target.LaunchSimple(None, environment, self.get_process_working_directory()) - self.assertEquals(process.GetState(), lldb.eStateStopped) - - # Regardless of the -m value the breakpoint should have exactly one - # location on the foo functions - self.runCmd("settings set target.move-to-nearest-code true") - lldbutil.run_break_set_by_file_and_line(self, 'foo.h', self.line1, - loc_exact=True, extra_options="-m 1") - lldbutil.run_break_set_by_file_and_line(self, 'foo.h', self.line2, - loc_exact=True, extra_options="-m 1") - - self.runCmd("settings set target.move-to-nearest-code false") - lldbutil.run_break_set_by_file_and_line(self, 'foo.h', self.line1, - loc_exact=True, extra_options="-m 0") - lldbutil.run_break_set_by_file_and_line(self, 'foo.h', self.line2, - loc_exact=True, extra_options="-m 0") - - - # Make sure we set a breakpoint in main with -m 1 for various lines in - # the function declaration - # "int" - lldbutil.run_break_set_by_file_and_line(self, 'main.cpp', - self.line_main-1, extra_options="-m 1") - # "main()" - lldbutil.run_break_set_by_file_and_line(self, 'main.cpp', - self.line_main, extra_options="-m 1") - # "{" - lldbutil.run_break_set_by_file_and_line(self, 'main.cpp', - self.line_main+1, extra_options="-m 1") - # "return .." - lldbutil.run_break_set_by_file_and_line(self, 'main.cpp', - self.line_main+2, extra_options="-m 1") - - # Make sure we don't put move the breakpoint if it is set between two functions: - lldbutil.run_break_set_by_file_and_line(self, 'main.cpp', - self.line_between, extra_options="-m 1", num_expected_locations=0) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/foo.h =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/foo.h +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/foo.h @@ -1,5 +0,0 @@ -inline int foo1() { return 1; } // !BR1 - -inline int foo2() { return 2; } // !BR2 - -LLDB_TEST_API extern int call_foo1(); Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/foo.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/foo.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/foo.cpp @@ -1,3 +0,0 @@ -#include "foo.h" - -int call_foo1() { return foo1(); } Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/main.cpp @@ -1,9 +0,0 @@ -#include "foo.h" - -int call_foo2() { return foo2(); } -// BR_Between -int -main() // !BR_main -{ - return call_foo1() + call_foo2(); -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/objc/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/objc/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/objc/Makefile @@ -1,7 +0,0 @@ -LEVEL = ../../../make - -OBJC_SOURCES := main.m - -include $(LEVEL)/Makefile.rules - -LDFLAGS += -framework Foundation Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/objc/TestObjCBreakpoints.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/objc/TestObjCBreakpoints.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/objc/TestObjCBreakpoints.py @@ -1,130 +0,0 @@ -""" -Test that objective-c constant strings are generated correctly by the expression -parser. -""" - -from __future__ import print_function - - -import shutil -import subprocess -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -@skipUnlessDarwin -class TestObjCBreakpoints(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def test_break(self): - """Test setting Objective-C specific breakpoints (DWARF in .o files).""" - self.build() - self.setTearDownCleanup() - self.check_objc_breakpoints(False) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to break inside main(). - self.main_source = "main.m" - self.line = line_number(self.main_source, '// Set breakpoint here') - - def check_category_breakpoints(self): - name_bp = self.target.BreakpointCreateByName("myCategoryFunction") - selector_bp = self.target.BreakpointCreateByName( - "myCategoryFunction", - lldb.eFunctionNameTypeSelector, - lldb.SBFileSpecList(), - lldb.SBFileSpecList()) - self.assertTrue( - name_bp.GetNumLocations() == selector_bp.GetNumLocations(), - 'Make sure setting a breakpoint by name "myCategoryFunction" sets a breakpoint even though it is in a category') - for bp_loc in selector_bp: - function_name = bp_loc.GetAddress().GetSymbol().GetName() - self.assertTrue( - " myCategoryFunction]" in function_name, - 'Make sure all function names have " myCategoryFunction]" in their names') - - category_bp = self.target.BreakpointCreateByName( - "-[MyClass(MyCategory) myCategoryFunction]") - stripped_bp = self.target.BreakpointCreateByName( - "-[MyClass myCategoryFunction]") - stripped2_bp = self.target.BreakpointCreateByName( - "[MyClass myCategoryFunction]") - self.assertTrue( - category_bp.GetNumLocations() == 1, - "Make sure we can set a breakpoint using a full objective C function name with the category included (-[MyClass(MyCategory) myCategoryFunction])") - self.assertTrue( - stripped_bp.GetNumLocations() == 1, - "Make sure we can set a breakpoint using a full objective C function name without the category included (-[MyClass myCategoryFunction])") - self.assertTrue( - stripped2_bp.GetNumLocations() == 1, - "Make sure we can set a breakpoint using a full objective C function name without the category included ([MyClass myCategoryFunction])") - - def check_objc_breakpoints(self, have_dsym): - """Test constant string generation amd comparison by the expression parser.""" - - # Set debugger into synchronous mode - self.dbg.SetAsync(False) - - # Create a target by the debugger. - exe = self.getBuildArtifact("a.out") - self.target = self.dbg.CreateTarget(exe) - self.assertTrue(self.target, VALID_TARGET) - - #---------------------------------------------------------------------- - # Set breakpoints on all selectors whose name is "count". This should - # catch breakpoints that are both C functions _and_ anything whose - # selector is "count" because just looking at "count" we can't tell - # definitively if the name is a selector or a C function - #---------------------------------------------------------------------- - name_bp = self.target.BreakpointCreateByName("count") - selector_bp = self.target.BreakpointCreateByName( - "count", - lldb.eFunctionNameTypeSelector, - lldb.SBFileSpecList(), - lldb.SBFileSpecList()) - self.assertTrue( - name_bp.GetNumLocations() >= selector_bp.GetNumLocations(), - 'Make sure we get at least the same amount of breakpoints if not more when setting by name "count"') - self.assertTrue( - selector_bp.GetNumLocations() > 50, - 'Make sure we find a lot of "count" selectors') # There are 93 on the latest MacOSX - for bp_loc in selector_bp: - function_name = bp_loc.GetAddress().GetSymbol().GetName() - self.assertTrue( - " count]" in function_name, - 'Make sure all function names have " count]" in their names') - - #---------------------------------------------------------------------- - # Set breakpoints on all selectors whose name is "isEqual:". This should - # catch breakpoints that are only ObjC selectors because no C function - # can end with a : - #---------------------------------------------------------------------- - name_bp = self.target.BreakpointCreateByName("isEqual:") - selector_bp = self.target.BreakpointCreateByName( - "isEqual:", - lldb.eFunctionNameTypeSelector, - lldb.SBFileSpecList(), - lldb.SBFileSpecList()) - self.assertTrue( - name_bp.GetNumLocations() == selector_bp.GetNumLocations(), - 'Make sure setting a breakpoint by name "isEqual:" only sets selector breakpoints') - for bp_loc in selector_bp: - function_name = bp_loc.GetAddress().GetSymbol().GetName() - self.assertTrue( - " isEqual:]" in function_name, - 'Make sure all function names have " isEqual:]" in their names') - - self.check_category_breakpoints() - - if have_dsym: - shutil.rmtree(exe + ".dSYM") - self.assertTrue(subprocess.call( - ['/usr/bin/strip', '-Sx', exe]) == 0, 'stripping dylib succeeded') - - # Check breakpoints again, this time using the symbol table only - self.check_category_breakpoints() Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/objc/main.m =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/objc/main.m +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/objc/main.m @@ -1,98 +0,0 @@ -#import -#include - -@interface MyClass : NSObject -@end - -@implementation MyClass : NSObject -@end - -@implementation MyClass (MyCategory) - - -- (void) myCategoryFunction { - NSLog (@"myCategoryFunction"); -} - -@end - - - -int -Test_Selector () -{ - SEL sel = @selector(length); - printf("sel = %p\n", sel); - // Expressions to test here for selector: - // expression (char *)sel_getName(sel) - // The expression above should return "sel" as it should be just - // a uniqued C string pointer. We were seeing the result pointer being - // truncated with recent LLDBs. - return 0; // Break here for selector: tests -} - -int -Test_NSString (const char *program) -{ - NSString *str = [NSString stringWithFormat:@"Hello from '%s'", program]; - NSLog(@"NSString instance: %@", str); - printf("str = '%s'\n", [str cStringUsingEncoding: [NSString defaultCStringEncoding]]); - printf("[str length] = %zu\n", (size_t)[str length]); - printf("[str description] = %s\n", [[str description] UTF8String]); - id str_id = str; - // Expressions to test here for NSString: - // expression (char *)sel_getName(sel) - // expression [str length] - // expression [str_id length] - // expression [str description] - // expression [str_id description] - // expression str.length - // expression str.description - // expression str = @"new" - // expression str = [NSString stringWithFormat: @"%cew", 'N'] - return 0; // Break here for NSString tests -} - -NSString *my_global_str = NULL; - -int -Test_NSArray () -{ - NSMutableArray *nil_mutable_array = nil; - NSArray *array1 = [NSArray arrayWithObjects: @"array1 object1", @"array1 object2", @"array1 object3", nil]; - NSArray *array2 = [NSArray arrayWithObjects: array1, @"array2 object2", @"array2 object3", nil]; - // Expressions to test here for NSArray: - // expression [nil_mutable_array count] - // expression [array1 count] - // expression array1.count - // expression [array2 count] - // expression array2.count - id obj; - // After each object at index call, use expression and validate object - obj = [array1 objectAtIndex: 0]; // Break here for NSArray tests - obj = [array1 objectAtIndex: 1]; - obj = [array1 objectAtIndex: 2]; - - obj = [array2 objectAtIndex: 0]; - obj = [array2 objectAtIndex: 1]; - obj = [array2 objectAtIndex: 2]; - NSUInteger count = [nil_mutable_array count]; - return 0; -} - - -int main (int argc, char const *argv[]) -{ - NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; - Test_Selector(); // Set breakpoint here - Test_NSArray (); - Test_NSString (argv[0]); - MyClass *my_class = [[MyClass alloc] init]; - [my_class myCategoryFunction]; - printf("sizeof(id) = %zu\n", sizeof(id)); - printf("sizeof(Class) = %zu\n", sizeof(Class)); - printf("sizeof(SEL) = %zu\n", sizeof(SEL)); - - [pool release]; - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/require_hw_breakpoints/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/require_hw_breakpoints/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/require_hw_breakpoints/Makefile @@ -1,9 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c - -ifneq (,$(findstring icc,$(CC))) - CFLAGS += -debug inline-debug-info -endif - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/require_hw_breakpoints/TestRequireHWBreakpoints.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/require_hw_breakpoints/TestRequireHWBreakpoints.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/require_hw_breakpoints/TestRequireHWBreakpoints.py @@ -1,103 +0,0 @@ -""" -Test require hardware breakpoints. -""" - -from __future__ import print_function - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class BreakpointLocationsTestCase(TestBase): - NO_DEBUG_INFO_TESTCASE = True - mydir = TestBase.compute_mydir(__file__) - - def test_breakpoint(self): - """Test regular breakpoints when hardware breakpoints are required.""" - self.build() - exe = self.getBuildArtifact("a.out") - target = self.dbg.CreateTarget(exe) - - self.runCmd("settings set target.require-hardware-breakpoint true") - - breakpoint = target.BreakpointCreateByLocation("main.c", 1) - self.assertTrue(breakpoint.IsHardware()) - - @skipIfWindows - def test_step_range(self): - """Test stepping when hardware breakpoints are required.""" - self.build() - - _, _, thread, _ = lldbutil.run_to_line_breakpoint( - self, lldb.SBFileSpec("main.c"), 1) - - self.runCmd("settings set target.require-hardware-breakpoint true") - - # Ensure we fail in the interpreter. - self.expect("thread step-in") - self.expect("thread step-in", error=True) - - # Ensure we fail when stepping through the API. - error = lldb.SBError() - thread.StepInto('', 4, error) - self.assertTrue(error.Fail()) - self.assertTrue("Could not create hardware breakpoint for thread plan" - in error.GetCString()) - - @skipIfWindows - def test_step_out(self): - """Test stepping out when hardware breakpoints are required.""" - self.build() - - _, _, thread, _ = lldbutil.run_to_line_breakpoint( - self, lldb.SBFileSpec("main.c"), 1) - - self.runCmd("settings set target.require-hardware-breakpoint true") - - # Ensure this fails in the command interpreter. - self.expect("thread step-out", error=True) - - # Ensure we fail when stepping through the API. - error = lldb.SBError() - thread.StepOut(error) - self.assertTrue(error.Fail()) - self.assertTrue("Could not create hardware breakpoint for thread plan" - in error.GetCString()) - - @skipIfWindows - def test_step_over(self): - """Test stepping over when hardware breakpoints are required.""" - self.build() - - _, _, thread, _ = lldbutil.run_to_line_breakpoint( - self, lldb.SBFileSpec("main.c"), 7) - - self.runCmd("settings set target.require-hardware-breakpoint true") - - # Step over doesn't fail immediately but fails later on. - self.expect( - "thread step-over", - error=True, - substrs=[ - 'error: Could not create hardware breakpoint for thread plan.' - ]) - - @skipIfWindows - def test_step_until(self): - """Test stepping until when hardware breakpoints are required.""" - self.build() - - _, _, thread, _ = lldbutil.run_to_line_breakpoint( - self, lldb.SBFileSpec("main.c"), 7) - - self.runCmd("settings set target.require-hardware-breakpoint true") - - self.expect("thread until 5", error=True) - - # Ensure we fail when stepping through the API. - error = thread.StepOverUntil(lldb.SBFrame(), lldb.SBFileSpec(), 5) - self.assertTrue(error.Fail()) - self.assertTrue("Could not create hardware breakpoint for thread plan" - in error.GetCString()) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/require_hw_breakpoints/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/require_hw_breakpoints/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/require_hw_breakpoints/main.c @@ -1,9 +0,0 @@ -int break_on_me() { - int i = 10; - i++; - return i; -} - -int main() { - return break_on_me(); -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/scripted_bkpt/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/scripted_bkpt/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/scripted_bkpt/Makefile @@ -1,6 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c -CFLAGS_EXTRAS += -std=c99 - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/scripted_bkpt/TestScriptedResolver.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/scripted_bkpt/TestScriptedResolver.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/scripted_bkpt/TestScriptedResolver.py @@ -1,197 +0,0 @@ -""" -Test setting breakpoints using a scripted resolver -""" - -from __future__ import print_function - - -import os -import lldb -import lldbsuite.test.lldbutil as lldbutil -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * - - -class TestScriptedResolver(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - NO_DEBUG_INFO_TESTCASE = True - - @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24528") - def test_scripted_resolver(self): - """Use a scripted resolver to set a by symbol name breakpoint""" - self.build() - self.do_test() - - @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24528") - def test_search_depths(self): - """ Make sure we are called at the right depths depending on what we return - from __get_depth__""" - self.build() - self.do_test_depths() - - @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24528") - def test_command_line(self): - """ Make sure we are called at the right depths depending on what we return - from __get_depth__""" - self.build() - self.do_test_cli() - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - - def make_target_and_import(self): - target = lldbutil.run_to_breakpoint_make_target(self) - interp = self.dbg.GetCommandInterpreter() - error = lldb.SBError() - - script_name = os.path.join(self.getSourceDir(), "resolver.py") - source_name = os.path.join(self.getSourceDir(), "main.c") - - command = "command script import " + script_name - result = lldb.SBCommandReturnObject() - interp.HandleCommand(command, result) - self.assertTrue(result.Succeeded(), "com scr imp failed: %s"%(result.GetError())) - return target - - def make_extra_args(self): - json_string = '{"symbol":"break_on_me", "test1": "value1"}' - json_stream = lldb.SBStream() - json_stream.Print(json_string) - extra_args = lldb.SBStructuredData() - error = extra_args.SetFromJSON(json_stream) - self.assertTrue(error.Success(), "Error making SBStructuredData: %s"%(error.GetCString())) - return extra_args - - def do_test(self): - """This reads in a python file and sets a breakpoint using it.""" - - target = self.make_target_and_import() - extra_args = self.make_extra_args() - - file_list = lldb.SBFileSpecList() - module_list = lldb.SBFileSpecList() - - # Make breakpoints with this resolver using different filters, first ones that will take: - right = [] - # one with no file or module spec - this one should fire: - right.append(target.BreakpointCreateFromScript("resolver.Resolver", extra_args, module_list, file_list)) - - # one with the right source file and no module - should also fire: - file_list.Append(lldb.SBFileSpec("main.c")) - right.append(target.BreakpointCreateFromScript("resolver.Resolver", extra_args, module_list, file_list)) - # Make sure the help text shows up in the "break list" output: - self.expect("break list", substrs=["I am a python breakpoint resolver"], msg="Help is listed in break list") - - # one with the right source file and right module - should also fire: - module_list.Append(lldb.SBFileSpec("a.out")) - right.append(target.BreakpointCreateFromScript("resolver.Resolver", extra_args, module_list, file_list)) - - # And one with no source file but the right module: - file_list.Clear() - right.append(target.BreakpointCreateFromScript("resolver.Resolver", extra_args, module_list, file_list)) - - # Make sure these all got locations: - for i in range (0, len(right)): - self.assertTrue(right[i].GetNumLocations() >= 1, "Breakpoint %d has no locations."%(i)) - - # Now some ones that won't take: - - module_list.Clear() - file_list.Clear() - wrong = [] - - # one with the wrong module - should not fire: - module_list.Append(lldb.SBFileSpec("noSuchModule")) - wrong.append(target.BreakpointCreateFromScript("resolver.Resolver", extra_args, module_list, file_list)) - - # one with the wrong file - also should not fire: - file_list.Clear() - module_list.Clear() - file_list.Append(lldb.SBFileSpec("noFileOfThisName.xxx")) - wrong.append(target.BreakpointCreateFromScript("resolver.Resolver", extra_args, module_list, file_list)) - - # Now make sure the CU level iteration obeys the file filters: - file_list.Clear() - module_list.Clear() - file_list.Append(lldb.SBFileSpec("no_such_file.xxx")) - wrong.append(target.BreakpointCreateFromScript("resolver.ResolverCUDepth", extra_args, module_list, file_list)) - - # And the Module filters: - file_list.Clear() - module_list.Clear() - module_list.Append(lldb.SBFileSpec("NoSuchModule.dylib")) - wrong.append(target.BreakpointCreateFromScript("resolver.ResolverCUDepth", extra_args, module_list, file_list)) - - # Now make sure the Function level iteration obeys the file filters: - file_list.Clear() - module_list.Clear() - file_list.Append(lldb.SBFileSpec("no_such_file.xxx")) - wrong.append(target.BreakpointCreateFromScript("resolver.ResolverFuncDepth", extra_args, module_list, file_list)) - - # And the Module filters: - file_list.Clear() - module_list.Clear() - module_list.Append(lldb.SBFileSpec("NoSuchModule.dylib")) - wrong.append(target.BreakpointCreateFromScript("resolver.ResolverFuncDepth", extra_args, module_list, file_list)) - - # Make sure these didn't get locations: - for i in range(0, len(wrong)): - self.assertEqual(wrong[i].GetNumLocations(), 0, "Breakpoint %d has locations."%(i)) - - # Now run to main and ensure we hit the breakpoints we should have: - - lldbutil.run_to_breakpoint_do_run(self, target, right[0]) - - # Test the hit counts: - for i in range(0, len(right)): - self.assertEqual(right[i].GetHitCount(), 1, "Breakpoint %d has the wrong hit count"%(i)) - - for i in range(0, len(wrong)): - self.assertEqual(wrong[i].GetHitCount(), 0, "Breakpoint %d has the wrong hit count"%(i)) - - def do_test_depths(self): - """This test uses a class variable in resolver.Resolver which gets set to 1 if we saw - compile unit and 2 if we only saw modules. If the search depth is module, you get passed just - the modules with no comp_unit. If the depth is comp_unit you get comp_units. So we can use - this to test that our callback gets called at the right depth.""" - - target = self.make_target_and_import() - extra_args = self.make_extra_args() - - file_list = lldb.SBFileSpecList() - module_list = lldb.SBFileSpecList() - module_list.Append(lldb.SBFileSpec("a.out")) - - # Make a breakpoint that has no __get_depth__, check that that is converted to eSearchDepthModule: - bkpt = target.BreakpointCreateFromScript("resolver.Resolver", extra_args, module_list, file_list) - self.assertTrue(bkpt.GetNumLocations() > 0, "Resolver got no locations.") - self.expect("script print(resolver.Resolver.got_files)", substrs=["2"], msg="Was only passed modules") - - # Make a breakpoint that asks for modules, check that we didn't get any files: - bkpt = target.BreakpointCreateFromScript("resolver.ResolverModuleDepth", extra_args, module_list, file_list) - self.assertTrue(bkpt.GetNumLocations() > 0, "ResolverModuleDepth got no locations.") - self.expect("script print(resolver.Resolver.got_files)", substrs=["2"], msg="Was only passed modules") - - # Make a breakpoint that asks for compile units, check that we didn't get any files: - bkpt = target.BreakpointCreateFromScript("resolver.ResolverCUDepth", extra_args, module_list, file_list) - self.assertTrue(bkpt.GetNumLocations() > 0, "ResolverCUDepth got no locations.") - self.expect("script print(resolver.Resolver.got_files)", substrs=["1"], msg="Was passed compile units") - - # Make a breakpoint that returns a bad value - we should convert that to "modules" so check that: - bkpt = target.BreakpointCreateFromScript("resolver.ResolverBadDepth", extra_args, module_list, file_list) - self.assertTrue(bkpt.GetNumLocations() > 0, "ResolverBadDepth got no locations.") - self.expect("script print(resolver.Resolver.got_files)", substrs=["2"], msg="Was only passed modules") - - # Make a breakpoint that searches at function depth: - bkpt = target.BreakpointCreateFromScript("resolver.ResolverFuncDepth", extra_args, module_list, file_list) - self.assertTrue(bkpt.GetNumLocations() > 0, "ResolverFuncDepth got no locations.") - self.expect("script print(resolver.Resolver.got_files)", substrs=["3"], msg="Was only passed modules") - self.expect("script print(resolver.Resolver.func_list)", substrs=["break_on_me", "main", "test_func"], msg="Saw all the functions") - - def do_test_cli(self): - target = self.make_target_and_import() - - lldbutil.run_break_set_by_script(self, "resolver.Resolver", extra_options="-k symbol -v break_on_me") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/scripted_bkpt/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/scripted_bkpt/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/scripted_bkpt/main.c @@ -1,21 +0,0 @@ -#include - -int -test_func() -{ - return printf("I am a test function."); -} - -void -break_on_me() -{ - printf("I was called.\n"); -} - -int -main() -{ - break_on_me(); - test_func(); - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/scripted_bkpt/resolver.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/scripted_bkpt/resolver.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/scripted_bkpt/resolver.py @@ -1,54 +0,0 @@ -import lldb - -class Resolver: - got_files = 0 - func_list = [] - - def __init__(self, bkpt, extra_args, dict): - self.bkpt = bkpt - self.extra_args = extra_args - Resolver.func_list = [] - Resolver.got_files = 0 - - def __callback__(self, sym_ctx): - sym_name = "not_a_real_function_name" - sym_item = self.extra_args.GetValueForKey("symbol") - if sym_item.IsValid(): - sym_name = sym_item.GetStringValue(1000) - - if sym_ctx.compile_unit.IsValid(): - Resolver.got_files = 1 - else: - Resolver.got_files = 2 - - if sym_ctx.function.IsValid(): - Resolver.got_files = 3 - func_name = sym_ctx.function.GetName() - Resolver.func_list.append(func_name) - if sym_name == func_name: - self.bkpt.AddLocation(sym_ctx.function.GetStartAddress()) - return - - if sym_ctx.module.IsValid(): - sym = sym_ctx.module.FindSymbol(sym_name, lldb.eSymbolTypeCode) - if sym.IsValid(): - self.bkpt.AddLocation(sym.GetStartAddress()) - - def get_short_help(self): - return "I am a python breakpoint resolver" - -class ResolverModuleDepth(Resolver): - def __get_depth__ (self): - return lldb.eSearchDepthModule - -class ResolverCUDepth(Resolver): - def __get_depth__ (self): - return lldb.eSearchDepthCompUnit - -class ResolverFuncDepth(Resolver): - def __get_depth__ (self): - return lldb.eSearchDepthFunction - -class ResolverBadDepth(Resolver): - def __get_depth__ (self): - return lldb.kLastSearchDepthKind + 1 Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/serialize/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/serialize/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/serialize/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/serialize/TestBreakpointSerialization.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/serialize/TestBreakpointSerialization.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/serialize/TestBreakpointSerialization.py @@ -1,291 +0,0 @@ -""" -Test breakpoint serialization. -""" - -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 BreakpointSerialization(TestBase): - - mydir = TestBase.compute_mydir(__file__) - NO_DEBUG_INFO_TESTCASE = True - - @add_test_categories(['pyapi']) - def test_resolvers(self): - """Use Python APIs to test that we serialize resolvers.""" - self.build() - self.setup_targets_and_cleanup() - self.do_check_resolvers() - - def test_filters(self): - """Use Python APIs to test that we serialize search filters correctly.""" - self.build() - self.setup_targets_and_cleanup() - self.do_check_filters() - - def test_options(self): - """Use Python APIs to test that we serialize breakpoint options correctly.""" - self.build() - self.setup_targets_and_cleanup() - self.do_check_options() - - def test_appending(self): - """Use Python APIs to test that we serialize breakpoint options correctly.""" - self.build() - self.setup_targets_and_cleanup() - self.do_check_appending() - - def test_name_filters(self): - """Use python APIs to test that reading in by name works correctly.""" - self.build() - self.setup_targets_and_cleanup() - self.do_check_names() - - def setup_targets_and_cleanup(self): - def cleanup (): - self.RemoveTempFile(self.bkpts_file_path) - - if self.orig_target.IsValid(): - self.dbg.DeleteTarget(self.orig_target) - self.dbg.DeleteTarget(self.copy_target) - - self.addTearDownHook(cleanup) - self.RemoveTempFile(self.bkpts_file_path) - - exe = self.getBuildArtifact("a.out") - - # Create the targets we are making breakpoints in and copying them to: - self.orig_target = self.dbg.CreateTarget(exe) - self.assertTrue(self.orig_target, VALID_TARGET) - - self.copy_target = self.dbg.CreateTarget(exe) - self.assertTrue(self.copy_target, VALID_TARGET) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - - self.bkpts_file_path = self.getBuildArtifact("breakpoints.json") - self.bkpts_file_spec = lldb.SBFileSpec(self.bkpts_file_path) - - def check_equivalence(self, source_bps, do_write = True): - - error = lldb.SBError() - - if (do_write): - error = self.orig_target.BreakpointsWriteToFile(self.bkpts_file_spec, source_bps) - self.assertTrue(error.Success(), "Failed writing breakpoints to file: %s."%(error.GetCString())) - - copy_bps = lldb.SBBreakpointList(self.copy_target) - error = self.copy_target.BreakpointsCreateFromFile(self.bkpts_file_spec, copy_bps) - self.assertTrue(error.Success(), "Failed reading breakpoints from file: %s"%(error.GetCString())) - - num_source_bps = source_bps.GetSize() - num_copy_bps = copy_bps.GetSize() - self.assertTrue(num_source_bps == num_copy_bps, "Didn't get same number of input and output breakpoints - orig: %d copy: %d"%(num_source_bps, num_copy_bps)) - - for i in range(0, num_source_bps): - source_bp = source_bps.GetBreakpointAtIndex(i) - source_desc = lldb.SBStream() - source_bp.GetDescription(source_desc, False) - source_text = source_desc.GetData() - - # I am assuming here that the breakpoints will get written out in breakpoint ID order, and - # read back in ditto. That is true right now, and I can't see any reason to do it differently - # but if we do we can go to writing the breakpoints one by one, or sniffing the descriptions to - # see which one is which. - copy_id = source_bp.GetID() - copy_bp = copy_bps.FindBreakpointByID(copy_id) - self.assertTrue(copy_bp.IsValid(), "Could not find copy breakpoint %d."%(copy_id)) - - copy_desc = lldb.SBStream() - copy_bp.GetDescription(copy_desc, False) - copy_text = copy_desc.GetData() - - # These two should be identical. - # print ("Source text for %d is %s."%(i, source_text)) - self.assertTrue (source_text == copy_text, "Source and dest breakpoints are not identical: \nsource: %s\ndest: %s"%(source_text, copy_text)) - - def do_check_resolvers(self): - """Use Python APIs to check serialization of breakpoint resolvers""" - - empty_module_list = lldb.SBFileSpecList() - empty_cu_list = lldb.SBFileSpecList() - blubby_file_spec = lldb.SBFileSpec(os.path.join(self.getSourceDir(), "blubby.c")) - - # It isn't actually important for these purposes that these breakpoint - # actually have locations. - source_bps = lldb.SBBreakpointList(self.orig_target) - source_bps.Append(self.orig_target.BreakpointCreateByLocation("blubby.c", 666)) - # Make sure we do one breakpoint right: - self.check_equivalence(source_bps) - source_bps.Clear() - - source_bps.Append(self.orig_target.BreakpointCreateByName("blubby", lldb.eFunctionNameTypeAuto, empty_module_list, empty_cu_list)) - source_bps.Append(self.orig_target.BreakpointCreateByName("blubby", lldb.eFunctionNameTypeFull, empty_module_list,empty_cu_list)) - source_bps.Append(self.orig_target.BreakpointCreateBySourceRegex("dont really care", blubby_file_spec)) - - # And some number greater than one: - self.check_equivalence(source_bps) - - def do_check_filters(self): - """Use Python APIs to check serialization of breakpoint filters.""" - module_list = lldb.SBFileSpecList() - module_list.Append(lldb.SBFileSpec("SomeBinary")) - module_list.Append(lldb.SBFileSpec("SomeOtherBinary")) - - cu_list = lldb.SBFileSpecList() - cu_list.Append(lldb.SBFileSpec("SomeCU.c")) - cu_list.Append(lldb.SBFileSpec("AnotherCU.c")) - cu_list.Append(lldb.SBFileSpec("ThirdCU.c")) - - blubby_file_spec = lldb.SBFileSpec(os.path.join(self.getSourceDir(), "blubby.c")) - - # It isn't actually important for these purposes that these breakpoint - # actually have locations. - source_bps = lldb.SBBreakpointList(self.orig_target) - bkpt = self.orig_target.BreakpointCreateByLocation(blubby_file_spec, 666, 0, module_list) - source_bps.Append(bkpt) - - # Make sure we do one right: - self.check_equivalence(source_bps) - source_bps.Clear() - - bkpt = self.orig_target.BreakpointCreateByName("blubby", lldb.eFunctionNameTypeAuto, module_list, cu_list) - source_bps.Append(bkpt) - bkpt = self.orig_target.BreakpointCreateByName("blubby", lldb.eFunctionNameTypeFull, module_list, cu_list) - source_bps.Append(bkpt) - bkpt = self.orig_target.BreakpointCreateBySourceRegex("dont really care", blubby_file_spec) - source_bps.Append(bkpt) - - # And some number greater than one: - self.check_equivalence(source_bps) - - def do_check_options(self): - """Use Python APIs to check serialization of breakpoint options.""" - - empty_module_list = lldb.SBFileSpecList() - empty_cu_list = lldb.SBFileSpecList() - blubby_file_spec = lldb.SBFileSpec(os.path.join(self.getSourceDir(), "blubby.c")) - - # It isn't actually important for these purposes that these breakpoint - # actually have locations. - source_bps = lldb.SBBreakpointList(self.orig_target) - - bkpt = self.orig_target.BreakpointCreateByLocation( - lldb.SBFileSpec("blubby.c"), 666, 333, 0, lldb.SBFileSpecList()) - bkpt.SetEnabled(False) - bkpt.SetOneShot(True) - bkpt.SetThreadID(10) - source_bps.Append(bkpt) - - # Make sure we get one right: - self.check_equivalence(source_bps) - source_bps.Clear() - - bkpt = self.orig_target.BreakpointCreateByName("blubby", lldb.eFunctionNameTypeAuto, empty_module_list, empty_cu_list) - bkpt.SetIgnoreCount(10) - bkpt.SetThreadName("grubby") - source_bps.Append(bkpt) - - bkpt = self.orig_target.BreakpointCreateByName("blubby", lldb.eFunctionNameTypeAuto, empty_module_list, empty_cu_list) - bkpt.SetCondition("gonna remove this") - bkpt.SetCondition("") - source_bps.Append(bkpt) - - bkpt = self.orig_target.BreakpointCreateByName("blubby", lldb.eFunctionNameTypeFull, empty_module_list,empty_cu_list) - bkpt.SetCondition("something != something_else") - bkpt.SetQueueName("grubby") - bkpt.AddName("FirstName") - bkpt.AddName("SecondName") - bkpt.SetScriptCallbackBody('\tprint("I am a function that prints.")\n\tprint("I don\'t do anything else")\n') - source_bps.Append(bkpt) - - bkpt = self.orig_target.BreakpointCreateBySourceRegex("dont really care", blubby_file_spec) - cmd_list = lldb.SBStringList() - cmd_list.AppendString("frame var") - cmd_list.AppendString("thread backtrace") - - bkpt.SetCommandLineCommands(cmd_list) - source_bps.Append(bkpt) - - self.check_equivalence(source_bps) - - def do_check_appending(self): - """Use Python APIs to check appending to already serialized options.""" - - empty_module_list = lldb.SBFileSpecList() - empty_cu_list = lldb.SBFileSpecList() - blubby_file_spec = lldb.SBFileSpec(os.path.join(self.getSourceDir(), "blubby.c")) - - # It isn't actually important for these purposes that these breakpoint - # actually have locations. - - all_bps = lldb.SBBreakpointList(self.orig_target) - source_bps = lldb.SBBreakpointList(self.orig_target) - - bkpt = self.orig_target.BreakpointCreateByLocation( - lldb.SBFileSpec("blubby.c"), 666, 333, 0, lldb.SBFileSpecList()) - bkpt.SetEnabled(False) - bkpt.SetOneShot(True) - bkpt.SetThreadID(10) - source_bps.Append(bkpt) - all_bps.Append(bkpt) - - error = lldb.SBError() - error = self.orig_target.BreakpointsWriteToFile(self.bkpts_file_spec, source_bps) - self.assertTrue(error.Success(), "Failed writing breakpoints to file: %s."%(error.GetCString())) - - source_bps.Clear() - - bkpt = self.orig_target.BreakpointCreateByName("blubby", lldb.eFunctionNameTypeAuto, empty_module_list, empty_cu_list) - bkpt.SetIgnoreCount(10) - bkpt.SetThreadName("grubby") - source_bps.Append(bkpt) - all_bps.Append(bkpt) - - bkpt = self.orig_target.BreakpointCreateByName("blubby", lldb.eFunctionNameTypeFull, empty_module_list,empty_cu_list) - bkpt.SetCondition("something != something_else") - bkpt.SetQueueName("grubby") - bkpt.AddName("FirstName") - bkpt.AddName("SecondName") - - source_bps.Append(bkpt) - all_bps.Append(bkpt) - - error = self.orig_target.BreakpointsWriteToFile(self.bkpts_file_spec, source_bps, True) - self.assertTrue(error.Success(), "Failed appending breakpoints to file: %s."%(error.GetCString())) - - self.check_equivalence(all_bps) - - def do_check_names(self): - bkpt = self.orig_target.BreakpointCreateByLocation( - lldb.SBFileSpec("blubby.c"), 666, 333, 0, lldb.SBFileSpecList()) - good_bkpt_name = "GoodBreakpoint" - write_bps = lldb.SBBreakpointList(self.orig_target) - bkpt.AddName(good_bkpt_name) - write_bps.Append(bkpt) - - error = lldb.SBError() - error = self.orig_target.BreakpointsWriteToFile(self.bkpts_file_spec, write_bps) - self.assertTrue(error.Success(), "Failed writing breakpoints to file: %s."%(error.GetCString())) - - copy_bps = lldb.SBBreakpointList(self.copy_target) - names_list = lldb.SBStringList() - names_list.AppendString("NoSuchName") - - error = self.copy_target.BreakpointsCreateFromFile(self.bkpts_file_spec, names_list, copy_bps) - self.assertTrue(error.Success(), "Failed reading breakpoints from file: %s"%(error.GetCString())) - self.assertTrue(copy_bps.GetSize() == 0, "Found breakpoints with a nonexistent name.") - - names_list.AppendString(good_bkpt_name) - error = self.copy_target.BreakpointsCreateFromFile(self.bkpts_file_spec, names_list, copy_bps) - self.assertTrue(error.Success(), "Failed reading breakpoints from file: %s"%(error.GetCString())) - self.assertTrue(copy_bps.GetSize() == 1, "Found the matching breakpoint.") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/serialize/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/serialize/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/serialize/main.c @@ -1,53 +0,0 @@ -//===-- main.c --------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -#include - -// This simple program is to demonstrate the capability of the lldb command -// "breakpoint modify -i breakpt-id" to set the number of times a -// breakpoint is skipped before stopping. Ignore count can also be set upon -// breakpoint creation by 'breakpoint set ... -i '. - -int a(int); -int b(int); -int c(int); - -int a(int val) -{ - if (val <= 1) - return b(val); - else if (val >= 3) - return c(val); // a(3) -> c(3) Find the call site of c(3). - - return val; -} - -int b(int val) -{ - return c(val); -} - -int c(int val) -{ - return val + 3; // Find the line number of function "c" here. -} - -int main (int argc, char const *argv[]) -{ - int A1 = a(1); // a(1) -> b(1) -> c(1) - printf("a(1) returns %d\n", A1); - - int B2 = b(2); // b(2) -> c(2) Find the call site of b(2). - printf("b(2) returns %d\n", B2); - - int A3 = a(3); // a(3) -> c(3) Find the call site of a(3). - printf("a(3) returns %d\n", A3); - - int C1 = c(5); // Find the call site of c in main. - printf ("c(5) returns %d\n", C1); - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/source_regexp/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/source_regexp/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/source_regexp/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c a.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/source_regexp/TestSourceRegexBreakpoints.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/source_regexp/TestSourceRegexBreakpoints.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/source_regexp/TestSourceRegexBreakpoints.py @@ -1,104 +0,0 @@ -""" -Test lldb breakpoint setting by source regular expression. -This test just tests the source file & function restrictions. -""" - -from __future__ import print_function - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestSourceRegexBreakpoints(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def test_location(self): - self.build() - self.source_regex_locations() - - def test_restrictions(self): - self.build() - self.source_regex_restrictions() - - def source_regex_locations(self): - """ Test that restricting source expressions to files & to functions. """ - # Create a target by the debugger. - exe = self.getBuildArtifact("a.out") - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, VALID_TARGET) - - # First look just in main: - target_files = lldb.SBFileSpecList() - target_files.Append(lldb.SBFileSpec("a.c")) - - func_names = lldb.SBStringList() - func_names.AppendString("a_func") - - source_regex = "Set . breakpoint here" - main_break = target.BreakpointCreateBySourceRegex( - source_regex, lldb.SBFileSpecList(), target_files, func_names) - num_locations = main_break.GetNumLocations() - self.assertTrue( - num_locations == 1, - "a.c in a_func should give one breakpoint, got %d." % - (num_locations)) - - loc = main_break.GetLocationAtIndex(0) - self.assertTrue(loc.IsValid(), "Got a valid location.") - address = loc.GetAddress() - self.assertTrue( - address.IsValid(), - "Got a valid address from the location.") - - a_func_line = line_number("a.c", "Set A breakpoint here") - line_entry = address.GetLineEntry() - self.assertTrue(line_entry.IsValid(), "Got a valid line entry.") - self.assertTrue(line_entry.line == a_func_line, - "Our line number matches the one lldbtest found.") - - def source_regex_restrictions(self): - """ Test that restricting source expressions to files & to functions. """ - # Create a target by the debugger. - exe = self.getBuildArtifact("a.out") - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, VALID_TARGET) - - # First look just in main: - target_files = lldb.SBFileSpecList() - target_files.Append(lldb.SBFileSpec("main.c")) - source_regex = "Set . breakpoint here" - main_break = target.BreakpointCreateBySourceRegex( - source_regex, lldb.SBFileSpecList(), target_files, lldb.SBStringList()) - - num_locations = main_break.GetNumLocations() - self.assertTrue( - num_locations == 2, - "main.c should have 2 matches, got %d." % - (num_locations)) - - # Now look in both files: - target_files.Append(lldb.SBFileSpec("a.c")) - - main_break = target.BreakpointCreateBySourceRegex( - source_regex, lldb.SBFileSpecList(), target_files, lldb.SBStringList()) - - num_locations = main_break.GetNumLocations() - self.assertTrue( - num_locations == 4, - "main.c and a.c should have 4 matches, got %d." % - (num_locations)) - - # Now restrict it to functions: - func_names = lldb.SBStringList() - func_names.AppendString("main_func") - main_break = target.BreakpointCreateBySourceRegex( - source_regex, lldb.SBFileSpecList(), target_files, func_names) - - num_locations = main_break.GetNumLocations() - self.assertTrue( - num_locations == 2, - "main_func in main.c and a.c should have 2 matches, got %d." % - (num_locations)) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/source_regexp/a.h =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/source_regexp/a.h +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/source_regexp/a.h @@ -1 +0,0 @@ -int a_func(int); Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/source_regexp/a.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/source_regexp/a.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/source_regexp/a.c @@ -1,16 +0,0 @@ -#include - -#include "a.h" - -static int -main_func(int input) -{ - return printf("Set B breakpoint here: %d", input); -} - -int -a_func(int input) -{ - input += 1; // Set A breakpoint here; - return main_func(input); -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/source_regexp/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/source_regexp/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/source_regexp/main.c @@ -1,17 +0,0 @@ -#include -#include "a.h" - -int -main_func(int input) -{ - return printf("Set B breakpoint here: %d.\n", input); -} - -int -main() -{ - a_func(10); - main_func(10); - printf("Set a breakpoint here:\n"); - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/Makefile @@ -1,9 +0,0 @@ -LEVEL = ../../../make - -CXX_SOURCES := main.cpp - -ifneq (,$(findstring icc,$(CC))) - CXXFLAGS += -debug inline-debug-info -endif - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/TestStepOverBreakpoint.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/TestStepOverBreakpoint.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/TestStepOverBreakpoint.py @@ -1,119 +0,0 @@ -""" -Test that breakpoints do not affect stepping. -Check for correct StopReason when stepping to the line with breakpoint -which chould be eStopReasonBreakpoint in general, -and eStopReasonPlanComplete when breakpoint's condition fails. -""" - -from __future__ import print_function - -import unittest2 -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class StepOverBreakpointsTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - TestBase.setUp(self) - - self.build() - exe = self.getBuildArtifact("a.out") - src = lldb.SBFileSpec("main.cpp") - - # Create a target by the debugger. - self.target = self.dbg.CreateTarget(exe) - self.assertTrue(self.target, VALID_TARGET) - - # Setup four breakpoints, two of them with false condition - self.line1 = line_number('main.cpp', "breakpoint_1") - self.line4 = line_number('main.cpp', "breakpoint_4") - - self.breakpoint1 = self.target.BreakpointCreateByLocation(src, self.line1) - self.assertTrue( - self.breakpoint1 and self.breakpoint1.GetNumLocations() == 1, - VALID_BREAKPOINT) - - self.breakpoint2 = self.target.BreakpointCreateBySourceRegex("breakpoint_2", src) - self.breakpoint2.GetLocationAtIndex(0).SetCondition('false') - - self.breakpoint3 = self.target.BreakpointCreateBySourceRegex("breakpoint_3", src) - self.breakpoint3.GetLocationAtIndex(0).SetCondition('false') - - self.breakpoint4 = self.target.BreakpointCreateByLocation(src, self.line4) - - # Start debugging - self.process = self.target.LaunchSimple( - None, None, self.get_process_working_directory()) - self.assertIsNotNone(self.process, PROCESS_IS_VALID) - self.thread = lldbutil.get_one_thread_stopped_at_breakpoint(self.process, self.breakpoint1) - self.assertIsNotNone(self.thread, "Didn't stop at breakpoint 1.") - - def test_step_instruction(self): - # Count instructions between breakpoint_1 and breakpoint_4 - contextList = self.target.FindFunctions('main', lldb.eFunctionNameTypeAuto) - self.assertEquals(contextList.GetSize(), 1) - symbolContext = contextList.GetContextAtIndex(0) - function = symbolContext.GetFunction() - self.assertTrue(function) - instructions = function.GetInstructions(self.target) - addr_1 = self.breakpoint1.GetLocationAtIndex(0).GetAddress() - addr_4 = self.breakpoint4.GetLocationAtIndex(0).GetAddress() - - # if third argument is true then the count will be the number of - # instructions on which a breakpoint can be set. - # start = addr_1, end = addr_4, canSetBreakpoint = True - steps_expected = instructions.GetInstructionsCount(addr_1, addr_4, True) - step_count = 0 - # Step from breakpoint_1 to breakpoint_4 - while True: - self.thread.StepInstruction(True) - step_count = step_count + 1 - self.assertEquals(self.process.GetState(), lldb.eStateStopped) - self.assertTrue(self.thread.GetStopReason() == lldb.eStopReasonPlanComplete or - self.thread.GetStopReason() == lldb.eStopReasonBreakpoint) - if (self.thread.GetStopReason() == lldb.eStopReasonBreakpoint) : - # we should not stop on breakpoint_2 and _3 because they have false condition - self.assertEquals(self.thread.GetFrameAtIndex(0).GetLineEntry().GetLine(), self.line4) - # breakpoint_2 and _3 should not affect step count - self.assertTrue(step_count >= steps_expected) - break - - # Run the process until termination - self.process.Continue() - self.assertEquals(self.process.GetState(), lldb.eStateExited) - - @skipIf(bugnumber="llvm.org/pr31972", hostoslist=["windows"]) - def test_step_over(self): - #lldb.DBG.EnableLog("lldb", ["step","breakpoint"]) - - self.thread.StepOver() - # We should be stopped at the breakpoint_2 line with stop plan complete reason - self.assertEquals(self.process.GetState(), lldb.eStateStopped) - self.assertEquals(self.thread.GetStopReason(), lldb.eStopReasonPlanComplete) - - self.thread.StepOver() - # We should be stopped at the breakpoint_3 line with stop plan complete reason - self.assertEquals(self.process.GetState(), lldb.eStateStopped) - self.assertEquals(self.thread.GetStopReason(), lldb.eStopReasonPlanComplete) - - self.thread.StepOver() - # We should be stopped at the breakpoint_4 - self.assertEquals(self.process.GetState(), lldb.eStateStopped) - self.assertEquals(self.thread.GetStopReason(), lldb.eStopReasonBreakpoint) - thread1 = lldbutil.get_one_thread_stopped_at_breakpoint(self.process, self.breakpoint4) - self.assertEquals(self.thread, thread1, "Didn't stop at breakpoint 4.") - - # Check that stepping does not affect breakpoint's hit count - self.assertEquals(self.breakpoint1.GetHitCount(), 1) - self.assertEquals(self.breakpoint2.GetHitCount(), 0) - self.assertEquals(self.breakpoint3.GetHitCount(), 0) - self.assertEquals(self.breakpoint4.GetHitCount(), 1) - - # Run the process until termination - self.process.Continue() - self.assertEquals(self.process.GetState(), lldb.eStateExited) - Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/main.cpp @@ -1,12 +0,0 @@ - -int func() { return 1; } - -int -main(int argc, char const *argv[]) -{ - int a = 0; // breakpoint_1 - int b = func(); // breakpoint_2 - a = b + func(); // breakpoint_3 - return 0; // breakpoint_4 -} - Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_history/.categories =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_history/.categories +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_history/.categories @@ -1 +0,0 @@ -cmdline Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_history/TestCommandHistory.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_history/TestCommandHistory.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_history/TestCommandHistory.py @@ -1,107 +0,0 @@ -""" -Test the command history mechanism -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class CommandHistoryTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @no_debug_info_test - def test_history(self): - self.runCmd('command history --clear', inHistory=False) - self.runCmd('breakpoint list', check=False, inHistory=True) # 0 - self.runCmd('register read', check=False, inHistory=True) # 1 - self.runCmd('apropos hello', check=False, inHistory=True) # 2 - self.runCmd('memory write', check=False, inHistory=True) # 3 - self.runCmd('log list', check=False, inHistory=True) # 4 - self.runCmd('disassemble', check=False, inHistory=True) # 5 - self.runCmd('expression 1', check=False, inHistory=True) # 6 - self.runCmd( - 'type summary list -w default', - check=False, - inHistory=True) # 7 - self.runCmd('version', check=False, inHistory=True) # 8 - self.runCmd('frame select 1', check=False, inHistory=True) # 9 - - self.expect( - "command history -s 3 -c 3", - inHistory=True, - substrs=[ - '3: memory write', - '4: log list', - '5: disassemble']) - - self.expect("command history -s 3 -e 3", inHistory=True, - substrs=['3: memory write']) - - self.expect( - "command history -s 6 -e 7", - inHistory=True, - substrs=[ - '6: expression 1', - '7: type summary list -w default']) - - self.expect("command history -c 2", inHistory=True, - substrs=['0: breakpoint list', '1: register read']) - - self.expect("command history -e 3 -c 1", inHistory=True, - substrs=['3: memory write']) - - self.expect( - "command history -e 2", - inHistory=True, - substrs=[ - '0: breakpoint list', - '1: register read', - '2: apropos hello']) - - self.expect( - "command history -s 12", - inHistory=True, - substrs=[ - '12: command history -s 6 -e 7', - '13: command history -c 2', - '14: command history -e 3 -c 1', - '15: command history -e 2', - '16: command history -s 12']) - - self.expect( - "command history -s end -c 3", - inHistory=True, - substrs=[ - '15: command history -e 2', - '16: command history -s 12', - '17: command history -s end -c 3']) - - self.expect( - "command history -s end -e 15", - inHistory=True, - substrs=[ - '15: command history -e 2', - '16: command history -s 12', - '17: command history -s end -c 3', - 'command history -s end -e 15']) - - self.expect("command history -s 5 -c 1", inHistory=True, - substrs=['5: disassemble']) - - self.expect("command history -c 1 -s 5", inHistory=True, - substrs=['5: disassemble']) - - self.expect("command history -c 1 -e 3", inHistory=True, - substrs=['3: memory write']) - - self.expect( - "command history -c 1 -e 3 -s 5", - error=True, - inHistory=True, - substrs=['error: --count, --start-index and --end-index cannot be all specified in the same invocation']) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/.categories =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/.categories +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/.categories @@ -1 +0,0 @@ -cmdline Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/TestCommandScript.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/TestCommandScript.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/TestCommandScript.py @@ -1,153 +0,0 @@ -""" -Test lldb Python commands. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * - - -class CmdPythonTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - NO_DEBUG_INFO_TESTCASE = True - - def test(self): - self.build() - self.pycmd_tests() - - def pycmd_tests(self): - self.runCmd("command source py_import") - - # Verify command that specifies eCommandRequiresTarget returns failure - # without a target. - self.expect('targetname', - substrs=['a.out'], matching=False, error=True) - - exe = self.getBuildArtifact("a.out") - self.expect("file " + exe, - patterns=["Current executable set to .*a.out"]) - - self.expect('targetname', - substrs=['a.out'], matching=True, error=False) - - # This is the function to remove the custom commands in order to have a - # clean slate for the next test case. - def cleanup(): - self.runCmd('command script delete welcome', check=False) - self.runCmd('command script delete targetname', check=False) - self.runCmd('command script delete longwait', check=False) - self.runCmd('command script delete mysto', check=False) - self.runCmd('command script delete tell_sync', check=False) - self.runCmd('command script delete tell_async', check=False) - self.runCmd('command script delete tell_curr', check=False) - self.runCmd('command script delete bug11569', check=False) - self.runCmd('command script delete takes_exe_ctx', check=False) - self.runCmd('command script delete decorated', check=False) - - # Execute the cleanup function during test case tear down. - self.addTearDownHook(cleanup) - - # Interact with debugger in synchronous mode - self.setAsync(False) - - # We don't want to display the stdout if not in TraceOn() mode. - if not self.TraceOn(): - self.HideStdout() - - self.expect('welcome Enrico', - substrs=['Hello Enrico, welcome to LLDB']) - - self.expect("help welcome", - substrs=['Just a docstring for welcome_impl', - 'A command that says hello to LLDB users']) - - decorated_commands = ["decorated" + str(n) for n in range(1, 5)] - for name in decorated_commands: - self.expect(name, substrs=["hello from " + name]) - self.expect("help " + name, - substrs=["Python command defined by @lldb.command"]) - - self.expect("help", - substrs=['For more information run', - 'welcome'] + decorated_commands) - - self.expect("help -a", - substrs=['For more information run', - 'welcome'] + decorated_commands) - - self.expect("help -u", matching=False, - substrs=['For more information run']) - - self.runCmd("command script delete welcome") - - self.expect('welcome Enrico', matching=False, error=True, - substrs=['Hello Enrico, welcome to LLDB']) - - self.expect('targetname fail', error=True, - substrs=['a test for error in command']) - - self.expect('command script list', - substrs=['targetname', - 'For more information run']) - - self.expect("help targetname", - substrs=['Expects', '\'raw\'', 'input', - 'help', 'raw-input']) - - self.expect("longwait", - substrs=['Done; if you saw the delays I am doing OK']) - - self.runCmd("b main") - self.runCmd("run") - self.runCmd("mysto 3") - self.expect("frame variable array", - substrs=['[0] = 79630', '[1] = 388785018', '[2] = 0']) - self.runCmd("mysto 3") - self.expect("frame variable array", - substrs=['[0] = 79630', '[4] = 388785018', '[5] = 0']) - -# we cannot use the stepover command to check for async execution mode since LLDB -# seems to get confused when events start to queue up - self.expect("tell_sync", - substrs=['running sync']) - self.expect("tell_async", - substrs=['running async']) - self.expect("tell_curr", - substrs=['I am running sync']) - -# check that the execution context is passed in to commands that ask for it - self.expect("takes_exe_ctx", substrs=["a.out"]) - - # Test that a python command can redefine itself - self.expect('command script add -f foobar welcome -h "just some help"') - - self.runCmd("command script clear") - - # Test that re-defining an existing command works - self.runCmd( - 'command script add my_command --class welcome.WelcomeCommand') - self.expect('my_command Blah', substrs=['Hello Blah, welcome to LLDB']) - - self.runCmd( - 'command script add my_command --class welcome.TargetnameCommand') - self.expect('my_command', substrs=['a.out']) - - self.runCmd("command script clear") - - self.expect('command script list', matching=False, - substrs=['targetname', - 'longwait']) - - self.expect('command script add -f foobar frame', error=True, - substrs=['cannot add command']) - - # http://llvm.org/bugs/show_bug.cgi?id=11569 - # LLDBSwigPythonCallCommand crashes when a command script returns an - # object - self.runCmd('command script add -f bug11569 bug11569') - # This should not crash. - self.runCmd('bug11569', check=False) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/bug11569.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/bug11569.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/bug11569.py @@ -1,6 +0,0 @@ -def bug11569(debugger, args, result, dict): - """ - http://llvm.org/bugs/show_bug.cgi?id=11569 - LLDBSwigPythonCallCommand crashes when a command script returns an object. - """ - return ["return", "a", "non-string", "should", "not", "crash", "LLDB"] Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/decorated.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/decorated.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/decorated.py @@ -1,35 +0,0 @@ -from __future__ import print_function - -import lldb - - -@lldb.command() -def decorated1(debugger, args, exe_ctx, result, dict): - """ - Python command defined by @lldb.command - """ - print("hello from decorated1", file=result) - - -@lldb.command(doc="Python command defined by @lldb.command") -def decorated2(debugger, args, exe_ctx, result, dict): - """ - This docstring is overridden. - """ - print("hello from decorated2", file=result) - - -@lldb.command() -def decorated3(debugger, args, result, dict): - """ - Python command defined by @lldb.command - """ - print("hello from decorated3", file=result) - - -@lldb.command("decorated4") -def _decorated4(debugger, args, exe_ctx, result, dict): - """ - Python command defined by @lldb.command - """ - print("hello from decorated4", file=result) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/Makefile @@ -1,6 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c -EXE := hello_world - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/TestImport.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/TestImport.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/TestImport.py @@ -1,76 +0,0 @@ -"""Test custom import command to import files by path.""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class ImportTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @add_test_categories(['pyapi']) - @no_debug_info_test - def test_import_command(self): - """Import some Python scripts by path and test them""" - self.run_test() - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - - def run_test(self): - """Import some Python scripts by path and test them.""" - - # This is the function to remove the custom commands in order to have a - # clean slate for the next test case. - def cleanup(): - self.runCmd('command script delete foo2cmd', check=False) - self.runCmd('command script delete foocmd', check=False) - self.runCmd('command script delete foobarcmd', check=False) - self.runCmd('command script delete barcmd', check=False) - self.runCmd('command script delete barothercmd', check=False) - self.runCmd('command script delete TPcommandA', check=False) - self.runCmd('command script delete TPcommandB', check=False) - - # Execute the cleanup function during test case tear down. - self.addTearDownHook(cleanup) - - self.runCmd("command script import ./foo/foo.py --allow-reload") - self.runCmd("command script import ./foo/foo2.py --allow-reload") - self.runCmd("command script import ./foo/bar/foobar.py --allow-reload") - self.runCmd("command script import ./bar/bar.py --allow-reload") - - self.expect("command script import ./nosuchfile.py", - error=True, startstr='error: module importing failed') - self.expect("command script import ./nosuchfolder/", - error=True, startstr='error: module importing failed') - self.expect("command script import ./foo/foo.py", error=False) - - self.runCmd("command script import --allow-reload ./thepackage") - self.expect("TPcommandA", substrs=["hello world A"]) - self.expect("TPcommandB", substrs=["hello world B"]) - - self.runCmd("script import dummymodule") - self.expect("command script import ./dummymodule.py", error=False) - self.expect( - "command script import --allow-reload ./dummymodule.py", - error=False) - - self.runCmd("command script add -f foo.foo_function foocmd") - self.runCmd("command script add -f foobar.foo_function foobarcmd") - self.runCmd("command script add -f bar.bar_function barcmd") - self.expect("foocmd hello", - substrs=['foo says', 'hello']) - self.expect("foo2cmd hello", - substrs=['foo2 says', 'hello']) - self.expect("barcmd hello", - substrs=['barutil says', 'bar told me', 'hello']) - self.expect("barothercmd hello", - substrs=['barutil says', 'bar told me', 'hello']) - self.expect("foobarcmd hello", - substrs=['foobar says', 'hello']) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/bar/bar.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/bar/bar.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/bar/bar.py @@ -1,15 +0,0 @@ -from __future__ import print_function - - -def bar_function(debugger, args, result, dict): - global UtilityModule - print(UtilityModule.barutil_function("bar told me " + args), file=result) - return None - - -def __lldb_init_module(debugger, session_dict): - global UtilityModule - UtilityModule = __import__("barutil") - debugger.HandleCommand( - "command script add -f bar.bar_function barothercmd") - return None Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/bar/barutil.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/bar/barutil.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/bar/barutil.py @@ -1,2 +0,0 @@ -def barutil_function(x): - return "barutil says: " + x Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/dummymodule.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/dummymodule.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/dummymodule.py @@ -1,2 +0,0 @@ -def no_useful_code(foo): - return foo Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/foo/bar/foobar.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/foo/bar/foobar.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/foo/bar/foobar.py @@ -1,6 +0,0 @@ -from __future__ import print_function - - -def foo_function(debugger, args, result, dict): - print("foobar says " + args, file=result) - return None Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/foo/foo.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/foo/foo.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/foo/foo.py @@ -1,6 +0,0 @@ -from __future__ import print_function - - -def foo_function(debugger, args, result, dict): - print("foo says " + args, file=result) - return None Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/foo/foo2.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/foo/foo2.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/foo/foo2.py @@ -1,11 +0,0 @@ -from __future__ import print_function - - -def foo2_function(debugger, args, result, dict): - print("foo2 says " + args, file=result) - return None - - -def __lldb_init_module(debugger, session_dict): - debugger.HandleCommand("command script add -f foo2.foo2_function foo2cmd") - return None Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/main.c @@ -1,15 +0,0 @@ -#include - -int main(int argc, char const *argv[]) { - printf("Hello world.\n"); // Set break point at this line. - if (argc == 1) - return 0; - - // Waiting to be attached by the debugger, otherwise. - char line[100]; - while (fgets(line, sizeof(line), stdin)) { // Waiting to be attached... - printf("input line=>%s\n", line); - } - - printf("Exiting now\n"); -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/rdar-12586188/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/rdar-12586188/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/rdar-12586188/Makefile @@ -1,3 +0,0 @@ -LEVEL = ../../../../make - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/rdar-12586188/TestRdar12586188.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/rdar-12586188/TestRdar12586188.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/rdar-12586188/TestRdar12586188.py @@ -1,36 +0,0 @@ -"""Check that we handle an ImportError in a special way when command script importing files.""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class Rdar12586188TestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @add_test_categories(['pyapi']) - @no_debug_info_test - def test_rdar12586188_command(self): - """Check that we handle an ImportError in a special way when command script importing files.""" - self.run_test() - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - - def run_test(self): - """Check that we handle an ImportError in a special way when command script importing files.""" - - self.expect( - "command script import ./fail12586188.py --allow-reload", - error=True, - substrs=['raise ImportError("I do not want to be imported")']) - self.expect( - "command script import ./fail212586188.py --allow-reload", - error=True, - substrs=['raise ValueError("I do not want to be imported")']) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/rdar-12586188/fail12586188.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/rdar-12586188/fail12586188.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/rdar-12586188/fail12586188.py @@ -1,4 +0,0 @@ -def f(x): - return x + 1 - -raise ImportError("I do not want to be imported") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/rdar-12586188/fail212586188.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/rdar-12586188/fail212586188.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/rdar-12586188/fail212586188.py @@ -1,4 +0,0 @@ -def f(x): - return x + 1 - -raise ValueError("I do not want to be imported") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/thepackage/TPunitA.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/thepackage/TPunitA.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/thepackage/TPunitA.py @@ -1,7 +0,0 @@ - -import six - - -def command(debugger, command, result, internal_dict): - result.PutCString(six.u("hello world A")) - return None Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/thepackage/TPunitB.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/thepackage/TPunitB.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/thepackage/TPunitB.py @@ -1,7 +0,0 @@ - -import six - - -def command(debugger, command, result, internal_dict): - result.PutCString(six.u("hello world B")) - return None Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/thepackage/__init__.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/thepackage/__init__.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/thepackage/__init__.py @@ -1,11 +0,0 @@ -from __future__ import absolute_import - -from . import TPunitA -from . import TPunitB - - -def __lldb_init_module(debugger, *args): - debugger.HandleCommand( - "command script add -f thepackage.TPunitA.command TPcommandA") - debugger.HandleCommand( - "command script add -f thepackage.TPunitB.command TPcommandB") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/main.cpp @@ -1,69 +0,0 @@ -//===-- main.cpp ------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include -#include -#include -#include -#include - -int -product (int x, int y) -{ - int result = x * y; - return result; -} - -int -sum (int a, int b) -{ - int result = a + b; - return result; -} - -int -strange_max (int m, int n) -{ - if (m > n) - return m; - else if (n > m) - return n; - else - return 0; -} - -int -foo (int i, int j) -{ - if (strange_max (i, j) == i) - return product (i, j); - else if (strange_max (i, j) == j) - return sum (i, j); - else - return product (sum (i, i), sum (j, j)); -} - -int -main(int argc, char const *argv[]) -{ - - int array[9]; - memset(array,0,9*sizeof(int)); - - array[0] = foo (1238, 78392); - array[1] = foo (379265, 23674); - array[2] = foo (872934, 234); - array[3] = foo (1238, 78392); - array[4] = foo (379265, 23674); - array[5] = foo (872934, 234); - array[6] = foo (1238, 78392); - array[7] = foo (379265, 23674); - array[8] = foo (872934, 234); - - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/mysto.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/mysto.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/mysto.py @@ -1,22 +0,0 @@ -from __future__ import print_function - -import lldb - - -def StepOver(debugger, args, result, dict): - """ - Step over a given number of times instead of only just once - """ - arg_split = args.split(" ") - print(type(arg_split)) - count = int(arg_split[0]) - for i in range(0, count): - debugger.GetSelectedTarget().GetProcess( - ).GetSelectedThread().StepOver(lldb.eOnlyThisThread) - print("step<%d>" % i) - - -def __lldb_init_module(debugger, session_dict): - # by default, --synchronicity is set to synchronous - debugger.HandleCommand("command script add -f mysto.StepOver mysto") - return None Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/py_import =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/py_import +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/py_import @@ -1,13 +0,0 @@ -script import sys, os -script sys.path.append(os.path.join(os.getcwd(), os.pardir)) -script import welcome -script import bug11569 -command script add welcome --class welcome.WelcomeCommand -command script add targetname --class welcome.TargetnameCommand -command script add longwait --function welcome.print_wait_impl -command script import mysto.py --allow-reload -command script add tell_sync --function welcome.check_for_synchro --synchronicity sync -command script add tell_async --function welcome.check_for_synchro --synchronicity async -command script add tell_curr --function welcome.check_for_synchro --synchronicity curr -command script add takes_exe_ctx --function welcome.takes_exe_ctx -command script import decorated.py Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/welcome.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/welcome.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/welcome.py @@ -1,53 +0,0 @@ -from __future__ import print_function -import lldb -import sys - - -class WelcomeCommand(object): - - def __init__(self, debugger, session_dict): - pass - - def get_short_help(self): - return "Just a docstring for welcome_impl\nA command that says hello to LLDB users" - - def __call__(self, debugger, args, exe_ctx, result): - print('Hello ' + args + ', welcome to LLDB', file=result) - return None - - -class TargetnameCommand(object): - - def __init__(self, debugger, session_dict): - pass - - def __call__(self, debugger, args, exe_ctx, result): - target = debugger.GetSelectedTarget() - file = target.GetExecutable() - print('Current target ' + file.GetFilename(), file=result) - if args == 'fail': - result.SetError('a test for error in command') - - def get_flags(self): - return lldb.eCommandRequiresTarget - - -def print_wait_impl(debugger, args, result, dict): - result.SetImmediateOutputFile(sys.stdout) - print('Trying to do long task..', file=result) - import time - time.sleep(1) - print('Still doing long task..', file=result) - time.sleep(1) - print('Done; if you saw the delays I am doing OK', file=result) - - -def check_for_synchro(debugger, args, result, dict): - if debugger.GetAsync(): - print('I am running async', file=result) - if debugger.GetAsync() == False: - print('I am running sync', file=result) - - -def takes_exe_ctx(debugger, args, exe_ctx, result, dict): - print(str(exe_ctx.GetTarget()), file=result) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_alias/.categories =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_alias/.categories +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_alias/.categories @@ -1 +0,0 @@ -cmdline Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_alias/TestCommandScriptAlias.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_alias/TestCommandScriptAlias.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_alias/TestCommandScriptAlias.py @@ -1,38 +0,0 @@ -""" -Test lldb Python commands. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.lldbtest import * - - -class CommandScriptAliasTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def test(self): - self.pycmd_tests() - - def pycmd_tests(self): - self.runCmd("command script import tcsacmd.py") - self.runCmd("command script add -f tcsacmd.some_command_here attach") - - # This is the function to remove the custom commands in order to have a - # clean slate for the next test case. - def cleanup(): - self.runCmd('command script delete attach', check=False) - - # Execute the cleanup function during test case tear down. - self.addTearDownHook(cleanup) - - # We don't want to display the stdout if not in TraceOn() mode. - if not self.TraceOn(): - self.HideStdout() - - self.expect('attach a', substrs=['Victory is mine']) - self.runCmd("command script delete attach") - # this can't crash but we don't care whether the actual attach works - self.runCmd('attach noprocessexistswiththisname', check=False) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_alias/tcsacmd.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_alias/tcsacmd.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_alias/tcsacmd.py @@ -1,11 +0,0 @@ -from __future__ import print_function -import lldb - - -def some_command_here(debugger, command, result, d): - if command == "a": - print("Victory is mine", file=result) - return True - else: - print("Sadness for all", file=result) - return False Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_source/.categories =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_source/.categories +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_source/.categories @@ -1 +0,0 @@ -cmdline Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_source/.lldb =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_source/.lldb +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_source/.lldb @@ -1,2 +0,0 @@ -# one more level of indirection to stress the command interpreter reentrancy -command source commands.txt Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_source/TestCommandSource.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_source/TestCommandSource.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_source/TestCommandSource.py @@ -1,35 +0,0 @@ -""" -Test that lldb command "command source" works correctly. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class CommandSourceTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @no_debug_info_test - def test_command_source(self): - """Test that lldb command "command source" works correctly.""" - - # Sourcing .lldb in the current working directory, which in turn imports - # the "my" package that defines the date() function. - self.runCmd("command source .lldb") - - # Python should evaluate "my.date()" successfully. - command_interpreter = self.dbg.GetCommandInterpreter() - self.assertTrue(command_interpreter, VALID_COMMAND_INTERPRETER) - result = lldb.SBCommandReturnObject() - command_interpreter.HandleCommand("script my.date()", result) - - import datetime - self.expect(result.GetOutput(), "script my.date() runs successfully", - exe=False, - substrs=[str(datetime.date.today())]) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_source/commands.txt =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_source/commands.txt +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_source/commands.txt @@ -1,2 +0,0 @@ -script import my -p 1 + 1 Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_source/my.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_source/my.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_source/my.py @@ -1,7 +0,0 @@ -from __future__ import print_function - - -def date(): - import datetime - today = datetime.date.today() - print(today) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/disassembly/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/disassembly/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/disassembly/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/disassembly/TestDisassembleBreakpoint.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/disassembly/TestDisassembleBreakpoint.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/disassembly/TestDisassembleBreakpoint.py @@ -1,39 +0,0 @@ -""" -Test some lldb command abbreviations. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class DisassemblyTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - NO_DEBUG_INFO_TESTCASE = True - - def test(self): - self.build() - target, _, _, bkpt = lldbutil.run_to_source_breakpoint(self, - "Set a breakpoint here", lldb.SBFileSpec("main.cpp")) - self.runCmd("dis -f") - disassembly_with_break = self.res.GetOutput().splitlines() - - self.assertTrue(target.BreakpointDelete(bkpt.GetID())) - - self.runCmd("dis -f") - disassembly_without_break = self.res.GetOutput().splitlines() - - # Make sure all assembly instructions are the same as instructions - # with the breakpoint removed. - self.assertEqual(len(disassembly_with_break), - len(disassembly_without_break)) - for dis_inst_with, dis_inst_without in \ - zip(disassembly_with_break, disassembly_without_break): - inst_with = dis_inst_with.split(':')[-1] - inst_without = dis_inst_without.split(':')[-1] - self.assertEqual(inst_with, inst_without) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/disassembly/TestFrameDisassemble.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/disassembly/TestFrameDisassemble.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/disassembly/TestFrameDisassemble.py @@ -1,65 +0,0 @@ -""" -Test to ensure SBFrame::Disassemble produces SOME output -""" - -from __future__ import print_function - - -import lldb -import lldbsuite.test.lldbutil as lldbutil -from lldbsuite.test.lldbtest import * - - -class FrameDisassembleTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - NO_DEBUG_INFO_TESTCASE = True - - def test_frame_disassemble(self): - """Sample test to ensure SBFrame::Disassemble produces SOME output.""" - self.build() - self.frame_disassemble_test() - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - - def frame_disassemble_test(self): - """Sample test to ensure SBFrame::Disassemble produces SOME output""" - exe = self.getBuildArtifact("a.out") - - # Create a target by the debugger. - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, VALID_TARGET) - - # Now create a breakpoint in main.c at the source matching - # "Set a breakpoint here" - breakpoint = target.BreakpointCreateBySourceRegex( - "Set a breakpoint here", lldb.SBFileSpec("main.cpp")) - self.assertTrue(breakpoint and - breakpoint.GetNumLocations() >= 1, - VALID_BREAKPOINT) - - error = lldb.SBError() - # This is the launch info. If you want to launch with arguments or - # environment variables, add them using SetArguments or - # SetEnvironmentEntries - - launch_info = lldb.SBLaunchInfo(None) - process = target.Launch(launch_info, error) - self.assertTrue(process, PROCESS_IS_VALID) - - # Did we hit our breakpoint? - from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint - threads = get_threads_stopped_at_breakpoint(process, breakpoint) - self.assertTrue( - len(threads) == 1, - "There should be a thread stopped at our breakpoint") - - # The hit count for the breakpoint should be 1. - self.assertTrue(breakpoint.GetHitCount() == 1) - - frame = threads[0].GetFrameAtIndex(0) - disassembly = frame.Disassemble() - self.assertTrue(len(disassembly) != 0, "Disassembly was empty.") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/disassembly/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/disassembly/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/disassembly/main.cpp @@ -1,27 +0,0 @@ -//===-- main.cpp ------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -int -sum (int a, int b) -{ - int result = a + b; // Set a breakpoint here - return result; -} - -int -main(int argc, char const *argv[]) -{ - - int array[3]; - - array[0] = sum (1238, 78392); - array[1] = sum (379265, 23674); - array[2] = sum (872934, 234); - - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/expr-doesnt-deadlock/.categories =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/expr-doesnt-deadlock/.categories +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/expr-doesnt-deadlock/.categories @@ -1 +0,0 @@ -expression Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/expr-doesnt-deadlock/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/expr-doesnt-deadlock/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/expr-doesnt-deadlock/Makefile @@ -1,6 +0,0 @@ -LEVEL = ../../make - -C_SOURCES := locking.c -ENABLE_THREADS := YES - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/expr-doesnt-deadlock/TestExprDoesntBlock.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/expr-doesnt-deadlock/TestExprDoesntBlock.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/expr-doesnt-deadlock/TestExprDoesntBlock.py @@ -1,60 +0,0 @@ -""" -Test that expr will time out and allow other threads to run if it blocks. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class ExprDoesntDeadlockTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr17946') - @expectedFailureAll( - oslist=["windows"], - bugnumber="Windows doesn't have pthreads, test needs to be ported") - @add_test_categories(["basic_process"]) - def test_with_run_command(self): - """Test that expr will time out and allow other threads to run if it blocks.""" - self.build() - exe = self.getBuildArtifact("a.out") - - # Create a target by the debugger. - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, VALID_TARGET) - - # Now create a breakpoint at source line before call_me_to_get_lock - # gets called. - - main_file_spec = lldb.SBFileSpec("locking.c") - breakpoint = target.BreakpointCreateBySourceRegex( - 'Break here', main_file_spec) - if self.TraceOn(): - print("breakpoint:", breakpoint) - self.assertTrue(breakpoint and - breakpoint.GetNumLocations() == 1, - VALID_BREAKPOINT) - - # Now launch the process, and do not stop at entry point. - process = target.LaunchSimple( - None, None, self.get_process_working_directory()) - self.assertTrue(process, PROCESS_IS_VALID) - - # Frame #0 should be on self.line1 and the break condition should hold. - from lldbsuite.test.lldbutil import get_stopped_thread - thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) - self.assertTrue( - thread.IsValid(), - "There should be a thread stopped due to breakpoint condition") - - frame0 = thread.GetFrameAtIndex(0) - - var = frame0.EvaluateExpression("call_me_to_get_lock()") - self.assertTrue(var.IsValid()) - self.assertTrue(var.GetValueAsSigned(0) == 567) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/expr-doesnt-deadlock/locking.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/expr-doesnt-deadlock/locking.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/expr-doesnt-deadlock/locking.c @@ -1,80 +0,0 @@ -#include -#include -#include -#include - -pthread_mutex_t contended_mutex = PTHREAD_MUTEX_INITIALIZER; - -pthread_mutex_t control_mutex = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t control_condition; - -pthread_mutex_t thread_started_mutex = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t thread_started_condition; - -// This function runs in a thread. The locking dance is to make sure that -// by the time the main thread reaches the pthread_join below, this thread -// has for sure acquired the contended_mutex. So then the call_me_to_get_lock -// function will block trying to get the mutex, and only succeed once it -// signals this thread, then lets it run to wake up from the cond_wait and -// release the mutex. - -void * -lock_acquirer_1 (void *input) -{ - pthread_mutex_lock (&contended_mutex); - - // Grab this mutex, that will ensure that the main thread - // is in its cond_wait for it (since that's when it drops the mutex. - - pthread_mutex_lock (&thread_started_mutex); - pthread_mutex_unlock(&thread_started_mutex); - - // Now signal the main thread that it can continue, we have the contended lock - // so the call to call_me_to_get_lock won't make any progress till this - // thread gets a chance to run. - - pthread_mutex_lock (&control_mutex); - - pthread_cond_signal (&thread_started_condition); - - pthread_cond_wait (&control_condition, &control_mutex); - - pthread_mutex_unlock (&contended_mutex); - return NULL; -} - -int -call_me_to_get_lock () -{ - pthread_cond_signal (&control_condition); - pthread_mutex_lock (&contended_mutex); - return 567; -} - -int main () -{ - pthread_t thread_1; - - pthread_cond_init (&control_condition, NULL); - pthread_cond_init (&thread_started_condition, NULL); - - pthread_mutex_lock (&thread_started_mutex); - - pthread_create (&thread_1, NULL, lock_acquirer_1, NULL); - - pthread_cond_wait (&thread_started_condition, &thread_started_mutex); - - pthread_mutex_lock (&control_mutex); - pthread_mutex_unlock (&control_mutex); - - // Break here. At this point the other thread will have the contended_mutex, - // and be sitting in its cond_wait for the control condition. So there is - // no way that our by-hand calling of call_me_to_get_lock will proceed - // without running the first thread at least somewhat. - - call_me_to_get_lock(); - pthread_join (thread_1, NULL); - - return 0; - -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/expr-entry-bp/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/expr-entry-bp/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/expr-entry-bp/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/expr-entry-bp/TestExprEntryBP.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/expr-entry-bp/TestExprEntryBP.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/expr-entry-bp/TestExprEntryBP.py @@ -1,34 +0,0 @@ -""" -Tests expressions evaluation when the breakpoint on module's entry is set. -""" - -import lldb -import lldbsuite.test.lldbutil as lldbutil -from lldbsuite.test.lldbtest import * - -class ExprEntryBPTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - NO_DEBUG_INFO_TESTCASE = True - - def test_expr_entry_bp(self): - """Tests expressions evaluation when the breakpoint on module's entry is set.""" - self.build() - self.main_source_file = lldb.SBFileSpec("main.c") - - (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, "Set a breakpoint here", self.main_source_file) - - self.assertEqual(1, bkpt.GetNumLocations()) - entry = bkpt.GetLocationAtIndex(0).GetAddress().GetModule().GetObjectFileEntryPointAddress() - self.assertTrue(entry.IsValid(), "Can't get a module entry point") - - entry_bp = target.BreakpointCreateBySBAddress(entry) - self.assertTrue(entry_bp.IsValid(), "Can't set a breakpoint on the module entry point") - - result = target.EvaluateExpression("sum(7, 1)") - self.assertTrue(result.IsValid(), "Can't evaluate expression") - self.assertEqual(8, result.GetValueAsSigned()) - - def setUp(self): - TestBase.setUp(self) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/expr-entry-bp/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/expr-entry-bp/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/expr-entry-bp/main.c @@ -1,10 +0,0 @@ -#include - -int sum(int x, int y) { - return x + y; -} - -int main() { - printf("Set a breakpoint here.\n"); - return sum(-1, 1); -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/array/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/array/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/array/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/array/TestArray.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/array/TestArray.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/array/TestArray.py @@ -1,31 +0,0 @@ -""" -Test the output of `frame diagnose` for an array access -""" - -from __future__ import print_function - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestArray(TestBase): - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - TestBase.setUp(self) - - @skipUnlessDarwin - @skipIfDarwinEmbedded # frame diagnose doesn't work for armv7 or arm64 - def test_array(self): - self.build() - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - self.runCmd("run", RUN_SUCCEEDED) - self.expect("thread list", "Thread should be stopped", - substrs=['stopped']) - self.expect( - "frame diagnose", - "Crash diagnosis was accurate", - substrs=["a[10]"]) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/array/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/array/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/array/main.c @@ -1,9 +0,0 @@ -struct Foo { - int b; - int c; -}; - -int main() { - struct Foo *a = 0; - return a[10].c; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/bad-reference/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/bad-reference/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/bad-reference/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/bad-reference/TestBadReference.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/bad-reference/TestBadReference.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/bad-reference/TestBadReference.py @@ -1,26 +0,0 @@ -""" -Test the output of `frame diagnose` for dereferencing a bad reference -""" - -from __future__ import print_function - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestBadReference(TestBase): - mydir = TestBase.compute_mydir(__file__) - - @skipUnlessDarwin - @skipIfDarwinEmbedded # frame diagnose doesn't work for armv7 or arm64 - def test_bad_reference(self): - TestBase.setUp(self) - self.build() - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - self.runCmd("run", RUN_SUCCEEDED) - self.expect("thread list", "Thread should be stopped", - substrs=['stopped']) - self.expect("frame diagnose", "Crash diagnosis was accurate", "f->b") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/bad-reference/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/bad-reference/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/bad-reference/main.cpp @@ -1,22 +0,0 @@ -struct Bar { - int c; - int d; -}; - -struct Foo { - int a; - struct Bar &b; -}; - -struct Foo *GetAFoo() { - static struct Foo f = { 0, *((Bar*)0) }; - return &f; -} - -int GetSum(struct Foo *f) { - return f->a + f->b.d; -} - -int main() { - return GetSum(GetAFoo()); -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/complicated-expression/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/complicated-expression/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/complicated-expression/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/complicated-expression/TestComplicatedExpression.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/complicated-expression/TestComplicatedExpression.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/complicated-expression/TestComplicatedExpression.py @@ -1,29 +0,0 @@ -""" -Test the output of `frame diagnose` for a subexpression of a complicated expression -""" - -from __future__ import print_function - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestDiagnoseDereferenceArgument(TestBase): - mydir = TestBase.compute_mydir(__file__) - - @skipUnlessDarwin - @skipIfDarwinEmbedded # frame diagnose doesn't work for armv7 or arm64 - def test_diagnose_dereference_argument(self): - TestBase.setUp(self) - self.build() - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - self.runCmd("run", RUN_SUCCEEDED) - self.expect("thread list", "Thread should be stopped", - substrs=['stopped']) - self.expect( - "frame diagnose", - "Crash diagnosis was accurate", - "f->b->d") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/complicated-expression/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/complicated-expression/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/complicated-expression/main.c @@ -1,26 +0,0 @@ -struct Bar { - int c; - int d; -}; - -struct Foo { - int a; - struct Bar *b; -}; - -struct Foo *GetAFoo() { - static struct Foo f = { 0, 0 }; - return &f; -} - -int SumTwoIntegers(int x, int y) { - return x + y; -} - -int GetSum(struct Foo *f) { - return SumTwoIntegers(f->a, f->b->d ? 0 : 1); -} - -int main() { - return GetSum(GetAFoo()); -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-argument/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-argument/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-argument/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-argument/TestDiagnoseDereferenceArgument.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-argument/TestDiagnoseDereferenceArgument.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-argument/TestDiagnoseDereferenceArgument.py @@ -1,29 +0,0 @@ -""" -Test the output of `frame diagnose` for dereferencing a function argument -""" - -from __future__ import print_function - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestDiagnoseDereferenceArgument(TestBase): - mydir = TestBase.compute_mydir(__file__) - - @skipUnlessDarwin - @skipIfDarwinEmbedded # frame diagnose doesn't work for armv7 or arm64 - def test_diagnose_dereference_argument(self): - TestBase.setUp(self) - self.build() - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - self.runCmd("run", RUN_SUCCEEDED) - self.expect("thread list", "Thread should be stopped", - substrs=['stopped']) - self.expect( - "frame diagnose", - "Crash diagnosis was accurate", - "f->b->d") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-argument/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-argument/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-argument/main.c @@ -1,22 +0,0 @@ -struct Bar { - int c; - int d; -}; - -struct Foo { - int a; - struct Bar *b; -}; - -struct Foo *GetAFoo() { - static struct Foo f = { 0, 0 }; - return &f; -} - -int GetSum(struct Foo *f) { - return f->a + f->b->d; -} - -int main() { - return GetSum(GetAFoo()); -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-function-return/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-function-return/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-function-return/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-function-return/TestDiagnoseDereferenceFunctionReturn.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-function-return/TestDiagnoseDereferenceFunctionReturn.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-function-return/TestDiagnoseDereferenceFunctionReturn.py @@ -1,32 +0,0 @@ -""" -Test the output of `frame diagnose` for dereferencing a function's return value -""" - -from __future__ import print_function - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestDiagnoseDereferenceFunctionReturn(TestBase): - mydir = TestBase.compute_mydir(__file__) - - @skipUnlessDarwin - @skipIfDarwinEmbedded # frame diagnose doesn't work for armv7 or arm64 - @expectedFailureAll(oslist=['macosx'], archs=['i386'], bugnumber="rdar://28656408") - def test_diagnose_dereference_function_return(self): - TestBase.setUp(self) - self.build() - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - self.runCmd("run", RUN_SUCCEEDED) - self.expect("thread list", "Thread should be stopped", - substrs=['stopped']) - self.expect( - "frame diagnose", - "Crash diagnosis was accurate", - substrs=[ - "GetAFoo", - "->b"]) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-function-return/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-function-return/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-function-return/main.c @@ -1,12 +0,0 @@ -struct Foo { - int a; - int b; -}; - -struct Foo *GetAFoo() { - return 0; -} - -int main() { - return GetAFoo()->b; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-this/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-this/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-this/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-this/TestDiagnoseDereferenceThis.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-this/TestDiagnoseDereferenceThis.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-this/TestDiagnoseDereferenceThis.py @@ -1,29 +0,0 @@ -""" -Test the output of `frame diagnose` for dereferencing `this` -""" - -from __future__ import print_function - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestDiagnoseDereferenceThis(TestBase): - mydir = TestBase.compute_mydir(__file__) - - @skipUnlessDarwin - @skipIfDarwinEmbedded # frame diagnose doesn't work for armv7 or arm64 - def test_diagnose_dereference_this(self): - TestBase.setUp(self) - self.build() - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - self.runCmd("run", RUN_SUCCEEDED) - self.expect("thread list", "Thread should be stopped", - substrs=['stopped']) - self.expect( - "frame diagnose", - "Crash diagnosis was accurate", - "this->a") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-this/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-this/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-this/main.cpp @@ -1,15 +0,0 @@ -struct Foo { - int a; - int b; - int Sum() { return a + b; } -}; - -struct Foo *GetAFoo() { - return (struct Foo*)0; -} - -int main() { - struct Foo *foo = GetAFoo(); - return foo->Sum(); -} - Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/inheritance/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/inheritance/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/inheritance/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/inheritance/TestDiagnoseInheritance.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/inheritance/TestDiagnoseInheritance.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/inheritance/TestDiagnoseInheritance.py @@ -1,26 +0,0 @@ -""" -Test the output of `frame diagnose` for calling virtual methods -""" - -from __future__ import print_function - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestDiagnoseInheritance(TestBase): - mydir = TestBase.compute_mydir(__file__) - - @skipUnlessDarwin - @skipIfDarwinEmbedded # frame diagnose doesn't work for armv7 or arm64 - def test_diagnose_inheritance(self): - TestBase.setUp(self) - self.build() - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - self.runCmd("run", RUN_SUCCEEDED) - self.expect("thread list", "Thread should be stopped", - substrs=['stopped']) - self.expect("frame diagnose", "Crash diagnosis was accurate", "d") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/inheritance/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/inheritance/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/inheritance/main.cpp @@ -1,69 +0,0 @@ -#include -#include - -class A -{ -public: - A(int a) : - m_a(a) - { - } - virtual ~A(){} - virtual int get2() const { return m_a; } - virtual int get() const { return m_a; } -protected: - int m_a; -}; - -class B : public A -{ -public: - B(int a, int b) : - A(a), - m_b(b) - { - } - - ~B() override - { - } - - int get2() const override - { - return m_b; - } - int get() const override - { - return m_b; - } - -protected: - int m_b; -}; - -struct C -{ - C(int c) : m_c(c){} - virtual ~C(){} - int m_c; -}; - -class D : public C, public B -{ -public: - D(int a, int b, int c, int d) : - C(c), - B(a, b), - m_d(d) - { - } -protected: - int m_d; -}; -int main (int argc, char const *argv[], char const *envp[]) -{ - D *good_d = new D(1, 2, 3, 4); - D *d = nullptr; - return d->get(); -} - Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/local-variable/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/local-variable/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/local-variable/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/local-variable/TestLocalVariable.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/local-variable/TestLocalVariable.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/local-variable/TestLocalVariable.py @@ -1,26 +0,0 @@ -""" -Test the output of `frame diagnose` for dereferencing a local variable -""" - -from __future__ import print_function - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestLocalVariable(TestBase): - mydir = TestBase.compute_mydir(__file__) - - @skipUnlessDarwin - @skipIfDarwinEmbedded # frame diagnose doesn't work for armv7 or arm64 - def test_local_variable(self): - TestBase.setUp(self) - self.build() - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - self.runCmd("run", RUN_SUCCEEDED) - self.expect("thread list", "Thread should be stopped", - substrs=['stopped']) - self.expect("frame diagnose", "Crash diagnosis was accurate", "myInt") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/local-variable/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/local-variable/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/local-variable/main.c @@ -1,4 +0,0 @@ -int main() { - int *myInt = 0; - return *myInt; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/virtual-method-call/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/virtual-method-call/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/virtual-method-call/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/virtual-method-call/TestDiagnoseDereferenceVirtualMethodCall.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/virtual-method-call/TestDiagnoseDereferenceVirtualMethodCall.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/virtual-method-call/TestDiagnoseDereferenceVirtualMethodCall.py @@ -1,26 +0,0 @@ -""" -Test the output of `frame diagnose` for calling virtual methods -""" - -from __future__ import print_function - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestDiagnoseVirtualMethodCall(TestBase): - mydir = TestBase.compute_mydir(__file__) - - @skipUnlessDarwin - @skipIfDarwinEmbedded # frame diagnose doesn't work for armv7 or arm64 - def test_diagnose_virtual_method_call(self): - TestBase.setUp(self) - self.build() - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - self.runCmd("run", RUN_SUCCEEDED) - self.expect("thread list", "Thread should be stopped", - substrs=['stopped']) - self.expect("frame diagnose", "Crash diagnosis was accurate", "foo") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/virtual-method-call/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/virtual-method-call/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-diagnose/virtual-method-call/main.cpp @@ -1,16 +0,0 @@ -class Foo { -public: - int a; - int b; - virtual int Sum() { return a + b; } -}; - -struct Foo *GetAFoo() { - return (struct Foo*)0; -} - -int main() { - struct Foo *foo = GetAFoo(); - return foo->Sum(); -} - Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-language/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-language/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-language/Makefile @@ -1,12 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp other.cpp other-2.cpp -C_SOURCES := somefunc.c - -include $(LEVEL)/Makefile.rules - -other-2.o: other-2.cpp - $(CXX) $(CFLAGS_NO_DEBUG) -c $(SRCDIR)/other-2.cpp - -somefunc.o: somefunc.c - $(CC) $(CFLAGS) -std=c99 -c $(SRCDIR)/somefunc.c Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-language/TestGuessLanguage.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-language/TestGuessLanguage.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-language/TestGuessLanguage.py @@ -1,86 +0,0 @@ -""" -Test the SB API SBFrame::GuessLanguage. -""" - -from __future__ import print_function - - -import lldb -import lldbsuite.test.lldbutil as lldbutil -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * - - -class TestFrameGuessLanguage(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # If your test case doesn't stress debug info, the - # set this to true. That way it won't be run once for - # each debug info format. - NO_DEBUG_INFO_TESTCASE = True - - @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr37658") - def test_guess_language(self): - """Test GuessLanguage for C and C++.""" - self.build() - self.do_test() - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - - def check_language(self, thread, frame_no, test_lang): - frame = thread.frames[frame_no] - self.assertTrue(frame.IsValid(), "Frame %d was not valid."%(frame_no)) - lang = frame.GuessLanguage() - self.assertEqual(lang, test_lang) - - def do_test(self): - """Test GuessLanguage for C & C++.""" - exe = self.getBuildArtifact("a.out") - - # Create a target by the debugger. - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, VALID_TARGET) - - # Now create a breakpoint in main.c at the source matching - # "Set a breakpoint here" - breakpoint = target.BreakpointCreateBySourceRegex( - "Set breakpoint here", lldb.SBFileSpec("somefunc.c")) - self.assertTrue(breakpoint and - breakpoint.GetNumLocations() >= 1, - VALID_BREAKPOINT) - - error = lldb.SBError() - # This is the launch info. If you want to launch with arguments or - # environment variables, add them using SetArguments or - # SetEnvironmentEntries - - launch_info = lldb.SBLaunchInfo(None) - process = target.Launch(launch_info, error) - self.assertTrue(process, PROCESS_IS_VALID) - - # Did we hit our breakpoint? - from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint - threads = get_threads_stopped_at_breakpoint(process, breakpoint) - self.assertTrue( - len(threads) == 1, - "There should be a thread stopped at our breakpoint") - - # The hit count for the breakpoint should be 1. - self.assertTrue(breakpoint.GetHitCount() == 1) - - thread = threads[0] - - c_frame_language = lldb.eLanguageTypeC99 - # gcc emits DW_LANG_C89 even if -std=c99 was specified - if "gcc" in self.getCompiler(): - c_frame_language = lldb.eLanguageTypeC89 - - self.check_language(thread, 0, c_frame_language) - self.check_language(thread, 1, lldb.eLanguageTypeC_plus_plus) - self.check_language(thread, 2, lldb.eLanguageTypeC_plus_plus) - - - Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-language/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-language/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-language/main.cpp @@ -1,10 +0,0 @@ -#include -#include "other.h" - -int -main() -{ - int test_var = 10; - Other::DoSomethingElse(); - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-language/other-2.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-language/other-2.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-language/other-2.cpp @@ -1,7 +0,0 @@ -#include "other.h" - -void -Other::DoSomethingElse() -{ - DoSomething(); -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-language/other.h =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-language/other.h +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-language/other.h @@ -1,7 +0,0 @@ -class Other -{ - public: - static void DoSomething(); - static void DoSomethingElse(); -}; - Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-language/other.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-language/other.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-language/other.cpp @@ -1,10 +0,0 @@ -#include "other.h" - -extern "C" void some_func(); - -void -Other::DoSomething() -{ - some_func(); -} - Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-language/somefunc.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-language/somefunc.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-language/somefunc.c @@ -1,7 +0,0 @@ -#include - -void -some_func() -{ - printf("Set breakpoint here."); -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-recognizer/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-recognizer/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-recognizer/Makefile @@ -1,10 +0,0 @@ -LEVEL = ../../make - -OBJC_SOURCES := main.m - -CFLAGS_EXTRAS += -g0 # No debug info. -MAKE_DSYM := NO - -include $(LEVEL)/Makefile.rules - -LDFLAGS += -framework Foundation Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-recognizer/TestFrameRecognizer.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-recognizer/TestFrameRecognizer.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-recognizer/TestFrameRecognizer.py @@ -1,119 +0,0 @@ -# encoding: utf-8 -""" -Test lldb's frame recognizers. -""" - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -import recognizer - -class FrameRecognizerTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - NO_DEBUG_INFO_TESTCASE = True - - @skipUnlessDarwin - def test_frame_recognizer_1(self): - self.build() - - target = self.dbg.CreateTarget(self.getBuildArtifact("a.out")) - self.assertTrue(target, VALID_TARGET) - - self.runCmd("command script import " + os.path.join(self.getSourceDir(), "recognizer.py")) - - self.expect("frame recognizer list", - substrs=['no matching results found.']) - - self.runCmd("frame recognizer add -l recognizer.MyFrameRecognizer -s a.out -n foo") - - self.expect("frame recognizer list", - substrs=['0: recognizer.MyFrameRecognizer, module a.out, function foo']) - - self.runCmd("frame recognizer add -l recognizer.MyOtherFrameRecognizer -s a.out -n bar -x") - - self.expect("frame recognizer list", - substrs=['0: recognizer.MyFrameRecognizer, module a.out, function foo', - '1: recognizer.MyOtherFrameRecognizer, module a.out, function bar (regexp)' - ]) - - self.runCmd("frame recognizer delete 0") - - self.expect("frame recognizer list", - substrs=['1: recognizer.MyOtherFrameRecognizer, module a.out, function bar (regexp)']) - - self.runCmd("frame recognizer clear") - - self.expect("frame recognizer list", - substrs=['no matching results found.']) - - self.runCmd("frame recognizer add -l recognizer.MyFrameRecognizer -s a.out -n foo") - - lldbutil.run_break_set_by_symbol(self, "foo") - self.runCmd("r") - - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', 'stop reason = breakpoint']) - - process = target.GetProcess() - thread = process.GetSelectedThread() - frame = thread.GetSelectedFrame() - - self.assertEqual(frame.GetSymbol().GetName(), "foo") - self.assertFalse(frame.GetLineEntry().IsValid()) - - self.expect("frame variable", - substrs=['(int) a = 42', '(int) b = 56']) - - # Recognized arguments don't show up by default... - variables = frame.GetVariables(lldb.SBVariablesOptions()) - self.assertEqual(variables.GetSize(), 0) - - # ...unless you set target.display-recognized-arguments to 1... - self.runCmd("settings set target.display-recognized-arguments 1") - variables = frame.GetVariables(lldb.SBVariablesOptions()) - self.assertEqual(variables.GetSize(), 2) - - # ...and you can reset it back to 0 to hide them again... - self.runCmd("settings set target.display-recognized-arguments 0") - variables = frame.GetVariables(lldb.SBVariablesOptions()) - self.assertEqual(variables.GetSize(), 0) - - # ... or explicitly ask for them with SetIncludeRecognizedArguments(True). - opts = lldb.SBVariablesOptions() - opts.SetIncludeRecognizedArguments(True) - variables = frame.GetVariables(opts) - - self.assertEqual(variables.GetSize(), 2) - self.assertEqual(variables.GetValueAtIndex(0).name, "a") - self.assertEqual(variables.GetValueAtIndex(0).signed, 42) - self.assertEqual(variables.GetValueAtIndex(0).GetValueType(), lldb.eValueTypeVariableArgument) - self.assertEqual(variables.GetValueAtIndex(1).name, "b") - self.assertEqual(variables.GetValueAtIndex(1).signed, 56) - self.assertEqual(variables.GetValueAtIndex(1).GetValueType(), lldb.eValueTypeVariableArgument) - - self.expect("frame recognizer info 0", - substrs=['frame 0 is recognized by recognizer.MyFrameRecognizer']) - - self.expect("frame recognizer info 999", error=True, - substrs=['no frame with index 999']) - - self.expect("frame recognizer info 1", - substrs=['frame 1 not recognized by any recognizer']) - - # FIXME: The following doesn't work yet, but should be fixed. - """ - lldbutil.run_break_set_by_symbol(self, "bar") - self.runCmd("c") - - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', 'stop reason = breakpoint']) - - self.expect("frame variable -t", - substrs=['(int *) a = ']) - - self.expect("frame variable -t *a", - substrs=['*a = 78']) - """ Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-recognizer/main.m =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-recognizer/main.m +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-recognizer/main.m @@ -1,27 +0,0 @@ -//===-- main.m ------------------------------------------------*- ObjC -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#import - -void foo(int a, int b) -{ - printf("%d %d\n", a, b); -} - -void bar(int *ptr) -{ - printf("%d\n", *ptr); -} - -int main (int argc, const char * argv[]) -{ - foo(42, 56); - int i = 78; - bar(&i); - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-recognizer/recognizer.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-recognizer/recognizer.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame-recognizer/recognizer.py @@ -1,21 +0,0 @@ -# encoding: utf-8 - -import lldb - -class MyFrameRecognizer(object): - def get_recognized_arguments(self, frame): - if frame.name == "foo": - arg1 = frame.EvaluateExpression("$arg1").signed - arg2 = frame.EvaluateExpression("$arg2").signed - val1 = lldb.target.CreateValueFromExpression("a", "%d" % arg1) - val2 = lldb.target.CreateValueFromExpression("b", "%d" % arg2) - return [val1, val2] - elif frame.name == "bar": - arg1 = frame.EvaluateExpression("$arg1").signed - val1 = lldb.target.CreateValueFromExpression("a", "(int *)%d" % arg1) - return [val1] - return [] - -class MyOtherFrameRecognizer(object): - def get_recognized_arguments(self, frame): - return [] Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var/Makefile @@ -1,6 +0,0 @@ -LEVEL = ../../make - -C_SOURCES := main.c -CFLAGS_EXTRAS += -std=c99 - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var/TestFrameVar.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var/TestFrameVar.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var/TestFrameVar.py @@ -1,96 +0,0 @@ -""" -Make sure the frame variable -g, -a, and -l flags work. -""" - -from __future__ import print_function - - -import lldb -import lldbsuite.test.lldbutil as lldbutil -from lldbsuite.test.lldbtest import * - - -class TestFrameVar(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # If your test case doesn't stress debug info, the - # set this to true. That way it won't be run once for - # each debug info format. - NO_DEBUG_INFO_TESTCASE = True - - def test_frame_var(self): - self.build() - self.do_test() - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - - def do_test(self): - exe = self.getBuildArtifact("a.out") - - # Create a target by the debugger. - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, VALID_TARGET) - - # Now create a breakpoint in main.c at the source matching - # "Set a breakpoint here" - breakpoint = target.BreakpointCreateBySourceRegex( - "Set a breakpoint here", lldb.SBFileSpec("main.c")) - self.assertTrue(breakpoint and - breakpoint.GetNumLocations() >= 1, - VALID_BREAKPOINT) - - error = lldb.SBError() - # This is the launch info. If you want to launch with arguments or - # environment variables, add them using SetArguments or - # SetEnvironmentEntries - - launch_info = lldb.SBLaunchInfo(None) - process = target.Launch(launch_info, error) - self.assertTrue(process, PROCESS_IS_VALID) - - # Did we hit our breakpoint? - from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint - threads = get_threads_stopped_at_breakpoint(process, breakpoint) - self.assertTrue( - len(threads) == 1, - "There should be a thread stopped at our breakpoint") - - # The hit count for the breakpoint should be 1. - self.assertTrue(breakpoint.GetHitCount() == 1) - - frame = threads[0].GetFrameAtIndex(0) - command_result = lldb.SBCommandReturnObject() - interp = self.dbg.GetCommandInterpreter() - - # Just get args: - result = interp.HandleCommand("frame var -l", command_result) - self.assertEqual(result, lldb.eReturnStatusSuccessFinishResult, "frame var -a didn't succeed") - output = command_result.GetOutput() - self.assertTrue("argc" in output, "Args didn't find argc") - self.assertTrue("argv" in output, "Args didn't find argv") - self.assertTrue("test_var" not in output, "Args found a local") - self.assertTrue("g_var" not in output, "Args found a global") - - # Just get locals: - result = interp.HandleCommand("frame var -a", command_result) - self.assertEqual(result, lldb.eReturnStatusSuccessFinishResult, "frame var -a didn't succeed") - output = command_result.GetOutput() - self.assertTrue("argc" not in output, "Locals found argc") - self.assertTrue("argv" not in output, "Locals found argv") - self.assertTrue("test_var" in output, "Locals didn't find test_var") - self.assertTrue("g_var" not in output, "Locals found a global") - - # Get the file statics: - result = interp.HandleCommand("frame var -l -a -g", command_result) - self.assertEqual(result, lldb.eReturnStatusSuccessFinishResult, "frame var -a didn't succeed") - output = command_result.GetOutput() - self.assertTrue("argc" not in output, "Globals found argc") - self.assertTrue("argv" not in output, "Globals found argv") - self.assertTrue("test_var" not in output, "Globals found test_var") - self.assertTrue("g_var" in output, "Globals didn't find g_var") - - - Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var/main.c @@ -1,11 +0,0 @@ -#include - -int g_var = 200; - -int -main(int argc, char **argv) -{ - int test_var = 10; - printf ("Set a breakpoint here: %d %d.\n", test_var, g_var); - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var_scope/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var_scope/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var_scope/Makefile @@ -1,3 +0,0 @@ -LEVEL = ../../make -C_SOURCES := main.c -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var_scope/TestFrameVariableScope.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var_scope/TestFrameVariableScope.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var_scope/TestFrameVariableScope.py @@ -1,5 +0,0 @@ -from lldbsuite.test import lldbinline -from lldbsuite.test import decorators - -lldbinline.MakeInlineTest( - __file__, globals(), []) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var_scope/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var_scope/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var_scope/main.c @@ -1,20 +0,0 @@ -//===-- main.c --------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -int foo(int x, int y) { - int z = 3 + x; - return z + y; //% self.expect("frame variable -s", substrs=['ARG: (int) x = -3','ARG: (int) y = 0']) - //% self.expect("frame variable -s x", substrs=['ARG: (int) x = -3']) - //% self.expect("frame variable -s y", substrs=['ARG: (int) y = 0']) - //% self.expect("frame variable -s z", substrs=['LOCAL: (int) z = 0']) -} - -int main (int argc, char const *argv[]) -{ - return foo(-3,0); //% self.expect("frame variable -s argc argv", substrs=['ARG: (int) argc =']) -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/launch_with_shellexpand/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/launch_with_shellexpand/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/launch_with_shellexpand/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/launch_with_shellexpand/TestLaunchWithShellExpand.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/launch_with_shellexpand/TestLaunchWithShellExpand.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/launch_with_shellexpand/TestLaunchWithShellExpand.py @@ -1,120 +0,0 @@ -""" -Test that argdumper is a viable launching strategy. -""" -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class LaunchWithShellExpandTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @expectedFailureAll( - oslist=[ - "windows", - "linux", - "freebsd"], - bugnumber="llvm.org/pr24778 llvm.org/pr22627") - @skipIfDarwinEmbedded # iOS etc don't launch the binary via a shell, so arg expansion won't happen - @expectedFailureNetBSD - def test(self): - self.build() - exe = self.getBuildArtifact("a.out") - - self.runCmd("target create %s" % exe) - - # Create the target - target = self.dbg.CreateTarget(exe) - - # Create any breakpoints we need - breakpoint = target.BreakpointCreateBySourceRegex( - 'break here', lldb.SBFileSpec("main.cpp", False)) - self.assertTrue(breakpoint, VALID_BREAKPOINT) - - self.runCmd( - "process launch -X true -w %s -- fi*.tx? () > <" % - (self.getSourceDir())) - - process = self.process() - - self.assertTrue(process.GetState() == lldb.eStateStopped, - STOPPED_DUE_TO_BREAKPOINT) - - thread = process.GetThreadAtIndex(0) - - self.assertTrue(thread.IsValid(), - "Process stopped at 'main' should have a valid thread") - - stop_reason = thread.GetStopReason() - - self.assertTrue( - stop_reason == lldb.eStopReasonBreakpoint, - "Thread in process stopped in 'main' should have a stop reason of eStopReasonBreakpoint") - - self.expect("frame variable argv[1]", substrs=['file1.txt']) - self.expect("frame variable argv[2]", substrs=['file2.txt']) - self.expect("frame variable argv[3]", substrs=['file3.txt']) - self.expect("frame variable argv[4]", substrs=['file4.txy']) - self.expect("frame variable argv[5]", substrs=['()']) - self.expect("frame variable argv[6]", substrs=['>']) - self.expect("frame variable argv[7]", substrs=['<']) - self.expect( - "frame variable argv[5]", - substrs=['file5.tyx'], - matching=False) - self.expect( - "frame variable argv[8]", - substrs=['file5.tyx'], - matching=False) - - self.runCmd("process kill") - - self.runCmd( - 'process launch -X true -w %s -- "foo bar"' % - (self.getSourceDir())) - - process = self.process() - - self.assertTrue(process.GetState() == lldb.eStateStopped, - STOPPED_DUE_TO_BREAKPOINT) - - thread = process.GetThreadAtIndex(0) - - self.assertTrue(thread.IsValid(), - "Process stopped at 'main' should have a valid thread") - - stop_reason = thread.GetStopReason() - - self.assertTrue( - stop_reason == lldb.eStopReasonBreakpoint, - "Thread in process stopped in 'main' should have a stop reason of eStopReasonBreakpoint") - - self.expect("frame variable argv[1]", substrs=['foo bar']) - - self.runCmd("process kill") - - self.runCmd('process launch -X true -w %s -- foo\ bar' - % (self.getBuildDir())) - - process = self.process() - - self.assertTrue(process.GetState() == lldb.eStateStopped, - STOPPED_DUE_TO_BREAKPOINT) - - thread = process.GetThreadAtIndex(0) - - self.assertTrue(thread.IsValid(), - "Process stopped at 'main' should have a valid thread") - - stop_reason = thread.GetStopReason() - - self.assertTrue( - stop_reason == lldb.eStopReasonBreakpoint, - "Thread in process stopped in 'main' should have a stop reason of eStopReasonBreakpoint") - - self.expect("frame variable argv[1]", substrs=['foo bar']) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/launch_with_shellexpand/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/launch_with_shellexpand/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/launch_with_shellexpand/main.cpp @@ -1,5 +0,0 @@ -int -main (int argc, char const **argv) -{ - return 0; // break here -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/nested_alias/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/nested_alias/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/nested_alias/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/nested_alias/TestNestedAlias.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/nested_alias/TestNestedAlias.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/nested_alias/TestNestedAlias.py @@ -1,90 +0,0 @@ -""" -Test that an alias can reference other aliases without crashing. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil - - -class NestedAliasTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to break inside main(). - self.line = line_number('main.cpp', '// break here') - - def test_nested_alias(self): - """Test that an alias can reference other aliases without crashing.""" - self.build() - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # Break in main() after the variables are assigned values. - 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) - - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', 'stop reason = breakpoint']) - - # The breakpoint should have a hit count of 1. - self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, - substrs=[' resolved, hit count = 1']) - - # This is the function to remove the custom aliases in order to have a - # clean slate for the next test case. - def cleanup(): - self.runCmd('command unalias read', check=False) - self.runCmd('command unalias rd', check=False) - self.runCmd('command unalias fo', check=False) - self.runCmd('command unalias foself', check=False) - - # Execute the cleanup function during test case tear down. - self.addTearDownHook(cleanup) - - self.runCmd('command alias read memory read -f A') - self.runCmd('command alias rd read -c 3') - - self.expect( - 'memory read -f A -c 3 `&my_ptr[0]`', - substrs=[ - 'deadbeef', - 'main.cpp:', - 'feedbeef']) - self.expect( - 'rd `&my_ptr[0]`', - substrs=[ - 'deadbeef', - 'main.cpp:', - 'feedbeef']) - - self.expect( - 'memory read -f A -c 3 `&my_ptr[0]`', - substrs=['deadfeed'], - matching=False) - self.expect('rd `&my_ptr[0]`', substrs=['deadfeed'], matching=False) - - self.runCmd('command alias fo frame variable -O --') - self.runCmd('command alias foself fo self') - - self.expect( - 'help foself', - substrs=[ - '--show-all-children', - '--raw-output'], - matching=False) - self.expect( - 'help foself', - substrs=[ - 'Show variables for the current', - 'stack frame.'], - matching=True) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/nested_alias/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/nested_alias/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/nested_alias/main.cpp @@ -1,21 +0,0 @@ -//===-- main.cpp ------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -#include - -int main (int argc, char const *argv[]) -{ - void* my_ptr[] = { - reinterpret_cast(0xDEADBEEF), - reinterpret_cast(main), - reinterpret_cast(0xFEEDBEEF), - reinterpret_cast(0xFEEDDEAD), - reinterpret_cast(0xDEADFEED) - }; - return 0; // break here -} - Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/nosucharch/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/nosucharch/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/nosucharch/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/nosucharch/TestNoSuchArch.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/nosucharch/TestNoSuchArch.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/nosucharch/TestNoSuchArch.py @@ -1,33 +0,0 @@ -""" -Test that using a non-existent architecture name does not crash LLDB. -""" -from __future__ import print_function - - -import lldb -from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil - - -class NoSuchArchTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def test(self): - self.build() - exe = self.getBuildArtifact("a.out") - - # Check that passing an invalid arch via the command-line fails but - # doesn't crash - self.expect( - "target crete --arch nothingtoseehere %s" % - (exe), error=True) - - # Check that passing an invalid arch via the SB API fails but doesn't - # crash - target = self.dbg.CreateTargetWithFileAndArch(exe, "nothingtoseehere") - self.assertFalse(target.IsValid(), "This target should not be valid") - - # Now just create the target with the default arch and check it's fine - target = self.dbg.CreateTarget(exe) - self.assertTrue(target.IsValid(), "This target should now be valid") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/nosucharch/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/nosucharch/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/nosucharch/main.cpp @@ -1,3 +0,0 @@ -int main() { - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/platform/TestPlatformCommand.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/platform/TestPlatformCommand.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/platform/TestPlatformCommand.py @@ -1,80 +0,0 @@ -""" -Test some lldb platform commands. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class PlatformCommandTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @no_debug_info_test - def test_help_platform(self): - self.runCmd("help platform") - - @no_debug_info_test - def test_list(self): - self.expect("platform list", - patterns=['^Available platforms:']) - - @no_debug_info_test - def test_process_list(self): - self.expect("platform process list", - substrs=['PID', 'TRIPLE', 'NAME']) - - @no_debug_info_test - def test_process_info_with_no_arg(self): - """This is expected to fail and to return a proper error message.""" - self.expect("platform process info", error=True, - substrs=['one or more process id(s) must be specified']) - - @no_debug_info_test - def test_status(self): - self.expect( - "platform status", - substrs=[ - 'Platform', - 'Triple', - 'OS Version', - 'Kernel', - 'Hostname']) - - @expectedFailureAll(oslist=["windows"]) - @no_debug_info_test - def test_shell(self): - """ Test that the platform shell command can invoke ls. """ - triple = self.dbg.GetSelectedPlatform().GetTriple() - if re.match(".*-.*-windows", triple): - self.expect( - "platform shell dir c:\\", substrs=[ - "Windows", "Program Files"]) - elif re.match(".*-.*-.*-android", triple): - self.expect( - "platform shell ls /", - substrs=[ - "cache", - "dev", - "system"]) - else: - self.expect("platform shell ls /", substrs=["dev", "tmp", "usr"]) - - @no_debug_info_test - def test_shell_builtin(self): - """ Test a shell built-in command (echo) """ - self.expect("platform shell echo hello lldb", - substrs=["hello lldb"]) - - # FIXME: re-enable once platform shell -t can specify the desired timeout - @no_debug_info_test - def test_shell_timeout(self): - """ Test a shell built-in command (sleep) that times out """ - self.skipTest("due to taking too long to complete.") - self.expect("platform shell sleep 15", error=True, substrs=[ - "error: timed out waiting for shell command to complete"]) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/platform/TestPlatformPython.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/platform/TestPlatformPython.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/platform/TestPlatformPython.py @@ -1,82 +0,0 @@ -""" -Test the lldb platform Python API. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class PlatformPythonTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @add_test_categories(['pyapi']) - @no_debug_info_test - def test_platform_list(self): - """Test SBDebugger::GetNumPlatforms() & GetPlatformAtIndex() API""" - # Verify the host platform is present by default. - initial_num_platforms = self.dbg.GetNumPlatforms() - self.assertGreater(initial_num_platforms, 0) - host_platform = self.dbg.GetPlatformAtIndex(0) - self.assertTrue(host_platform.IsValid() and - host_platform.GetName() == 'host', - 'The host platform is present') - # Select another platform and verify that the platform is added to - # the platform list. - platform_idx = self.dbg.GetNumAvailablePlatforms() - 1 - if platform_idx < 1: - self.fail('No platforms other than host are available') - platform_data = self.dbg.GetAvailablePlatformInfoAtIndex(platform_idx) - platform_name = platform_data.GetValueForKey('name').GetStringValue(100) - self.assertNotEqual(platform_name, 'host') - self.dbg.SetCurrentPlatform(platform_name) - selected_platform = self.dbg.GetSelectedPlatform() - self.assertTrue(selected_platform.IsValid()) - self.assertEqual(selected_platform.GetName(), platform_name) - self.assertEqual(self.dbg.GetNumPlatforms(), initial_num_platforms + 1) - platform_found = False - for platform_idx in range(self.dbg.GetNumPlatforms()): - platform = self.dbg.GetPlatformAtIndex(platform_idx) - if platform.GetName() == platform_name: - platform_found = True - break - self.assertTrue(platform_found) - - @add_test_categories(['pyapi']) - @no_debug_info_test - def test_host_is_connected(self): - # We've already tested that this one IS the host platform. - host_platform = self.dbg.GetPlatformAtIndex(0) - self.assertTrue(host_platform.IsConnected(), "The host platform is always connected") - - - @add_test_categories(['pyapi']) - @no_debug_info_test - def test_available_platform_list(self): - """Test SBDebugger::GetNumAvailablePlatforms() and GetAvailablePlatformInfoAtIndex() API""" - num_platforms = self.dbg.GetNumAvailablePlatforms() - self.assertGreater( - num_platforms, 0, - 'There should be at least one platform available') - - for i in range(num_platforms): - platform_data = self.dbg.GetAvailablePlatformInfoAtIndex(i) - name_data = platform_data.GetValueForKey('name') - desc_data = platform_data.GetValueForKey('description') - self.assertTrue( - name_data and name_data.IsValid(), - 'Platform has a name') - self.assertEqual( - name_data.GetType(), lldb.eStructuredDataTypeString, - 'Platform name is a string') - self.assertTrue( - desc_data and desc_data.IsValid(), - 'Platform has a description') - self.assertEqual( - desc_data.GetType(), lldb.eStructuredDataTypeString, - 'Platform description is a string') Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/plugins/command_plugin/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/plugins/command_plugin/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/plugins/command_plugin/Makefile @@ -0,0 +1,8 @@ +LEVEL = ../../../make + +DYLIB_CXX_SOURCES := plugin.cpp +DYLIB_NAME := plugin +DYLIB_ONLY := YES +MAKE_DSYM := NO + +include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/plugins/command_plugin/TestPluginCommands.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/plugins/command_plugin/TestPluginCommands.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/plugins/command_plugin/TestPluginCommands.py @@ -0,0 +1,78 @@ +""" +Test that plugins that load commands work correctly. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class PluginCommandTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + TestBase.setUp(self) + self.generateSource('plugin.cpp') + + @skipIfNoSBHeaders + # Requires a compatible arch and platform to link against the host's built + # lldb lib. + @skipIfHostIncompatibleWithRemote + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24778") + @no_debug_info_test + def test_load_plugin(self): + """Test that plugins that load commands work correctly.""" + + plugin_name = "plugin" + if sys.platform.startswith("darwin"): + plugin_lib_name = "lib%s.dylib" % plugin_name + else: + plugin_lib_name = "lib%s.so" % plugin_name + + # Invoke the library build rule. + self.buildLibrary("plugin.cpp", plugin_name) + + debugger = lldb.SBDebugger.Create() + + retobj = lldb.SBCommandReturnObject() + + retval = debugger.GetCommandInterpreter().HandleCommand( + "plugin load %s" % self.getBuildArtifact(plugin_lib_name), retobj) + + retobj.Clear() + + retval = debugger.GetCommandInterpreter().HandleCommand( + "plugin_loaded_command child abc def ghi", retobj) + + if self.TraceOn(): + print(retobj.GetOutput()) + + self.expect(retobj, substrs=['abc def ghi'], exe=False) + + retobj.Clear() + + # check that abbreviations work correctly in plugin commands. + retval = debugger.GetCommandInterpreter().HandleCommand( + "plugin_loaded_ ch abc def ghi", retobj) + + if self.TraceOn(): + print(retobj.GetOutput()) + + self.expect(retobj, substrs=['abc def ghi'], exe=False) + + @no_debug_info_test + def test_invalid_plugin_invocation(self): + self.expect("plugin load a b", + error=True, startstr="error: 'plugin load' requires one argument") + self.expect("plugin load", + error=True, startstr="error: 'plugin load' requires one argument") + + @no_debug_info_test + def test_invalid_plugin_target(self): + self.expect("plugin load ThisIsNotAValidPluginName", + error=True, startstr="error: no such file") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/plugins/command_plugin/plugin.cpp.template =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/plugins/command_plugin/plugin.cpp.template +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/plugins/command_plugin/plugin.cpp.template @@ -0,0 +1,53 @@ +//===-- plugin.cpp -------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +/* +An example plugin for LLDB that provides a new foo command with a child subcommand +Compile this into a dylib foo.dylib and load by placing in appropriate locations on disk or +by typing plugin load foo.dylib at the LLDB command line +*/ + +%include_SB_APIs% + +namespace lldb { + bool + PluginInitialize (lldb::SBDebugger debugger); +} + +class ChildCommand : public lldb::SBCommandPluginInterface +{ +public: + virtual bool + DoExecute (lldb::SBDebugger debugger, + char** command, + lldb::SBCommandReturnObject &result) + { + if (command) + { + const char* arg = *command; + while (arg) + { + result.Printf("%s ",arg); + arg = *(++command); + } + result.Printf("\n"); + return true; + } + return false; + } + +}; + +bool +lldb::PluginInitialize (lldb::SBDebugger debugger) +{ + lldb::SBCommandInterpreter interpreter = debugger.GetCommandInterpreter(); + lldb::SBCommand foo = interpreter.AddMultiwordCommand("plugin_loaded_command",NULL); + foo.AddCommand("child",new ChildCommand(),"a child of plugin_loaded_command"); + return true; +} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/plugins/commands/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/plugins/commands/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/plugins/commands/Makefile @@ -1,8 +0,0 @@ -LEVEL = ../../../make - -DYLIB_CXX_SOURCES := plugin.cpp -DYLIB_NAME := plugin -DYLIB_ONLY := YES -MAKE_DSYM := NO - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/plugins/commands/TestPluginCommands.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/plugins/commands/TestPluginCommands.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/plugins/commands/TestPluginCommands.py @@ -1,78 +0,0 @@ -""" -Test that plugins that load commands work correctly. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class PluginCommandTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - TestBase.setUp(self) - self.generateSource('plugin.cpp') - - @skipIfNoSBHeaders - # Requires a compatible arch and platform to link against the host's built - # lldb lib. - @skipIfHostIncompatibleWithRemote - @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24778") - @no_debug_info_test - def test_load_plugin(self): - """Test that plugins that load commands work correctly.""" - - plugin_name = "plugin" - if sys.platform.startswith("darwin"): - plugin_lib_name = "lib%s.dylib" % plugin_name - else: - plugin_lib_name = "lib%s.so" % plugin_name - - # Invoke the library build rule. - self.buildLibrary("plugin.cpp", plugin_name) - - debugger = lldb.SBDebugger.Create() - - retobj = lldb.SBCommandReturnObject() - - retval = debugger.GetCommandInterpreter().HandleCommand( - "plugin load %s" % self.getBuildArtifact(plugin_lib_name), retobj) - - retobj.Clear() - - retval = debugger.GetCommandInterpreter().HandleCommand( - "plugin_loaded_command child abc def ghi", retobj) - - if self.TraceOn(): - print(retobj.GetOutput()) - - self.expect(retobj, substrs=['abc def ghi'], exe=False) - - retobj.Clear() - - # check that abbreviations work correctly in plugin commands. - retval = debugger.GetCommandInterpreter().HandleCommand( - "plugin_loaded_ ch abc def ghi", retobj) - - if self.TraceOn(): - print(retobj.GetOutput()) - - self.expect(retobj, substrs=['abc def ghi'], exe=False) - - @no_debug_info_test - def test_invalid_plugin_invocation(self): - self.expect("plugin load a b", - error=True, startstr="error: 'plugin load' requires one argument") - self.expect("plugin load", - error=True, startstr="error: 'plugin load' requires one argument") - - @no_debug_info_test - def test_invalid_plugin_target(self): - self.expect("plugin load ThisIsNotAValidPluginName", - error=True, startstr="error: no such file") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/plugins/commands/plugin.cpp.template =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/plugins/commands/plugin.cpp.template +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/plugins/commands/plugin.cpp.template @@ -1,53 +0,0 @@ -//===-- plugin.cpp -------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -/* -An example plugin for LLDB that provides a new foo command with a child subcommand -Compile this into a dylib foo.dylib and load by placing in appropriate locations on disk or -by typing plugin load foo.dylib at the LLDB command line -*/ - -%include_SB_APIs% - -namespace lldb { - bool - PluginInitialize (lldb::SBDebugger debugger); -} - -class ChildCommand : public lldb::SBCommandPluginInterface -{ -public: - virtual bool - DoExecute (lldb::SBDebugger debugger, - char** command, - lldb::SBCommandReturnObject &result) - { - if (command) - { - const char* arg = *command; - while (arg) - { - result.Printf("%s ",arg); - arg = *(++command); - } - result.Printf("\n"); - return true; - } - return false; - } - -}; - -bool -lldb::PluginInitialize (lldb::SBDebugger debugger) -{ - lldb::SBCommandInterpreter interpreter = debugger.GetCommandInterpreter(); - lldb::SBCommand foo = interpreter.AddMultiwordCommand("plugin_loaded_command",NULL); - foo.AddCommand("child",new ChildCommand(),"a child of plugin_loaded_command"); - return true; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_attach/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_attach/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_attach/Makefile @@ -1,7 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -EXE := ProcessAttach - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_attach/TestProcessAttach.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_attach/TestProcessAttach.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_attach/TestProcessAttach.py @@ -1,91 +0,0 @@ -""" -Test process attach. -""" - -from __future__ import print_function - - -import os -import lldb -import shutil -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -exe_name = "ProcessAttach" # Must match Makefile - - -class ProcessAttachTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - NO_DEBUG_INFO_TESTCASE = True - - @skipIfiOSSimulator - @expectedFailureNetBSD - def test_attach_to_process_by_id(self): - """Test attach by process id""" - self.build() - exe = self.getBuildArtifact(exe_name) - - # Spawn a new process - popen = self.spawnSubprocess(exe) - self.addTearDownHook(self.cleanupSubprocesses) - - self.runCmd("process attach -p " + str(popen.pid)) - - target = self.dbg.GetSelectedTarget() - - process = target.GetProcess() - self.assertTrue(process, PROCESS_IS_VALID) - - @expectedFailureNetBSD - def test_attach_to_process_from_different_dir_by_id(self): - """Test attach by process id""" - newdir = self.getBuildArtifact("newdir") - try: - os.mkdir(newdir) - except OSError as e: - if e.errno != os.errno.EEXIST: - raise - testdir = self.getBuildDir() - exe = os.path.join(newdir, 'proc_attach') - self.buildProgram('main.cpp', exe) - self.addTearDownHook(lambda: shutil.rmtree(newdir)) - - # Spawn a new process - popen = self.spawnSubprocess(exe) - self.addTearDownHook(self.cleanupSubprocesses) - - os.chdir(newdir) - self.addTearDownHook(lambda: os.chdir(testdir)) - self.runCmd("process attach -p " + str(popen.pid)) - - target = self.dbg.GetSelectedTarget() - - process = target.GetProcess() - self.assertTrue(process, PROCESS_IS_VALID) - - @expectedFailureNetBSD - def test_attach_to_process_by_name(self): - """Test attach by process name""" - self.build() - exe = self.getBuildArtifact(exe_name) - - # Spawn a new process - popen = self.spawnSubprocess(exe) - self.addTearDownHook(self.cleanupSubprocesses) - - self.runCmd("process attach -n " + exe_name) - - target = self.dbg.GetSelectedTarget() - - process = target.GetProcess() - self.assertTrue(process, PROCESS_IS_VALID) - - def tearDown(self): - # Destroy process before TestBase.tearDown() - self.dbg.GetSelectedTarget().GetProcess().Destroy() - - # Call super's tearDown(). - TestBase.tearDown(self) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/Makefile @@ -1,14 +0,0 @@ -LEVEL = ../../../make - -CXX_SOURCES := main.cpp - -EXE := AttachDenied - -all: AttachDenied sign - -include $(LEVEL)/Makefile.rules - -sign: entitlements.plist AttachDenied -ifeq ($(OS),Darwin) - codesign -s - -f --entitlements $^ -endif Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/TestAttachDenied.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/TestAttachDenied.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/TestAttachDenied.py @@ -1,46 +0,0 @@ -""" -Test denied process attach. -""" - -from __future__ import print_function - - -import time -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -exe_name = 'AttachDenied' # Must match Makefile - - -class AttachDeniedTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - NO_DEBUG_INFO_TESTCASE = True - - @skipIfWindows - @skipIfiOSSimulator - @skipIfDarwinEmbedded # ptrace(ATTACH_REQUEST...) won't work on ios/tvos/etc - def test_attach_to_process_by_id_denied(self): - """Test attach by process id denied""" - self.build() - exe = self.getBuildArtifact(exe_name) - - # Use a file as a synchronization point between test and inferior. - pid_file_path = lldbutil.append_to_process_working_directory(self, - "pid_file_%d" % (int(time.time()))) - self.addTearDownHook( - lambda: self.run_platform_command( - "rm %s" % - (pid_file_path))) - - # Spawn a new process - popen = self.spawnSubprocess(exe, [pid_file_path]) - self.addTearDownHook(self.cleanupSubprocesses) - - pid = lldbutil.wait_for_file_on_target(self, pid_file_path) - - self.expect('process attach -p ' + pid, - startstr='error: attach failed:', - error=True) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/entitlements.plist =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/entitlements.plist +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/entitlements.plist @@ -1,8 +0,0 @@ - - - - - com.apple.security.cs.debugger - - - Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/main.cpp @@ -1,108 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#if defined(PTRACE_ATTACH) -#define ATTACH_REQUEST PTRACE_ATTACH -#define DETACH_REQUEST PTRACE_DETACH -#elif defined(PT_ATTACH) -#define ATTACH_REQUEST PT_ATTACH -#define DETACH_REQUEST PT_DETACH -#else -#error "Unsupported platform" -#endif - -bool writePid (const char* file_name, const pid_t pid) -{ - char *tmp_file_name = (char *)malloc(strlen(file_name) + 16); - strcpy(tmp_file_name, file_name); - strcat(tmp_file_name, "_tmp"); - int fd = open (tmp_file_name, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR); - if (fd == -1) - { - fprintf (stderr, "open(%s) failed: %s\n", tmp_file_name, strerror (errno)); - free(tmp_file_name); - return false; - } - char buffer[64]; - snprintf (buffer, sizeof(buffer), "%ld", (long)pid); - - bool res = true; - if (write (fd, buffer, strlen (buffer)) == -1) - { - fprintf (stderr, "write(%s) failed: %s\n", buffer, strerror (errno)); - res = false; - } - close (fd); - - if (rename (tmp_file_name, file_name) == -1) - { - fprintf (stderr, "rename(%s, %s) failed: %s\n", tmp_file_name, file_name, strerror (errno)); - res = false; - } - free(tmp_file_name); - - return res; -} - -void signal_handler (int) -{ -} - -int main (int argc, char const *argv[]) -{ - if (argc < 2) - { - fprintf (stderr, "invalid number of command line arguments\n"); - return 1; - } - - const pid_t pid = fork (); - if (pid == -1) - { - fprintf (stderr, "fork failed: %s\n", strerror (errno)); - return 1; - } - - if (pid > 0) - { - // Make pause call to return when a signal is received. Normally this happens when the - // test runner tries to terminate us. - signal (SIGHUP, signal_handler); - signal (SIGTERM, signal_handler); - if (ptrace (ATTACH_REQUEST, pid, NULL, 0) == -1) - { - fprintf (stderr, "ptrace(ATTACH) failed: %s\n", strerror (errno)); - } - else - { - if (writePid (argv[1], pid)) - pause (); // Waiting for the debugger trying attach to the child. - - if (ptrace (DETACH_REQUEST, pid, NULL, 0) != 0) - fprintf (stderr, "ptrace(DETACH) failed: %s\n", strerror (errno)); - } - - kill (pid, SIGTERM); - int status = 0; - if (waitpid (pid, &status, 0) == -1) - fprintf (stderr, "waitpid failed: %s\n", strerror (errno)); - } - else - { - // child inferior. - pause (); - } - - printf ("Exiting now\n"); - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_attach/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_attach/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_attach/main.cpp @@ -1,20 +0,0 @@ -#include - -#include -#include - -int main(int argc, char const *argv[]) { - int temp; - lldb_enable_attach(); - - // Waiting to be attached by the debugger. - temp = 0; - - while (temp < 30) // Waiting to be attached... - { - std::this_thread::sleep_for(std::chrono::seconds(2)); - temp++; - } - - printf("Exiting now\n"); -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_launch/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_launch/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_launch/Makefile @@ -1,7 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp -#CXX_SOURCES := print-cwd.cpp - -include $(LEVEL)/Makefile.rules - Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_launch/TestProcessLaunch.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_launch/TestProcessLaunch.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_launch/TestProcessLaunch.py @@ -1,205 +0,0 @@ -""" -Test lldb process launch flags. -""" - -from __future__ import print_function - -import os - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -import six - - -class ProcessLaunchTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - NO_DEBUG_INFO_TESTCASE = True - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - self.runCmd("settings set auto-confirm true") - - def tearDown(self): - self.runCmd("settings clear auto-confirm") - TestBase.tearDown(self) - - @not_remote_testsuite_ready - def test_io(self): - """Test that process launch I/O redirection flags work properly.""" - self.build() - exe = self.getBuildArtifact("a.out") - self.expect("file " + exe, - patterns=["Current executable set to .*a.out"]) - - in_file = os.path.join(self.getSourceDir(), "input-file.txt") - out_file = lldbutil.append_to_process_working_directory(self, "output-test.out") - err_file = lldbutil.append_to_process_working_directory(self, "output-test.err") - - # Make sure the output files do not exist before launching the process - try: - os.remove(out_file) - except OSError: - pass - - try: - os.remove(err_file) - except OSError: - pass - - launch_command = "process launch -i '{0}' -o '{1}' -e '{2}' -w '{3}'".format( - in_file, out_file, err_file, self.get_process_working_directory()) - - if lldb.remote_platform: - self.runCmd('platform put-file "{local}" "{remote}"'.format( - local=in_file, remote=in_file)) - - self.expect(launch_command, - patterns=["Process .* launched: .*a.out"]) - - success = True - err_msg = "" - - out = lldbutil.read_file_on_target(self, out_file) - if out != "This should go to stdout.\n": - success = False - err_msg = err_msg + " ERROR: stdout file does not contain correct output.\n" - - - err = lldbutil.read_file_on_target(self, err_file) - if err != "This should go to stderr.\n": - success = False - err_msg = err_msg + " ERROR: stderr file does not contain correct output.\n" - - if not success: - self.fail(err_msg) - - # rdar://problem/9056462 - # The process launch flag '-w' for setting the current working directory - # not working? - @not_remote_testsuite_ready - @expectedFailureAll(oslist=["linux"], bugnumber="llvm.org/pr20265") - @expectedFailureNetBSD - def test_set_working_dir_nonexisting(self): - """Test that '-w dir' fails to set the working dir when running the inferior with a dir which doesn't exist.""" - d = {'CXX_SOURCES': 'print_cwd.cpp'} - self.build(dictionary=d) - self.setTearDownCleanup(d) - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe) - - mywd = 'my_working_dir' - out_file_name = "my_working_dir_test.out" - err_file_name = "my_working_dir_test.err" - - my_working_dir_path = self.getBuildArtifact(mywd) - out_file_path = os.path.join(my_working_dir_path, out_file_name) - err_file_path = os.path.join(my_working_dir_path, err_file_name) - - # Check that we get an error when we have a nonexisting path - invalid_dir_path = mywd + 'z' - launch_command = "process launch -w %s -o %s -e %s" % ( - invalid_dir_path, out_file_path, err_file_path) - - self.expect( - launch_command, error=True, patterns=[ - "error:.* No such file or directory: %s" % - invalid_dir_path]) - - @not_remote_testsuite_ready - def test_set_working_dir_existing(self): - """Test that '-w dir' sets the working dir when running the inferior.""" - d = {'CXX_SOURCES': 'print_cwd.cpp'} - self.build(dictionary=d) - self.setTearDownCleanup(d) - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe) - - mywd = 'my_working_dir' - out_file_name = "my_working_dir_test.out" - err_file_name = "my_working_dir_test.err" - - my_working_dir_path = self.getBuildArtifact(mywd) - lldbutil.mkdir_p(my_working_dir_path) - out_file_path = os.path.join(my_working_dir_path, out_file_name) - err_file_path = os.path.join(my_working_dir_path, err_file_name) - - # Make sure the output files do not exist before launching the process - try: - os.remove(out_file_path) - os.remove(err_file_path) - except OSError: - pass - - launch_command = "process launch -w %s -o %s -e %s" % ( - my_working_dir_path, out_file_path, err_file_path) - - self.expect(launch_command, - patterns=["Process .* launched: .*a.out"]) - - success = True - err_msg = "" - - # Check to see if the 'stdout' file was created - try: - out_f = open(out_file_path) - except IOError: - success = False - err_msg = err_msg + "ERROR: stdout file was not created.\n" - else: - # Check to see if the 'stdout' file contains the right output - line = out_f.readline() - if self.TraceOn(): - print("line:", line) - if not re.search(mywd, line): - success = False - err_msg = err_msg + "The current working directory was not set correctly.\n" - out_f.close() - - # Try to delete the 'stdout' and 'stderr' files - try: - os.remove(out_file_path) - os.remove(err_file_path) - except OSError: - pass - - if not success: - self.fail(err_msg) - - def test_environment_with_special_char(self): - """Test that environment variables containing '*' and '}' are handled correctly by the inferior.""" - source = 'print_env.cpp' - d = {'CXX_SOURCES': source} - self.build(dictionary=d) - self.setTearDownCleanup(d) - exe = self.getBuildArtifact("a.out") - - evil_var = 'INIT*MIDDLE}TAIL' - - target = self.dbg.CreateTarget(exe) - main_source_spec = lldb.SBFileSpec(source) - breakpoint = target.BreakpointCreateBySourceRegex( - '// Set breakpoint here.', main_source_spec) - - process = target.LaunchSimple(None, - ['EVIL=' + evil_var], - self.get_process_working_directory()) - self.assertEqual( - process.GetState(), - lldb.eStateStopped, - PROCESS_STOPPED) - - threads = lldbutil.get_threads_stopped_at_breakpoint( - process, breakpoint) - self.assertEqual(len(threads), 1) - frame = threads[0].GetFrameAtIndex(0) - sbvalue = frame.EvaluateExpression("evil") - value = sbvalue.GetSummary().strip('"') - - self.assertEqual(value, evil_var) - process.Continue() - self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_launch/input-file.txt =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_launch/input-file.txt +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_launch/input-file.txt @@ -1,2 +0,0 @@ -This should go to stdout. -This should go to stderr. Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_launch/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_launch/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_launch/main.cpp @@ -1,17 +0,0 @@ -#include -#include - -int -main (int argc, char **argv) -{ - char buffer[1024]; - - fgets (buffer, sizeof (buffer), stdin); - fprintf (stdout, "%s", buffer); - - - fgets (buffer, sizeof (buffer), stdin); - fprintf (stderr, "%s", buffer); - - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_launch/print_cwd.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_launch/print_cwd.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_launch/print_cwd.cpp @@ -1,21 +0,0 @@ -#include - -#ifdef _MSC_VER -#define _CRT_NONSTDC_NO_WARNINGS -#include -#undef getcwd -#define getcwd(buffer, length) _getcwd(buffer, length) -#else -#include -#endif - -int -main (int argc, char **argv) -{ - char buffer[1024]; - - fprintf(stdout, "stdout: %s\n", getcwd(buffer, 1024)); - fprintf(stderr, "stderr: %s\n", getcwd(buffer, 1024)); - - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_launch/print_env.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_launch/print_env.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_launch/print_env.cpp @@ -1,10 +0,0 @@ -#include -#include -#include - -int main (int argc, char **argv) -{ - char *evil = getenv("EVIL"); - - return 0; // Set breakpoint here. -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/Makefile @@ -1,7 +0,0 @@ -LEVEL = ../../../make - -CXX_SOURCES := main.cpp - -CFLAGS_EXTRAS += -mmpx -fcheck-pointer-bounds -fuse-ld=bfd - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/TestMPXRegisters.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/TestMPXRegisters.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/TestMPXRegisters.py @@ -1,65 +0,0 @@ -""" -Test the Intel(R) MPX registers. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class RegisterCommandsTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - TestBase.setUp(self) - - @skipIf(compiler="clang") - @skipIf(oslist=no_match(['linux'])) - @skipIf(archs=no_match(['i386', 'x86_64'])) - @skipIf(oslist=["linux"], compiler="gcc", compiler_version=["<", "5"]) #GCC version >= 5 supports Intel(R) MPX. - def test_mpx_registers_with_example_code(self): - """Test Intel(R) MPX registers with example code.""" - self.build() - self.mpx_registers_with_example_code() - - def mpx_registers_with_example_code(self): - """Test Intel(R) MPX registers after running example code.""" - self.line = line_number('main.cpp', '// Set a break point here.') - - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.line, num_expected_locations=1) - self.runCmd("run", RUN_SUCCEEDED) - - target = self.dbg.GetSelectedTarget() - process = target.GetProcess() - - if (process.GetState() == lldb.eStateExited): - self.skipTest("Intel(R) MPX is not supported.") - else: - self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, - substrs = ["stop reason = breakpoint 1."]) - - if self.getArchitecture() == 'x86_64': - self.expect("register read -s 3", - substrs = ['bnd0 = {0x0000000000000010 0xffffffffffffffe6}', - 'bnd1 = {0x0000000000000020 0xffffffffffffffd6}', - 'bnd2 = {0x0000000000000030 0xffffffffffffffc6}', - 'bnd3 = {0x0000000000000040 0xffffffffffffffb6}', - 'bndcfgu = {0x01 0x80 0xb5 0x76 0xff 0x7f 0x00 0x00}', - 'bndstatus = {0x02 0x80 0xb5 0x76 0xff 0x7f 0x00 0x00}']) - if self.getArchitecture() == 'i386': - self.expect("register read -s 3", - substrs = ['bnd0 = {0x0000000000000010 0x00000000ffffffe6}', - 'bnd1 = {0x0000000000000020 0x00000000ffffffd6}', - 'bnd2 = {0x0000000000000030 0x00000000ffffffc6}', - 'bnd3 = {0x0000000000000040 0x00000000ffffffb6}', - 'bndcfgu = {0x01 0xd0 0x7d 0xf7 0x00 0x00 0x00 0x00}', - 'bndstatus = {0x02 0xd0 0x7d 0xf7 0x00 0x00 0x00 0x00}']) - Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/main.cpp @@ -1,61 +0,0 @@ -//===-- main.cpp ------------------------------------------------*- C++ -*-===// -//// -//// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -//// See https://llvm.org/LICENSE.txt for license information. -//// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -//// -////===----------------------------------------------------------------------===// -// - -#include -#include - -int -main(int argc, char const *argv[]) -{ -// PR_MPX_ENABLE_MANAGEMENT won't be defined on linux kernel versions below 3.19 -#ifndef PR_MPX_ENABLE_MANAGEMENT - return -1; -#endif - - // This call returns 0 only if the CPU and the kernel support Intel(R) MPX. - if (prctl(PR_MPX_ENABLE_MANAGEMENT, 0, 0, 0, 0) != 0) - return -1; - -// Run Intel(R) MPX test code. -#if defined(__x86_64__) - asm("mov $16, %rax\n\t" - "mov $9, %rdx\n\t" - "bndmk (%rax,%rdx), %bnd0\n\t" - "mov $32, %rax\n\t" - "mov $9, %rdx\n\t" - "bndmk (%rax,%rdx), %bnd1\n\t" - "mov $48, %rax\n\t" - "mov $9, %rdx\n\t" - "bndmk (%rax,%rdx), %bnd2\n\t" - "mov $64, %rax\n\t" - "mov $9, %rdx\n\t" - "bndmk (%rax,%rdx), %bnd3\n\t" - "bndstx %bnd3, (%rax) \n\t" - "nop\n\t"); -#endif -#if defined(__i386__) - asm("mov $16, %eax\n\t" - "mov $9, %edx\n\t" - "bndmk (%eax,%edx), %bnd0\n\t" - "mov $32, %eax\n\t" - "mov $9, %edx\n\t" - "bndmk (%eax,%edx), %bnd1\n\t" - "mov $48, %eax\n\t" - "mov $9, %edx\n\t" - "bndmk (%eax,%edx), %bnd2\n\t" - "mov $64, %eax\n\t" - "mov $9, %edx\n\t" - "bndmk (%eax,%edx), %bnd3\n\t" - "bndstx %bnd3, (%eax)\n\t" - "nop\n\t"); -#endif - asm("nop\n\t"); // Set a break point here. - - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/mpx_bound_violation/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/mpx_bound_violation/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/mpx_bound_violation/Makefile @@ -1,7 +0,0 @@ -LEVEL = ../../../../make - -CXX_SOURCES := main.cpp - -CFLAGS_EXTRAS += -mmpx -fcheck-pointer-bounds -fuse-ld=bfd - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/mpx_bound_violation/TestBoundViolation.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/mpx_bound_violation/TestBoundViolation.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/mpx_bound_violation/TestBoundViolation.py @@ -1,53 +0,0 @@ -""" -Test the Intel(R) MPX bound violation signal. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class RegisterCommandsTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @skipIf(compiler="clang") - @skipIf(oslist=no_match(['linux'])) - @skipIf(archs=no_match(['i386', 'x86_64'])) - @skipIf(oslist=["linux"], compiler="gcc", compiler_version=["<", "5"]) #GCC version >= 5 supports Intel(R) MPX. - def test_mpx_boundary_violation(self): - """Test Intel(R) MPX bound violation signal.""" - self.build() - self.mpx_boundary_violation() - - def mpx_boundary_violation(self): - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - self.runCmd("run", RUN_SUCCEEDED) - - target = self.dbg.GetSelectedTarget() - process = target.GetProcess() - - if (process.GetState() == lldb.eStateExited): - self.skipTest("Intel(R) MPX is not supported.") - - if (process.GetState() == lldb.eStateStopped): - self.expect("thread backtrace", STOPPED_DUE_TO_SIGNAL, - substrs = ['stop reason = signal SIGSEGV: upper bound violation', - 'fault address:', 'lower bound:', 'upper bound:']) - - self.runCmd("continue") - - if (process.GetState() == lldb.eStateStopped): - self.expect("thread backtrace", STOPPED_DUE_TO_SIGNAL, - substrs = ['stop reason = signal SIGSEGV: lower bound violation', - 'fault address:', 'lower bound:', 'upper bound:']) - - self.runCmd("continue") - self.assertTrue(process.GetState() == lldb.eStateExited, - PROCESS_EXITED) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/mpx_bound_violation/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/mpx_bound_violation/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/mpx_bound_violation/main.cpp @@ -1,44 +0,0 @@ -//===-- main.cpp ------------------------------------------------*- C++ -*-===// -//// -//// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -//// See https://llvm.org/LICENSE.txt for license information. -//// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -//// -////===----------------------------------------------------------------------===// -// - -#include -#include - -static void violate_upper_bound(int *ptr, int size) -{ - int i; - i = *(ptr + size); -} - -static void violate_lower_bound (int *ptr, int size) -{ - int i; - i = *(ptr - size); -} - -int -main(int argc, char const *argv[]) -{ - unsigned int rax, rbx, rcx, rdx; - int array[5]; - -// PR_MPX_ENABLE_MANAGEMENT won't be defined on linux kernel versions below 3.19 -#ifndef PR_MPX_ENABLE_MANAGEMENT - return -1; -#endif - - // This call returns 0 only if the CPU and the kernel support Intel(R) MPX. - if (prctl(PR_MPX_ENABLE_MANAGEMENT, 0, 0, 0, 0) != 0) - return -1; - - violate_upper_bound(array, 5); - violate_lower_bound(array, 5); - - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/register_command/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/register_command/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/register_command/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -CXX_SOURCES := main.cpp a.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/register_command/TestRegisters.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/register_command/TestRegisters.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/register_command/TestRegisters.py @@ -1,505 +0,0 @@ -""" -Test the 'register' command. -""" - -from __future__ import print_function - - -import os -import sys -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class RegisterCommandsTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - NO_DEBUG_INFO_TESTCASE = True - - def setUp(self): - TestBase.setUp(self) - self.has_teardown = False - - def tearDown(self): - self.dbg.GetSelectedTarget().GetProcess().Destroy() - TestBase.tearDown(self) - - @skipIfiOSSimulator - @skipIf(archs=no_match(['amd64', 'arm', 'i386', 'x86_64'])) - @expectedFailureNetBSD - def test_register_commands(self): - """Test commands related to registers, in particular vector registers.""" - self.build() - self.common_setup() - - # verify that logging does not assert - self.log_enable("registers") - - self.expect("register read -a", MISSING_EXPECTED_REGISTERS, - substrs=['registers were unavailable'], matching=False) - - if self.getArchitecture() in ['amd64', 'i386', 'x86_64']: - self.runCmd("register read xmm0") - self.runCmd("register read ymm15") # may be available - self.runCmd("register read bnd0") # may be available - elif self.getArchitecture() in ['arm', 'armv7', 'armv7k', 'arm64']: - self.runCmd("register read s0") - self.runCmd("register read q15") # may be available - - self.expect( - "register read -s 4", - substrs=['invalid register set index: 4'], - error=True) - - @skipIfiOSSimulator - # Writing of mxcsr register fails, presumably due to a kernel/hardware - # problem - @skipIfTargetAndroid(archs=["i386"]) - @skipIf(archs=no_match(['amd64', 'arm', 'i386', 'x86_64'])) - @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr37995") - @expectedFailureNetBSD - def test_fp_register_write(self): - """Test commands that write to registers, in particular floating-point registers.""" - self.build() - self.fp_register_write() - - @skipIfiOSSimulator - # "register read fstat" always return 0xffff - @expectedFailureAndroid(archs=["i386"]) - @skipIfFreeBSD # llvm.org/pr25057 - @skipIf(archs=no_match(['amd64', 'i386', 'x86_64'])) - @skipIfOutOfTreeDebugserver - @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr37995") - @expectedFailureNetBSD - def test_fp_special_purpose_register_read(self): - """Test commands that read fpu special purpose registers.""" - self.build() - self.fp_special_purpose_register_read() - - @skipIfiOSSimulator - @skipIf(archs=no_match(['amd64', 'arm', 'i386', 'x86_64'])) - @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr37683") - def test_register_expressions(self): - """Test expression evaluation with commands related to registers.""" - self.build() - self.common_setup() - - if self.getArchitecture() in ['amd64', 'i386', 'x86_64']: - gpr = "eax" - vector = "xmm0" - elif self.getArchitecture() in ['arm64', 'aarch64']: - gpr = "w0" - vector = "v0" - elif self.getArchitecture() in ['arm', 'armv7', 'armv7k']: - gpr = "r0" - vector = "q0" - - self.expect("expr/x $%s" % gpr, substrs=['unsigned int', ' = 0x']) - self.expect("expr $%s" % vector, substrs=['vector_type']) - self.expect( - "expr (unsigned int)$%s[0]" % - vector, substrs=['unsigned int']) - - if self.getArchitecture() in ['amd64', 'x86_64']: - self.expect( - "expr -- ($rax & 0xffffffff) == $eax", - substrs=['true']) - - @skipIfiOSSimulator - @skipIf(archs=no_match(['amd64', 'x86_64'])) - @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr37683") - def test_convenience_registers(self): - """Test convenience registers.""" - self.build() - self.convenience_registers() - - @skipIfiOSSimulator - @skipIf(archs=no_match(['amd64', 'x86_64'])) - @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr37683") - @expectedFailureNetBSD - def test_convenience_registers_with_process_attach(self): - """Test convenience registers after a 'process attach'.""" - self.build() - self.convenience_registers_with_process_attach(test_16bit_regs=False) - - @skipIfiOSSimulator - @skipIf(archs=no_match(['amd64', 'x86_64'])) - @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr37683") - @expectedFailureNetBSD - def test_convenience_registers_16bit_with_process_attach(self): - """Test convenience registers after a 'process attach'.""" - self.build() - self.convenience_registers_with_process_attach(test_16bit_regs=True) - - def common_setup(self): - exe = self.getBuildArtifact("a.out") - - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # Break in main(). - lldbutil.run_break_set_by_symbol( - self, "main", num_expected_locations=-1) - - 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']) - - # platform specific logging of the specified category - def log_enable(self, category): - # This intentionally checks the host platform rather than the target - # platform as logging is host side. - self.platform = "" - if (sys.platform.startswith("freebsd") or - sys.platform.startswith("linux") or - sys.platform.startswith("netbsd")): - self.platform = "posix" - - if self.platform != "": - self.log_file = self.getBuildArtifact('TestRegisters.log') - self.runCmd( - "log enable " + - self.platform + - " " + - str(category) + - " registers -v -f " + - self.log_file, - RUN_SUCCEEDED) - if not self.has_teardown: - def remove_log(self): - if os.path.exists(self.log_file): - os.remove(self.log_file) - self.has_teardown = True - self.addTearDownHook(remove_log) - - def write_and_read(self, frame, register, new_value, must_exist=True): - value = frame.FindValue(register, lldb.eValueTypeRegister) - if must_exist: - self.assertTrue( - value.IsValid(), - "finding a value for register " + - register) - elif not value.IsValid(): - return # If register doesn't exist, skip this test - - # Also test the 're' alias. - self.runCmd("re write " + register + " \'" + new_value + "\'") - self.expect( - "register read " + - register, - substrs=[ - register + - ' = ', - new_value]) - - def fp_special_purpose_register_read(self): - exe = self.getBuildArtifact("a.out") - - # Create a target by the debugger. - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, VALID_TARGET) - - # Launch the process and stop. - self.expect("run", PROCESS_STOPPED, substrs=['stopped']) - - # Check stop reason; Should be either signal SIGTRAP or EXC_BREAKPOINT - output = self.res.GetOutput() - matched = False - substrs = [ - 'stop reason = EXC_BREAKPOINT', - 'stop reason = signal SIGTRAP'] - for str1 in substrs: - matched = output.find(str1) != -1 - with recording(self, False) as sbuf: - print("%s sub string: %s" % ('Expecting', str1), file=sbuf) - print("Matched" if matched else "Not Matched", file=sbuf) - if matched: - break - self.assertTrue(matched, STOPPED_DUE_TO_SIGNAL) - - process = target.GetProcess() - self.assertTrue(process.GetState() == lldb.eStateStopped, - PROCESS_STOPPED) - - thread = process.GetThreadAtIndex(0) - self.assertTrue(thread.IsValid(), "current thread is valid") - - currentFrame = thread.GetFrameAtIndex(0) - self.assertTrue(currentFrame.IsValid(), "current frame is valid") - - # Extract the value of fstat and ftag flag at the point just before - # we start pushing floating point values on st% register stack - value = currentFrame.FindValue("fstat", lldb.eValueTypeRegister) - error = lldb.SBError() - reg_value_fstat_initial = value.GetValueAsUnsigned(error, 0) - - self.assertTrue(error.Success(), "reading a value for fstat") - value = currentFrame.FindValue("ftag", lldb.eValueTypeRegister) - error = lldb.SBError() - reg_value_ftag_initial = value.GetValueAsUnsigned(error, 0) - - self.assertTrue(error.Success(), "reading a value for ftag") - fstat_top_pointer_initial = (reg_value_fstat_initial & 0x3800) >> 11 - - # Execute 'si' aka 'thread step-inst' instruction 5 times and with - # every execution verify the value of fstat and ftag registers - for x in range(0, 5): - # step into the next instruction to push a value on 'st' register - # stack - self.runCmd("si", RUN_SUCCEEDED) - - # Verify fstat and save it to be used for verification in next - # execution of 'si' command - if not (reg_value_fstat_initial & 0x3800): - self.expect("register read fstat", substrs=[ - 'fstat' + ' = ', str("0x%0.4x" % ((reg_value_fstat_initial & ~(0x3800)) | 0x3800))]) - reg_value_fstat_initial = ( - (reg_value_fstat_initial & ~(0x3800)) | 0x3800) - fstat_top_pointer_initial = 7 - else: - self.expect("register read fstat", substrs=[ - 'fstat' + ' = ', str("0x%0.4x" % (reg_value_fstat_initial - 0x0800))]) - reg_value_fstat_initial = (reg_value_fstat_initial - 0x0800) - fstat_top_pointer_initial -= 1 - - # Verify ftag and save it to be used for verification in next - # execution of 'si' command - self.expect( - "register read ftag", substrs=[ - 'ftag' + ' = ', str( - "0x%0.4x" % - (reg_value_ftag_initial | ( - 1 << fstat_top_pointer_initial)))]) - reg_value_ftag_initial = reg_value_ftag_initial | ( - 1 << fstat_top_pointer_initial) - - def fp_register_write(self): - exe = self.getBuildArtifact("a.out") - - # Create a target by the debugger. - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, VALID_TARGET) - - # Launch the process, stop at the entry point. - error = lldb.SBError() - process = target.Launch( - lldb.SBListener(), - None, None, # argv, envp - None, None, None, # stdin/out/err - self.get_process_working_directory(), - 0, # launch flags - True, # stop at entry - error) - self.assertTrue(error.Success(), "Launch succeeds. Error is :" + str(error)) - - self.assertTrue( - process.GetState() == lldb.eStateStopped, - PROCESS_STOPPED) - - thread = process.GetThreadAtIndex(0) - self.assertTrue(thread.IsValid(), "current thread is valid") - - currentFrame = thread.GetFrameAtIndex(0) - self.assertTrue(currentFrame.IsValid(), "current frame is valid") - - if self.getArchitecture() in ['amd64', 'i386', 'x86_64']: - reg_list = [ - # reg value must-have - ("fcw", "0x0000ff0e", False), - ("fsw", "0x0000ff0e", False), - ("ftw", "0x0000ff0e", False), - ("ip", "0x0000ff0e", False), - ("dp", "0x0000ff0e", False), - ("mxcsr", "0x0000ff0e", False), - ("mxcsrmask", "0x0000ff0e", False), - ] - - st0regname = None - if currentFrame.FindRegister("st0").IsValid(): - st0regname = "st0" - elif currentFrame.FindRegister("stmm0").IsValid(): - st0regname = "stmm0" - if st0regname is not None: - # reg value - # must-have - reg_list.append( - (st0regname, "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x00 0x00}", True)) - reg_list.append( - ("xmm0", - "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x2f 0x2f}", - True)) - reg_list.append( - ("xmm15", - "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x0e 0x0f}", - False)) - elif self.getArchitecture() in ['arm64', 'aarch64']: - reg_list = [ - # reg value - # must-have - ("fpsr", "0xfbf79f9f", True), - ("s0", "1.25", True), - ("s31", "0.75", True), - ("d1", "123", True), - ("d17", "987", False), - ("v1", "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x2f 0x2f}", True), - ("v14", - "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x0e 0x0f}", - False), - ] - elif self.getArchitecture() in ['armv7'] and self.platformIsDarwin(): - reg_list = [ - # reg value - # must-have - ("fpsr", "0xfbf79f9f", True), - ("s0", "1.25", True), - ("s31", "0.75", True), - ("d1", "123", True), - ("d17", "987", False), - ("q1", "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x2f 0x2f}", True), - ("q14", - "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x0e 0x0f}", - False), - ] - elif self.getArchitecture() in ['arm', 'armv7k']: - reg_list = [ - # reg value - # must-have - ("fpscr", "0xfbf79f9f", True), - ("s0", "1.25", True), - ("s31", "0.75", True), - ("d1", "123", True), - ("d17", "987", False), - ("q1", "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x2f 0x2f}", True), - ("q14", - "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x0e 0x0f}", - False), - ] - - for (reg, val, must) in reg_list: - self.write_and_read(currentFrame, reg, val, must) - - if self.getArchitecture() in ['amd64', 'i386', 'x86_64']: - if st0regname is None: - self.fail("st0regname could not be determined") - self.runCmd( - "register write " + - st0regname + - " \"{0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00}\"") - self.expect( - "register read " + - st0regname + - " --format f", - substrs=[ - st0regname + - ' = 0']) - - has_avx = False - has_mpx = False - # Returns an SBValueList. - registerSets = currentFrame.GetRegisters() - for registerSet in registerSets: - if 'advanced vector extensions' in registerSet.GetName().lower(): - has_avx = True - if 'memory protection extension' in registerSet.GetName().lower(): - has_mpx = True - - if has_avx: - new_value = "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x0e 0x0f 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x0c 0x0d 0x0e 0x0f}" - self.write_and_read(currentFrame, "ymm0", new_value) - self.write_and_read(currentFrame, "ymm7", new_value) - self.expect("expr $ymm0", substrs=['vector_type']) - else: - self.runCmd("register read ymm0") - - if has_mpx: - # Test write and read for bnd0. - new_value_w = "{0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f 0x10}" - self.runCmd("register write bnd0 \'" + new_value_w + "\'") - new_value_r = "{0x0807060504030201 0x100f0e0d0c0b0a09}" - self.expect("register read bnd0", substrs = ['bnd0 = ', new_value_r]) - self.expect("expr $bnd0", substrs = ['vector_type']) - - # Test write and for bndstatus. - new_value = "{0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08}" - self.write_and_read(currentFrame, "bndstatus", new_value) - self.expect("expr $bndstatus", substrs = ['vector_type']) - else: - self.runCmd("register read bnd0") - - def convenience_registers(self): - """Test convenience registers.""" - self.common_setup() - - # The command "register read -a" does output a derived register like - # eax... - self.expect("register read -a", matching=True, - substrs=['eax']) - - # ...however, the vanilla "register read" command should not output derived registers like eax. - self.expect("register read", matching=False, - substrs=['eax']) - - # Test reading of rax and eax. - self.expect("register read rax eax", - substrs=['rax = 0x', 'eax = 0x']) - - # Now write rax with a unique bit pattern and test that eax indeed - # represents the lower half of rax. - self.runCmd("register write rax 0x1234567887654321") - self.expect("register read rax 0x1234567887654321", - substrs=['0x1234567887654321']) - - def convenience_registers_with_process_attach(self, test_16bit_regs): - """Test convenience registers after a 'process attach'.""" - exe = self.getBuildArtifact("a.out") - - # Spawn a new process - pid = self.spawnSubprocess(exe, ['wait_for_attach']).pid - self.addTearDownHook(self.cleanupSubprocesses) - - if self.TraceOn(): - print("pid of spawned process: %d" % pid) - - self.runCmd("process attach -p %d" % pid) - - # Check that "register read eax" works. - self.runCmd("register read eax") - - if self.getArchitecture() in ['amd64', 'x86_64']: - self.expect("expr -- ($rax & 0xffffffff) == $eax", - substrs=['true']) - - if test_16bit_regs: - self.expect("expr -- $ax == (($ah << 8) | $al)", - substrs=['true']) - - @skipIfiOSSimulator - @skipIf(archs=no_match(['amd64', 'arm', 'i386', 'x86_64'])) - @expectedFailureNetBSD - def test_invalid_invocation(self): - self.build() - self.common_setup() - - self.expect("register read -a arg", error=True, - substrs=["the --all option can't be used when registers names are supplied as arguments"]) - - self.expect("register read --set 0 r", error=True, - substrs=["the --set option can't be used when registers names are supplied as arguments"]) - - self.expect("register write a", error=True, - substrs=["register write takes exactly 2 arguments: "]) - self.expect("register write a b c", error=True, - substrs=["register write takes exactly 2 arguments: "]) - - @skipIfiOSSimulator - @skipIf(archs=no_match(['amd64', 'arm', 'i386', 'x86_64'])) - @expectedFailureNetBSD - def test_write_unknown_register(self): - self.build() - self.common_setup() - - self.expect("register write blub 1", error=True, - substrs=["error: Register not found for 'blub'."]) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/register_command/a.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/register_command/a.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/register_command/a.cpp @@ -1,43 +0,0 @@ -//===-- a.cpp ------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -#include - -long double -return_long_double (long double value) -{ -#if defined (__i386__) || defined (__x86_64__) - float a=2, b=4,c=8, d=16, e=32, f=64, k=128, l=256, add=0; - __asm__ ( - "int3 ;" - "flds %1 ;" - "flds %2 ;" - "flds %3 ;" - "flds %4 ;" - "flds %5 ;" - "flds %6 ;" - "flds %7 ;" - "faddp ;" : "=g" (add) : "g" (a), "g" (b), "g" (c), "g" (d), "g" (e), "g" (f), "g" (k), "g" (l) ); // Set break point at this line. -#endif // #if defined (__i386__) || defined (__x86_64__) - return value; -} - -long double -outer_return_long_double (long double value) -{ - long double val = return_long_double(value); - val *= 2 ; - return val; -} - -long double -outermost_return_long_double (long double value) -{ - long double val = outer_return_long_double(value); - val *= 2 ; - return val; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/register_command/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/register_command/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/register/register_command/main.cpp @@ -1,35 +0,0 @@ -//===-- main.cpp ------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -#include - -#include -#include - -long double outermost_return_long_double (long double my_long_double); - -int main (int argc, char const *argv[]) -{ - lldb_enable_attach(); - - char my_string[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 0}; - double my_double = 1234.5678; - long double my_long_double = 1234.5678; - - // For simplicity assume that any cmdline argument means wait for attach. - if (argc > 1) - { - volatile int wait_for_attach=1; - while (wait_for_attach) - std::this_thread::sleep_for(std::chrono::microseconds(1)); - } - - printf("my_string=%s\n", my_string); - printf("my_double=%g\n", my_double); - outermost_return_long_double (my_long_double); - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/reproducer/TestReproducer.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/reproducer/TestReproducer.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/reproducer/TestReproducer.py @@ -1,20 +0,0 @@ -import lldb -from lldbsuite.test.lldbtest import * -from lldbsuite.test.decorators import * - -class ReproducerTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - TestBase.setUp(self) - - @no_debug_info_test - def test_reproducer_generate_invalid_invocation(self): - self.expect("reproducer generate f", error=True, - substrs=["'reproducer generate' takes no arguments"]) - - @no_debug_info_test - def test_reproducer_status_invalid_invocation(self): - self.expect("reproducer status f", error=True, - substrs=["'reproducer status' takes no arguments"]) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/stats/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/stats/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/stats/Makefile @@ -1,3 +0,0 @@ -LEVEL = ../../make -C_SOURCES := main.c -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/stats/TestStats.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/stats/TestStats.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/stats/TestStats.py @@ -1,5 +0,0 @@ -from lldbsuite.test import lldbinline -from lldbsuite.test import decorators - -lldbinline.MakeInlineTest( - __file__, globals(), []) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/stats/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/stats/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/stats/main.c @@ -1,18 +0,0 @@ -// Test that the lldb command `statistics` works. - -int main(void) { - int patatino = 27; - //%self.expect("statistics disable", substrs=['need to enable statistics before disabling'], error=True) - //%self.expect("statistics enable") - //%self.expect("statistics enable", substrs=['already enabled'], error=True) - //%self.expect("expr patatino", substrs=['27']) - //%self.expect("statistics disable") - //%self.expect("statistics dump", substrs=['expr evaluation successes : 1', 'expr evaluation failures : 0']) - //%self.expect("frame var", substrs=['27']) - //%self.expect("statistics enable") - //%self.expect("frame var", substrs=['27']) - //%self.expect("statistics disable") - //%self.expect("statistics dump", substrs=['frame var successes : 1', 'frame var failures : 0']) - - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/stop-hooks/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/stop-hooks/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/stop-hooks/Makefile @@ -1,6 +0,0 @@ -LEVEL = ../../make - -C_SOURCES := main.c -CFLAGS_EXTRAS += -std=c99 - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/stop-hooks/TestStopHooks.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/stop-hooks/TestStopHooks.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/stop-hooks/TestStopHooks.py @@ -1,45 +0,0 @@ -""" -Test that stop hooks trigger on "step-out" -""" - -from __future__ import print_function - - -import lldb -import lldbsuite.test.lldbutil as lldbutil -from lldbsuite.test.lldbtest import * - - -class TestStopHooks(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # If your test case doesn't stress debug info, the - # set this to true. That way it won't be run once for - # each debug info format. - NO_DEBUG_INFO_TESTCASE = True - - def test_stop_hooks_step_out(self): - """Test that stop hooks fire on step-out.""" - self.build() - self.main_source_file = lldb.SBFileSpec("main.c") - self.step_out_test() - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - - def step_out_test(self): - (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, - "Set a breakpoint here", self.main_source_file) - - interp = self.dbg.GetCommandInterpreter() - result = lldb.SBCommandReturnObject() - interp.HandleCommand("target stop-hook add -o 'expr g_var++'", result) - self.assertTrue(result.Succeeded, "Set the target stop hook") - thread.StepOut() - var = target.FindFirstGlobalVariable("g_var") - self.assertTrue(var.IsValid()) - self.assertEqual(var.GetValueAsUnsigned(), 1, "Updated g_var") - - Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/stop-hooks/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/stop-hooks/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/stop-hooks/main.c @@ -1,14 +0,0 @@ -#include - -static int g_var = 0; - -int step_out_of_me() -{ - return g_var; // Set a breakpoint here and step out. -} - -int -main() -{ - return step_out_of_me(); -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_command/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_command/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_command/Makefile @@ -1,8 +0,0 @@ -LEVEL = ../../make - -# Example: -# -# C_SOURCES := b.c -# EXE := b.out - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_command/TestTargetCommand.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_command/TestTargetCommand.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_command/TestTargetCommand.py @@ -1,440 +0,0 @@ -""" -Test some target commands: create, list, select, variable. -""" - -from __future__ import print_function -import os -import stat -import tempfile - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class targetCommandTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line numbers for our breakpoints. - self.line_b = line_number('b.c', '// Set break point at this line.') - self.line_c = line_number('c.c', '// Set break point at this line.') - - def buildB(self): - db = {'C_SOURCES': 'b.c', 'EXE': self.getBuildArtifact('b.out')} - self.build(dictionary=db) - self.addTearDownCleanup(dictionary=db) - - def buildAll(self): - da = {'C_SOURCES': 'a.c', 'EXE': self.getBuildArtifact('a.out')} - self.build(dictionary=da) - self.addTearDownCleanup(dictionary=da) - - self.buildB() - - dc = {'C_SOURCES': 'c.c', 'EXE': self.getBuildArtifact('c.out')} - self.build(dictionary=dc) - self.addTearDownCleanup(dictionary=dc) - - def test_target_command(self): - """Test some target commands: create, list, select.""" - self.buildAll() - self.do_target_command() - - def test_target_variable_command(self): - """Test 'target variable' command before and after starting the inferior.""" - d = {'C_SOURCES': 'globals.c', 'EXE': self.getBuildArtifact('globals')} - self.build(dictionary=d) - self.addTearDownCleanup(dictionary=d) - - self.do_target_variable_command('globals') - - def test_target_variable_command_no_fail(self): - """Test 'target variable' command before and after starting the inferior.""" - d = {'C_SOURCES': 'globals.c', 'EXE': self.getBuildArtifact('globals')} - self.build(dictionary=d) - self.addTearDownCleanup(dictionary=d) - - self.do_target_variable_command_no_fail('globals') - - def do_target_command(self): - """Exercise 'target create', 'target list', 'target select' commands.""" - exe_a = self.getBuildArtifact("a.out") - exe_b = self.getBuildArtifact("b.out") - exe_c = self.getBuildArtifact("c.out") - - self.runCmd("target list") - output = self.res.GetOutput() - if output.startswith("No targets"): - # We start from index 0. - base = 0 - else: - # Find the largest index of the existing list. - import re - pattern = re.compile("target #(\d+):") - for line in reversed(output.split(os.linesep)): - match = pattern.search(line) - if match: - # We will start from (index + 1) .... - base = int(match.group(1), 10) + 1 - #print("base is:", base) - break - - self.runCmd("target create " + exe_a, CURRENT_EXECUTABLE_SET) - self.runCmd("run", RUN_SUCCEEDED) - - self.runCmd("target create " + exe_b, CURRENT_EXECUTABLE_SET) - lldbutil.run_break_set_by_file_and_line( - self, 'b.c', self.line_b, num_expected_locations=1, loc_exact=True) - self.runCmd("run", RUN_SUCCEEDED) - - self.runCmd("target create " + exe_c, CURRENT_EXECUTABLE_SET) - lldbutil.run_break_set_by_file_and_line( - self, 'c.c', self.line_c, num_expected_locations=1, loc_exact=True) - self.runCmd("run", RUN_SUCCEEDED) - - self.runCmd("target list") - - self.runCmd("target select %d" % base) - self.runCmd("thread backtrace") - - self.runCmd("target select %d" % (base + 2)) - self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, - substrs=['c.c:%d' % self.line_c, - 'stop reason = breakpoint']) - - self.runCmd("target select %d" % (base + 1)) - self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, - substrs=['b.c:%d' % self.line_b, - 'stop reason = breakpoint']) - - self.runCmd("target list") - - def do_target_variable_command(self, exe_name): - """Exercise 'target variable' command before and after starting the inferior.""" - self.runCmd("file " + self.getBuildArtifact(exe_name), - CURRENT_EXECUTABLE_SET) - - self.expect( - "target variable my_global_char", - VARIABLES_DISPLAYED_CORRECTLY, - substrs=[ - "my_global_char", - "'X'"]) - self.expect( - "target variable my_global_str", - VARIABLES_DISPLAYED_CORRECTLY, - substrs=[ - 'my_global_str', - '"abc"']) - self.expect( - "target variable my_static_int", - VARIABLES_DISPLAYED_CORRECTLY, - substrs=[ - 'my_static_int', - '228']) - self.expect("target variable my_global_str_ptr", matching=False, - substrs=['"abc"']) - self.expect("target variable *my_global_str_ptr", matching=True, - substrs=['"abc"']) - self.expect( - "target variable *my_global_str", - VARIABLES_DISPLAYED_CORRECTLY, - substrs=['a']) - - self.runCmd("b main") - self.runCmd("run") - - self.expect( - "target variable my_global_str", - VARIABLES_DISPLAYED_CORRECTLY, - substrs=[ - 'my_global_str', - '"abc"']) - self.expect( - "target variable my_static_int", - VARIABLES_DISPLAYED_CORRECTLY, - substrs=[ - 'my_static_int', - '228']) - self.expect("target variable my_global_str_ptr", matching=False, - substrs=['"abc"']) - self.expect("target variable *my_global_str_ptr", matching=True, - substrs=['"abc"']) - self.expect( - "target variable *my_global_str", - VARIABLES_DISPLAYED_CORRECTLY, - substrs=['a']) - self.expect( - "target variable my_global_char", - VARIABLES_DISPLAYED_CORRECTLY, - substrs=[ - "my_global_char", - "'X'"]) - - self.runCmd("c") - - # rdar://problem/9763907 - # 'target variable' command fails if the target program has been run - self.expect( - "target variable my_global_str", - VARIABLES_DISPLAYED_CORRECTLY, - substrs=[ - 'my_global_str', - '"abc"']) - self.expect( - "target variable my_static_int", - VARIABLES_DISPLAYED_CORRECTLY, - substrs=[ - 'my_static_int', - '228']) - self.expect("target variable my_global_str_ptr", matching=False, - substrs=['"abc"']) - self.expect("target variable *my_global_str_ptr", matching=True, - substrs=['"abc"']) - self.expect( - "target variable *my_global_str", - VARIABLES_DISPLAYED_CORRECTLY, - substrs=['a']) - self.expect( - "target variable my_global_char", - VARIABLES_DISPLAYED_CORRECTLY, - substrs=[ - "my_global_char", - "'X'"]) - - def do_target_variable_command_no_fail(self, exe_name): - """Exercise 'target variable' command before and after starting the inferior.""" - self.runCmd("file " + self.getBuildArtifact(exe_name), - CURRENT_EXECUTABLE_SET) - - self.expect( - "target variable my_global_char", - VARIABLES_DISPLAYED_CORRECTLY, - substrs=[ - "my_global_char", - "'X'"]) - self.expect( - "target variable my_global_str", - VARIABLES_DISPLAYED_CORRECTLY, - substrs=[ - 'my_global_str', - '"abc"']) - self.expect( - "target variable my_static_int", - VARIABLES_DISPLAYED_CORRECTLY, - substrs=[ - 'my_static_int', - '228']) - self.expect("target variable my_global_str_ptr", matching=False, - substrs=['"abc"']) - self.expect("target variable *my_global_str_ptr", matching=True, - substrs=['"abc"']) - self.expect( - "target variable *my_global_str", - VARIABLES_DISPLAYED_CORRECTLY, - substrs=['a']) - - self.runCmd("b main") - self.runCmd("run") - - # New feature: you don't need to specify the variable(s) to 'target vaiable'. - # It will find all the global and static variables in the current - # compile unit. - self.expect("target variable", - substrs=['my_global_char', - 'my_global_str', - 'my_global_str_ptr', - 'my_static_int']) - - self.expect( - "target variable my_global_str", - VARIABLES_DISPLAYED_CORRECTLY, - substrs=[ - 'my_global_str', - '"abc"']) - self.expect( - "target variable my_static_int", - VARIABLES_DISPLAYED_CORRECTLY, - substrs=[ - 'my_static_int', - '228']) - self.expect("target variable my_global_str_ptr", matching=False, - substrs=['"abc"']) - self.expect("target variable *my_global_str_ptr", matching=True, - substrs=['"abc"']) - self.expect( - "target variable *my_global_str", - VARIABLES_DISPLAYED_CORRECTLY, - substrs=['a']) - self.expect( - "target variable my_global_char", - VARIABLES_DISPLAYED_CORRECTLY, - substrs=[ - "my_global_char", - "'X'"]) - - @no_debug_info_test - def test_target_stop_hook_disable_enable(self): - self.buildB() - self.runCmd("file " + self.getBuildArtifact("b.out"), CURRENT_EXECUTABLE_SET) - - self.expect("target stop-hook disable 1", error=True, substrs=['unknown stop hook id: "1"']) - self.expect("target stop-hook disable blub", error=True, substrs=['invalid stop hook id: "blub"']) - self.expect("target stop-hook enable 1", error=True, substrs=['unknown stop hook id: "1"']) - self.expect("target stop-hook enable blub", error=True, substrs=['invalid stop hook id: "blub"']) - - @no_debug_info_test - def test_target_stop_hook_delete(self): - self.buildB() - self.runCmd("file " + self.getBuildArtifact("b.out"), CURRENT_EXECUTABLE_SET) - - self.expect("target stop-hook delete 1", error=True, substrs=['unknown stop hook id: "1"']) - self.expect("target stop-hook delete blub", error=True, substrs=['invalid stop hook id: "blub"']) - - @no_debug_info_test - def test_target_list_args(self): - self.expect("target list blub", error=True, - substrs=["the 'target list' command takes no arguments"]) - - @no_debug_info_test - def test_target_select_no_index(self): - self.expect("target select", error=True, - substrs=["'target select' takes a single argument: a target index"]) - - @no_debug_info_test - def test_target_select_invalid_index(self): - self.runCmd("target delete --all") - self.expect("target select 0", error=True, - substrs=["index 0 is out of range since there are no active targets"]) - self.buildB() - self.runCmd("file " + self.getBuildArtifact("b.out"), CURRENT_EXECUTABLE_SET) - self.expect("target select 1", error=True, - substrs=["index 1 is out of range, valid target indexes are 0 - 0"]) - - - @no_debug_info_test - def test_target_create_multiple_args(self): - self.expect("target create a b", error=True, - substrs=["'target create' takes exactly one executable path"]) - - @no_debug_info_test - def test_target_create_nonexistent_core_file(self): - self.expect("target create -c doesntexist", error=True, - substrs=["core file 'doesntexist' doesn't exist"]) - - # Write only files don't seem to be supported on Windows. - @skipIfWindows - @no_debug_info_test - def test_target_create_unreadable_core_file(self): - tf = tempfile.NamedTemporaryFile() - os.chmod(tf.name, stat.S_IWRITE) - self.expect("target create -c '" + tf.name + "'", error=True, - substrs=["core file '", "' is not readable"]) - - @no_debug_info_test - def test_target_create_nonexistent_sym_file(self): - self.expect("target create -s doesntexist doesntexisteither", error=True, - substrs=["invalid symbol file path 'doesntexist'"]) - - @skipIfWindows - @no_debug_info_test - def test_target_create_invalid_core_file(self): - invalid_core_path = os.path.join(self.getSourceDir(), "invalid_core_file") - self.expect("target create -c '" + invalid_core_path + "'", error=True, - substrs=["Unable to find process plug-in for core file '"]) - - - # Write only files don't seem to be supported on Windows. - @skipIfWindows - @no_debug_info_test - def test_target_create_unreadable_sym_file(self): - tf = tempfile.NamedTemporaryFile() - os.chmod(tf.name, stat.S_IWRITE) - self.expect("target create -s '" + tf.name + "' no_exe", error=True, - substrs=["symbol file '", "' is not readable"]) - - @no_debug_info_test - def test_target_delete_all(self): - self.buildAll() - self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) - self.runCmd("file " + self.getBuildArtifact("b.out"), CURRENT_EXECUTABLE_SET) - self.expect("target delete --all") - self.expect("target list", substrs=["No targets."]) - - @no_debug_info_test - def test_target_delete_by_index(self): - self.buildAll() - self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) - self.runCmd("file " + self.getBuildArtifact("b.out"), CURRENT_EXECUTABLE_SET) - self.runCmd("file " + self.getBuildArtifact("c.out"), CURRENT_EXECUTABLE_SET) - self.expect("target delete 3", error=True, - substrs=["target index 3 is out of range, valid target indexes are 0 - 2"]) - - self.runCmd("target delete 1") - self.expect("target list", matching=False, substrs=["b.out"]) - self.runCmd("target delete 1") - self.expect("target list", matching=False, substrs=["c.out"]) - - self.expect("target delete 1", error=True, - substrs=["target index 1 is out of range, the only valid index is 0"]) - - self.runCmd("target delete 0") - self.expect("target list", matching=False, substrs=["a.out"]) - - self.expect("target delete 0", error=True, substrs=["no targets to delete"]) - self.expect("target delete 1", error=True, substrs=["no targets to delete"]) - - @no_debug_info_test - def test_target_delete_by_index_multiple(self): - self.buildAll() - self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) - self.runCmd("file " + self.getBuildArtifact("b.out"), CURRENT_EXECUTABLE_SET) - self.runCmd("file " + self.getBuildArtifact("c.out"), CURRENT_EXECUTABLE_SET) - - self.expect("target delete 0 1 2 3", error=True, - substrs=["target index 3 is out of range, valid target indexes are 0 - 2"]) - self.expect("target list", substrs=["a.out", "b.out", "c.out"]) - - self.runCmd("target delete 0 1 2") - self.expect("target list", matching=False, substrs=["a.out", "c.out"]) - - @no_debug_info_test - def test_target_delete_selected(self): - self.buildAll() - self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) - self.runCmd("file " + self.getBuildArtifact("b.out"), CURRENT_EXECUTABLE_SET) - self.runCmd("file " + self.getBuildArtifact("c.out"), CURRENT_EXECUTABLE_SET) - self.runCmd("target select 1") - self.runCmd("target delete") - self.expect("target list", matching=False, substrs=["b.out"]) - self.runCmd("target delete") - self.runCmd("target delete") - self.expect("target list", substrs=["No targets."]) - self.expect("target delete", error=True, substrs=["no target is currently selected"]) - - @no_debug_info_test - def test_target_modules_search_paths_clear(self): - self.buildB() - self.runCmd("file " + self.getBuildArtifact("b.out"), CURRENT_EXECUTABLE_SET) - self.runCmd("target modules search-paths add foo bar") - self.runCmd("target modules search-paths add foz baz") - self.runCmd("target modules search-paths clear") - self.expect("target list", matching=False, substrs=["bar", "baz"]) - - @no_debug_info_test - def test_target_modules_search_paths_query(self): - self.buildB() - self.runCmd("file " + self.getBuildArtifact("b.out"), CURRENT_EXECUTABLE_SET) - self.runCmd("target modules search-paths add foo bar") - self.expect("target modules search-paths query foo", substrs=["bar"]) - # Query something that doesn't exist. - self.expect("target modules search-paths query faz", substrs=["faz"]) - - # Invalid arguments. - self.expect("target modules search-paths query faz baz", error=True, - substrs=["query requires one argument"]) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_command/a.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_command/a.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_command/a.c @@ -1,15 +0,0 @@ -//===-- main.c --------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -#include - -int main(int argc, const char* argv[]) -{ - int *null_ptr = 0; - printf("Hello, segfault!\n"); - printf("Now crash %d\n", *null_ptr); // Crash here. -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_command/b.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_command/b.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_command/b.c @@ -1,12 +0,0 @@ -//===-- main.c --------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -int main (int argc, char const *argv[]) -{ - return 0; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_command/c.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_command/c.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_command/c.c @@ -1,28 +0,0 @@ -//===-- main.c --------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -#include - -int main (int argc, char const *argv[]) -{ - enum days { - Monday = 10, - Tuesday, - Wednesday, - Thursday, - Friday, - Saturday, - Sunday, - kNumDays - }; - enum days day; - for (day = Monday - 1; day <= kNumDays + 1; day++) - { - printf("day as int is %i\n", (int)day); - } - return 0; // Set break point at this line. -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_command/globals.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_command/globals.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_command/globals.c @@ -1,24 +0,0 @@ -//===-- main.c --------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -#include - -char my_global_char = 'X'; -const char* my_global_str = "abc"; -const char **my_global_str_ptr = &my_global_str; -static int my_static_int = 228; - -int main (int argc, char const *argv[]) -{ - printf("global char: %c\n", my_global_char); - - printf("global str: %s\n", my_global_str); - - printf("argc + my_static_int = %d\n", (argc + my_static_int)); - - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_command/invalid_core_file =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_command/invalid_core_file +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_command/invalid_core_file @@ -1 +0,0 @@ -stub Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_create_deps/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_create_deps/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_create_deps/Makefile @@ -1,16 +0,0 @@ -LEVEL := ../../make - -LIB_PREFIX := load_ - -LD_EXTRAS := -L. -l$(LIB_PREFIX)a -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules - -a.out: lib_a - -lib_%: - $(MAKE) VPATH=$(SRCDIR) -I $(SRCDIR) -f $(SRCDIR)/$*.mk - -clean:: - $(MAKE) -f $(SRCDIR)/a.mk clean Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_create_deps/TestTargetCreateDeps.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_create_deps/TestTargetCreateDeps.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_create_deps/TestTargetCreateDeps.py @@ -1,114 +0,0 @@ -""" -Test that loading of dependents works correctly for all the potential -combinations. -""" - -from __future__ import print_function - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -@skipIfWindows # Windows deals differently with shared libs. -class TargetDependentsTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - NO_DEBUG_INFO_TESTCASE = True - - def setUp(self): - TestBase.setUp(self) - self.build() - - def has_exactly_one_image(self, matching, msg=""): - self.expect( - "image list", - "image list should contain at least one image", - substrs=['[ 0]']) - should_match = not matching - self.expect( - "image list", msg, matching=should_match, substrs=['[ 1]']) - - - @expectedFailureAll(oslist=["linux"], - triple=no_match(".*-android")) - #linux does not support loading dependent files, but android does - @expectedFailureNetBSD - def test_dependents_implicit_default_exe(self): - """Test default behavior""" - exe = self.getBuildArtifact("a.out") - self.runCmd("target create " + exe, CURRENT_EXECUTABLE_SET) - self.has_exactly_one_image(False) - - @expectedFailureAll(oslist=["linux"], - triple=no_match(".*-android")) - #linux does not support loading dependent files, but android does - @expectedFailureNetBSD - def test_dependents_explicit_default_exe(self): - """Test default behavior""" - exe = self.getBuildArtifact("a.out") - self.runCmd("target create -ddefault " + exe, CURRENT_EXECUTABLE_SET) - self.has_exactly_one_image(False) - - def test_dependents_explicit_true_exe(self): - """Test default behavior""" - exe = self.getBuildArtifact("a.out") - self.runCmd("target create -dtrue " + exe, CURRENT_EXECUTABLE_SET) - self.has_exactly_one_image(True) - - @expectedFailureAll(oslist=["linux"], - triple=no_match(".*-android")) - #linux does not support loading dependent files, but android does - @expectedFailureNetBSD - def test_dependents_explicit_false_exe(self): - """Test default behavior""" - exe = self.getBuildArtifact("a.out") - self.runCmd("target create -dfalse " + exe, CURRENT_EXECUTABLE_SET) - self.has_exactly_one_image(False) - - def test_dependents_implicit_false_exe(self): - """Test default behavior""" - exe = self.getBuildArtifact("a.out") - self.runCmd("target create -d " + exe, CURRENT_EXECUTABLE_SET) - self.has_exactly_one_image(True) - - @expectedFailureAndroid # android will return mutiple images - def test_dependents_implicit_default_lib(self): - ctx = self.platformContext - dylibName = ctx.shlib_prefix + 'load_a.' + ctx.shlib_extension - lib = self.getBuildArtifact(dylibName) - self.runCmd("target create " + lib, CURRENT_EXECUTABLE_SET) - self.has_exactly_one_image(True) - - def test_dependents_explicit_default_lib(self): - ctx = self.platformContext - dylibName = ctx.shlib_prefix + 'load_a.' + ctx.shlib_extension - lib = self.getBuildArtifact(dylibName) - self.runCmd("target create -ddefault " + lib, CURRENT_EXECUTABLE_SET) - self.has_exactly_one_image(True) - - def test_dependents_explicit_true_lib(self): - ctx = self.platformContext - dylibName = ctx.shlib_prefix + 'load_a.' + ctx.shlib_extension - lib = self.getBuildArtifact(dylibName) - self.runCmd("target create -dtrue " + lib, CURRENT_EXECUTABLE_SET) - self.has_exactly_one_image(True) - - @expectedFailureAll(oslist=["linux"], - triple=no_match(".*-android")) - #linux does not support loading dependent files, but android does - @expectedFailureNetBSD - def test_dependents_explicit_false_lib(self): - ctx = self.platformContext - dylibName = ctx.shlib_prefix + 'load_a.' + ctx.shlib_extension - lib = self.getBuildArtifact(dylibName) - self.runCmd("target create -dfalse " + lib, CURRENT_EXECUTABLE_SET) - self.has_exactly_one_image(False) - - def test_dependents_implicit_false_lib(self): - ctx = self.platformContext - dylibName = ctx.shlib_prefix + 'load_a.' + ctx.shlib_extension - lib = self.getBuildArtifact(dylibName) - self.runCmd("target create -d " + lib, CURRENT_EXECUTABLE_SET) - self.has_exactly_one_image(True) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_create_deps/a.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_create_deps/a.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_create_deps/a.cpp @@ -1,12 +0,0 @@ -//===-- b.c -----------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -int a_function () -{ - return 500; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_create_deps/a.mk =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_create_deps/a.mk +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_create_deps/a.mk @@ -1,9 +0,0 @@ -LEVEL := ../../make - -LIB_PREFIX := load_ - -DYLIB_NAME := $(LIB_PREFIX)a -DYLIB_CXX_SOURCES := a.cpp -DYLIB_ONLY := YES - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_create_deps/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_create_deps/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/target_create_deps/main.cpp @@ -1,16 +0,0 @@ -//===-- main.c --------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -extern int a_function (); -extern int b_function (); - -int -main (int argc, char const *argv[]) -{ - return a_function(); -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/version/TestVersion.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/version/TestVersion.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/version/TestVersion.py @@ -1,22 +0,0 @@ -import lldb -from lldbsuite.test.lldbtest import * -from lldbsuite.test.decorators import * - -class VersionTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - TestBase.setUp(self) - - @no_debug_info_test - def test_version(self): - # Should work even when people patch the output, - # so let's just assume that every vendor at least mentions - # 'lldb' in their version string. - self.expect("version", substrs=['lldb']) - - @no_debug_info_test - def test_version_invalid_invocation(self): - self.expect("version a", error=True, - substrs=['the version command takes no arguments.']) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/.categories =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/.categories +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/.categories @@ -1 +0,0 @@ -watchpoint Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/hello_watchlocation/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/hello_watchlocation/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/hello_watchlocation/Makefile @@ -1,6 +0,0 @@ -LEVEL = ../../../make - -ENABLE_THREADS := YES -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/hello_watchlocation/TestWatchLocation.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/hello_watchlocation/TestWatchLocation.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/hello_watchlocation/TestWatchLocation.py @@ -1,113 +0,0 @@ -""" -Test lldb watchpoint that uses '-s size' to watch a pointed location with size. -""" - -from __future__ import print_function - - -import re -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class HelloWatchLocationTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Our simple source filename. - self.source = 'main.cpp' - # Find the line number to break inside main(). - self.line = line_number( - self.source, '// Set break point at this line.') - # This is for verifying that watch location works. - self.violating_func = "do_bad_thing_with_location" - # Build dictionary to have unique executable names for each test - # method. - self.exe_name = self.testMethodName - self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name} - - @expectedFailureAll( - oslist=["windows"], - bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") - # Most of the MIPS boards provide only one H/W watchpoints, and S/W - # watchpoints are not supported yet - @expectedFailureAll(triple=re.compile('^mips')) - # SystemZ and PowerPC also currently supports only one H/W watchpoint - @expectedFailureAll(archs=['powerpc64le', 's390x']) - @expectedFailureNetBSD - @skipIfDarwin - def test_hello_watchlocation(self): - """Test watching a location with '-s size' option.""" - self.build(dictionary=self.d) - self.setTearDownCleanup(dictionary=self.d) - exe = self.getBuildArtifact(self.exe_name) - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # Add a breakpoint to set a watchpoint when stopped on the breakpoint. - lldbutil.run_break_set_by_file_and_line( - self, None, self.line, num_expected_locations=1, loc_exact=False) - - # Run the program. - self.runCmd("run", RUN_SUCCEEDED) - - # We should be stopped again due to the breakpoint. - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', - 'stop reason = breakpoint']) - - # Now let's set a write-type watchpoint pointed to by 'g_char_ptr'. - self.expect( - "watchpoint set expression -w write -s 1 -- g_char_ptr", - WATCHPOINT_CREATED, - substrs=[ - 'Watchpoint created', - 'size = 1', - 'type = w']) - # Get a hold of the watchpoint id just created, it is used later on to - # match the watchpoint id which is expected to be fired. - match = re.match( - "Watchpoint created: Watchpoint (.*):", - self.res.GetOutput().splitlines()[0]) - if match: - expected_wp_id = int(match.group(1), 0) - else: - self.fail("Grokking watchpoint id faailed!") - - self.runCmd("expr unsigned val = *g_char_ptr; val") - self.expect(self.res.GetOutput().splitlines()[0], exe=False, - endstr=' = 0') - - self.runCmd("watchpoint set expression -w write -s 4 -- &threads[0]") - - # Use the '-v' option to do verbose listing of the watchpoint. - # The hit count should be 0 initially. - self.expect("watchpoint list -v", - substrs=['hit_count = 0']) - - self.runCmd("process continue") - - # We should be stopped again due to the watchpoint (write type), but - # only once. The stop reason of the thread should be watchpoint. - self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT, - substrs=['stopped', - 'stop reason = watchpoint %d' % expected_wp_id]) - - # Switch to the thread stopped due to watchpoint and issue some - # commands. - self.switch_to_thread_with_stop_reason(lldb.eStopReasonWatchpoint) - self.runCmd("thread backtrace") - self.expect("frame info", - substrs=[self.violating_func]) - - # Use the '-v' option to do verbose listing of the watchpoint. - # The hit count should now be 1. - self.expect("watchpoint list -v", - substrs=['hit_count = 1']) - - self.runCmd("thread backtrace all") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/hello_watchlocation/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/hello_watchlocation/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/hello_watchlocation/main.cpp @@ -1,103 +0,0 @@ -//===-- main.cpp ------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include -#include -#include -#include -#include - -std::default_random_engine g_random_engine{std::random_device{}()}; -std::uniform_int_distribution<> g_distribution{0, 3000000}; -std::condition_variable g_condition_variable; -std::mutex g_mutex; -int g_count; - -char *g_char_ptr = nullptr; - -void -barrier_wait() -{ - std::unique_lock lock{g_mutex}; - if (--g_count > 0) - g_condition_variable.wait(lock); - else - g_condition_variable.notify_all(); -} - -void -do_bad_thing_with_location(char *char_ptr, char new_val) -{ - unsigned what = new_val; - printf("new value written to location(%p) = %u\n", char_ptr, what); - *char_ptr = new_val; -} - -uint32_t -access_pool (bool flag = false) -{ - static std::mutex g_access_mutex; - g_access_mutex.lock(); - - char old_val = *g_char_ptr; - if (flag) - do_bad_thing_with_location(g_char_ptr, old_val + 1); - - g_access_mutex.unlock(); - return *g_char_ptr; -} - -void -thread_func (uint32_t thread_index) -{ - printf ("%s (thread index = %u) startng...\n", __FUNCTION__, thread_index); - - barrier_wait(); - - uint32_t count = 0; - uint32_t val; - while (count++ < 15) - { - // random micro second sleep from zero to 3 seconds - int usec = g_distribution(g_random_engine); - printf ("%s (thread = %u) doing a usleep (%d)...\n", __FUNCTION__, thread_index, usec); - std::this_thread::sleep_for(std::chrono::microseconds{usec}); - - if (count < 7) - val = access_pool (); - else - val = access_pool (true); - - printf ("%s (thread = %u) after usleep access_pool returns %d (count=%d)...\n", __FUNCTION__, thread_index, val, count); - } - printf ("%s (thread index = %u) exiting...\n", __FUNCTION__, thread_index); -} - - -int main (int argc, char const *argv[]) -{ - g_count = 4; - std::thread threads[3]; - - g_char_ptr = new char{}; - - // Create 3 threads - for (auto &thread : threads) - thread = std::thread{thread_func, std::distance(threads, &thread)}; - - printf ("Before turning all three threads loose...\n"); // Set break point at this line. - barrier_wait(); - - // Join all of our threads - for (auto &thread : threads) - thread.join(); - - delete g_char_ptr; - - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/hello_watchpoint/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/hello_watchpoint/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/hello_watchpoint/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/hello_watchpoint/TestMyFirstWatchpoint.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/hello_watchpoint/TestMyFirstWatchpoint.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/hello_watchpoint/TestMyFirstWatchpoint.py @@ -1,95 +0,0 @@ -""" -Test my first lldb watchpoint. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class HelloWatchpointTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Our simple source filename. - self.source = 'main.c' - # Find the line number to break inside main(). - self.line = line_number( - self.source, '// Set break point at this line.') - # And the watchpoint variable declaration line number. - self.decl = line_number(self.source, - '// Watchpoint variable declaration.') - self.exe_name = self.getBuildArtifact('a.out') - self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} - - @expectedFailureAll( - oslist=["windows"], - bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") - @add_test_categories(["basic_process"]) - def test_hello_watchpoint_using_watchpoint_set(self): - """Test a simple sequence of watchpoint creation and watchpoint hit.""" - self.build(dictionary=self.d) - self.setTearDownCleanup(dictionary=self.d) - - exe = self.getBuildArtifact(self.exe_name) - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # Add a breakpoint to set a watchpoint when stopped on the breakpoint. - lldbutil.run_break_set_by_file_and_line( - self, None, self.line, num_expected_locations=1) - - # Run the program. - self.runCmd("run", RUN_SUCCEEDED) - - # We should be stopped again due to the breakpoint. - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', - 'stop reason = breakpoint']) - - # Now let's set a write-type watchpoint for 'global'. - # There should be only one watchpoint hit (see main.c). - self.expect( - "watchpoint set variable -w write global", - WATCHPOINT_CREATED, - substrs=[ - 'Watchpoint created', - 'size = 4', - 'type = w', - '%s:%d' % - (self.source, - self.decl)]) - - # Use the '-v' option to do verbose listing of the watchpoint. - # The hit count should be 0 initially. - self.expect("watchpoint list -v", - substrs=['hit_count = 0']) - - self.runCmd("process continue") - - # We should be stopped again due to the watchpoint (write type), but - # only once. The stop reason of the thread should be watchpoint. - self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT, - substrs=['stopped', - 'stop reason = watchpoint']) - - self.runCmd("process continue") - - # Don't expect the read of 'global' to trigger a stop exception. - process = self.dbg.GetSelectedTarget().GetProcess() - if process.GetState() == lldb.eStateStopped: - self.assertFalse( - lldbutil.get_stopped_thread( - process, lldb.eStopReasonWatchpoint)) - - # Use the '-v' option to do verbose listing of the watchpoint. - # The hit count should now be 1. - self.expect("watchpoint list -v", - substrs=['hit_count = 1']) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/hello_watchpoint/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/hello_watchpoint/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/hello_watchpoint/main.c @@ -1,29 +0,0 @@ -//===-- main.c --------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -#include -#include - -int32_t global = 10; // Watchpoint variable declaration. -char gchar1 = 'a'; -char gchar2 = 'b'; - -int main(int argc, char** argv) { - int local = 0; - printf("&global=%p\n", &global); - printf("about to write to 'global'...\n"); // Set break point at this line. - // When stopped, watch 'global' for write. - global = 20; - gchar1 += 1; - gchar2 += 1; - local += argc; - ++local; - printf("local: %d\n", local); - printf("global=%d\n", global); - printf("gchar1='%c'\n", gchar1); - printf("gchar2='%c'\n", gchar2); -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multi_watchpoint_slots/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multi_watchpoint_slots/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multi_watchpoint_slots/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multi_watchpoint_slots/TestWatchpointMultipleSlots.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multi_watchpoint_slots/TestWatchpointMultipleSlots.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multi_watchpoint_slots/TestWatchpointMultipleSlots.py @@ -1,101 +0,0 @@ -""" -Test watchpoint slots we should not be able to install multiple watchpoints -within same word boundary. We should be able to install individual watchpoints -on any of the bytes, half-word, or word. This is only for ARM/AArch64 targets. -""" - -from __future__ import print_function - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class WatchpointSlotsTestCase(TestBase): - NO_DEBUG_INFO_TESTCASE = True - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - - # Source filename. - self.source = 'main.c' - - # Output filename. - self.exe_name = self.getBuildArtifact("a.out") - self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} - - # This is a arm and aarch64 specific test case. No other architectures tested. - @skipIf(archs=no_match(['arm', 'aarch64'])) - def test_multiple_watchpoints_on_same_word(self): - - self.build(dictionary=self.d) - self.setTearDownCleanup(dictionary=self.d) - - exe = self.getBuildArtifact(self.exe_name) - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # Detect line number after which we are going to increment arrayName. - loc_line = line_number('main.c', '// About to write byteArray') - - # Set a breakpoint on the line detected above. - lldbutil.run_break_set_by_file_and_line( - self, "main.c", loc_line, num_expected_locations=1, loc_exact=True) - - # Run the program. - 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']) - - # Delete breakpoint we just hit. - self.expect("breakpoint delete 1", substrs=['1 breakpoints deleted']) - - # Set a watchpoint at byteArray[0] - self.expect("watchpoint set variable byteArray[0]", WATCHPOINT_CREATED, - substrs=['Watchpoint created','size = 1']) - - # Use the '-v' option to do verbose listing of the watchpoint. - # The hit count should be 0 initially. - self.expect("watchpoint list -v 1", substrs=['hit_count = 0']) - - # debugserver on ios doesn't give an error, it creates another watchpoint, - # only expect errors on non-darwin platforms. - if not self.platformIsDarwin(): - # Try setting a watchpoint at byteArray[1] - self.expect("watchpoint set variable byteArray[1]", error=True, - substrs=['Watchpoint creation failed']) - - self.runCmd("process continue") - - # We should be stopped due to the watchpoint. - # The stop reason of the thread should be watchpoint. - self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT, - substrs=['stopped', 'stop reason = watchpoint 1']) - - # Delete the watchpoint we hit above successfully. - self.expect("watchpoint delete 1", substrs=['1 watchpoints deleted']) - - # Set a watchpoint at byteArray[3] - self.expect("watchpoint set variable byteArray[3]", WATCHPOINT_CREATED, - substrs=['Watchpoint created','size = 1']) - - # Resume inferior. - self.runCmd("process continue") - - # We should be stopped due to the watchpoint. - # The stop reason of the thread should be watchpoint. - if self.platformIsDarwin(): - # On darwin we'll hit byteArray[3] which is watchpoint 2 - self.expect("thread list -v", STOPPED_DUE_TO_WATCHPOINT, - substrs=['stopped', 'stop reason = watchpoint 2']) - else: - self.expect("thread list -v", STOPPED_DUE_TO_WATCHPOINT, - substrs=['stopped', 'stop reason = watchpoint 3']) - - # Resume inferior. - self.runCmd("process continue") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multi_watchpoint_slots/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multi_watchpoint_slots/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multi_watchpoint_slots/main.c @@ -1,28 +0,0 @@ -//===-- main.c --------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -#include -#include - -uint64_t pad0 = 0; -uint8_t byteArray[4] = {0}; -uint64_t pad1 = 0; - -int main(int argc, char** argv) { - - int i; - - for (i = 0; i < 4; i++) - { - printf("About to write byteArray[%d] ...\n", i); // About to write byteArray - pad0++; - byteArray[i] = 7; - pad1++; - } - - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_hits/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_hits/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_hits/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_hits/TestMultipleHits.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_hits/TestMultipleHits.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_hits/TestMultipleHits.py @@ -1,57 +0,0 @@ -""" -Test handling of cases when a single instruction triggers multiple watchpoints -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class MultipleHitsTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - NO_DEBUG_INFO_TESTCASE = True - - @expectedFailureAll( - oslist=["windows"], - bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") - @skipIf(bugnumber="llvm.org/pr30758", oslist=["linux"], archs=["arm", "aarch64", "powerpc64le"]) - @skipIfwatchOS - def test(self): - self.build() - exe = self.getBuildArtifact("a.out") - target = self.dbg.CreateTarget(exe) - self.assertTrue(target and target.IsValid(), VALID_TARGET) - - bp = target.BreakpointCreateByName("main") - self.assertTrue(bp and bp.IsValid(), "Breakpoint is valid") - - process = target.LaunchSimple(None, None, - self.get_process_working_directory()) - self.assertEqual(process.GetState(), lldb.eStateStopped) - - thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) - self.assertIsNotNone(thread) - - frame = thread.GetFrameAtIndex(0) - self.assertTrue(frame and frame.IsValid(), "Frame is valid") - - buf = frame.FindValue("buf", lldb.eValueTypeVariableGlobal) - self.assertTrue(buf and buf.IsValid(), "buf is valid") - - for i in [0, target.GetAddressByteSize()]: - member = buf.GetChildAtIndex(i) - self.assertTrue(member and member.IsValid(), "member is valid") - - error = lldb.SBError() - watch = member.Watch(True, True, True, error) - self.assertTrue(error.Success()) - - process.Continue(); - self.assertEqual(process.GetState(), lldb.eStateStopped) - self.assertEqual(thread.GetStopReason(), lldb.eStopReasonWatchpoint) - Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_hits/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_hits/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_hits/main.cpp @@ -1,28 +0,0 @@ -//===-- main.cpp ------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -#include -#include -alignas(16) uint8_t buf[32]; -// This uses inline assembly to generate an instruction that writes to a large -// block of memory. If it fails on your compiler/architecture, please add -// appropriate code to generate a large write to "buf". If you cannot write at -// least 2*sizeof(void*) bytes with a single instruction, you will have to skip -// this test. - -int main() { -#if defined(__i386__) || defined(__x86_64__) - asm volatile ("movdqa %%xmm0, %0" : : "m"(buf)); -#elif defined(__arm__) - asm volatile ("stm %0, { r0, r1, r2, r3 }" : : "r"(buf)); -#elif defined(__aarch64__) - asm volatile ("stp x0, x1, %0" : : "m"(buf)); -#elif defined(__mips__) - asm volatile ("lw $2, %0" : : "m"(buf)); -#endif - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_threads/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_threads/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_threads/Makefile @@ -1,6 +0,0 @@ -LEVEL = ../../../make - -ENABLE_THREADS := YES -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_threads/TestWatchpointMultipleThreads.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_threads/TestWatchpointMultipleThreads.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_threads/TestWatchpointMultipleThreads.py @@ -1,119 +0,0 @@ -""" -Test that lldb watchpoint works for multiple threads. -""" - -from __future__ import print_function - - -import re -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class WatchpointForMultipleThreadsTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - NO_DEBUG_INFO_TESTCASE = True - main_spec = lldb.SBFileSpec("main.cpp", False) - - @expectedFailureAll( - oslist=["windows"], - bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") - @expectedFailureNetBSD - def test_watchpoint_before_thread_start(self): - """Test that we can hit a watchpoint we set before starting another thread""" - self.do_watchpoint_test("Before running the thread") - - @expectedFailureAll( - oslist=["windows"], - bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") - @expectedFailureNetBSD - def test_watchpoint_after_thread_start(self): - """Test that we can hit a watchpoint we set after starting another thread""" - self.do_watchpoint_test("After running the thread") - - def do_watchpoint_test(self, line): - self.build() - lldbutil.run_to_source_breakpoint(self, line, self.main_spec) - - # Now let's set a write-type watchpoint for variable 'g_val'. - self.expect( - "watchpoint set variable -w write g_val", - WATCHPOINT_CREATED, - substrs=[ - 'Watchpoint created', - 'size = 4', - 'type = w']) - - # Use the '-v' option to do verbose listing of the watchpoint. - # The hit count should be 0 initially. - self.expect("watchpoint list -v", - substrs=['hit_count = 0']) - - self.runCmd("process continue") - - self.runCmd("thread list") - if "stop reason = watchpoint" in self.res.GetOutput(): - # Good, we verified that the watchpoint works! - self.runCmd("thread backtrace all") - else: - self.fail("The stop reason should be either break or watchpoint") - - # Use the '-v' option to do verbose listing of the watchpoint. - # The hit count should now be 1. - self.expect("watchpoint list -v", - substrs=['hit_count = 1']) - - @expectedFailureAll( - oslist=["windows"], - bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") - def test_watchpoint_multiple_threads_wp_set_and_then_delete(self): - """Test that lldb watchpoint works for multiple threads, and after the watchpoint is deleted, the watchpoint event should no longer fires.""" - self.build() - self.setTearDownCleanup() - - lldbutil.run_to_source_breakpoint(self, "After running the thread", self.main_spec) - - # Now let's set a write-type watchpoint for variable 'g_val'. - self.expect( - "watchpoint set variable -w write g_val", - WATCHPOINT_CREATED, - substrs=[ - 'Watchpoint created', - 'size = 4', - 'type = w']) - - # Use the '-v' option to do verbose listing of the watchpoint. - # The hit count should be 0 initially. - self.expect("watchpoint list -v", - substrs=['hit_count = 0']) - - watchpoint_stops = 0 - while True: - self.runCmd("process continue") - self.runCmd("process status") - if re.search("Process .* exited", self.res.GetOutput()): - # Great, we are done with this test! - break - - self.runCmd("thread list") - if "stop reason = watchpoint" in self.res.GetOutput(): - self.runCmd("thread backtrace all") - watchpoint_stops += 1 - if watchpoint_stops > 1: - self.fail( - "Watchpoint hits not supposed to exceed 1 by design!") - # Good, we verified that the watchpoint works! Now delete the - # watchpoint. - if self.TraceOn(): - print( - "watchpoint_stops=%d at the moment we delete the watchpoint" % - watchpoint_stops) - self.runCmd("watchpoint delete 1") - self.expect("watchpoint list -v", - substrs=['No watchpoints currently set.']) - continue - else: - self.fail("The stop reason should be either break or watchpoint") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_threads/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_threads/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_threads/main.cpp @@ -1,34 +0,0 @@ -//===-- main.cpp ------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "pseudo_barrier.h" -#include -#include - -volatile uint32_t g_val = 0; -pseudo_barrier_t g_barrier; - -void thread_func() { - pseudo_barrier_wait(g_barrier); - printf("%s starting...\n", __FUNCTION__); - for (uint32_t i = 0; i < 10; ++i) - g_val = i; -} - -int main(int argc, char const *argv[]) { - printf("Before running the thread\n"); - pseudo_barrier_init(g_barrier, 2); - std::thread thread(thread_func); - - printf("After running the thread\n"); - pseudo_barrier_wait(g_barrier); - - thread.join(); - - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/step_over_watchpoint/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/step_over_watchpoint/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/step_over_watchpoint/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/step_over_watchpoint/TestStepOverWatchpoint.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/step_over_watchpoint/TestStepOverWatchpoint.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/step_over_watchpoint/TestStepOverWatchpoint.py @@ -1,122 +0,0 @@ -"""Test stepping over watchpoints.""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestStepOverWatchpoint(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @expectedFailureAll( - oslist=["linux"], - archs=[ - 'aarch64', - 'arm'], - bugnumber="llvm.org/pr26031") - @expectedFailureAll( - oslist=["windows"], - bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") - # Read-write watchpoints not supported on SystemZ - @expectedFailureAll(archs=['s390x']) - @expectedFailureAll(oslist=["ios", "watchos", "tvos", "bridgeos"], bugnumber="") # watchpoint tests aren't working on arm64 - @add_test_categories(["basic_process"]) - def test(self): - """Test stepping over watchpoints.""" - self.build() - exe = self.getBuildArtifact("a.out") - - target = self.dbg.CreateTarget(exe) - self.assertTrue(self.target, VALID_TARGET) - - lldbutil.run_break_set_by_symbol(self, 'main') - - process = target.LaunchSimple(None, None, - self.get_process_working_directory()) - self.assertTrue(process.IsValid(), PROCESS_IS_VALID) - self.assertTrue(process.GetState() == lldb.eStateStopped, - PROCESS_STOPPED) - - thread = lldbutil.get_stopped_thread(process, - lldb.eStopReasonBreakpoint) - self.assertTrue(thread.IsValid(), "Failed to get thread.") - - frame = thread.GetFrameAtIndex(0) - self.assertTrue(frame.IsValid(), "Failed to get frame.") - - read_value = frame.FindValue('g_watch_me_read', - lldb.eValueTypeVariableGlobal) - self.assertTrue(read_value.IsValid(), "Failed to find read value.") - - error = lldb.SBError() - - # resolve_location=True, read=True, write=False - read_watchpoint = read_value.Watch(True, True, False, error) - self.assertTrue(error.Success(), - "Error while setting watchpoint: %s" % - error.GetCString()) - self.assertTrue(read_watchpoint, "Failed to set read watchpoint.") - - thread.StepOver() - self.assertTrue(thread.GetStopReason() == lldb.eStopReasonWatchpoint, - STOPPED_DUE_TO_WATCHPOINT) - self.assertTrue(thread.GetStopDescription(20) == 'watchpoint 1') - - process.Continue() - self.assertTrue(process.GetState() == lldb.eStateStopped, - PROCESS_STOPPED) - self.assertTrue(thread.GetStopDescription(20) == 'step over') - - self.step_inst_for_watchpoint(1) - - write_value = frame.FindValue('g_watch_me_write', - lldb.eValueTypeVariableGlobal) - self.assertTrue(write_value, "Failed to find write value.") - - # Most of the MIPS boards provide only one H/W watchpoints, and S/W - # watchpoints are not supported yet - arch = self.getArchitecture() - if re.match("^mips", arch) or re.match("powerpc64le", arch): - self.runCmd("watchpoint delete 1") - - # resolve_location=True, read=False, write=True - write_watchpoint = write_value.Watch(True, False, True, error) - self.assertTrue(write_watchpoint, "Failed to set write watchpoint.") - self.assertTrue(error.Success(), - "Error while setting watchpoint: %s" % - error.GetCString()) - - thread.StepOver() - self.assertTrue(thread.GetStopReason() == lldb.eStopReasonWatchpoint, - STOPPED_DUE_TO_WATCHPOINT) - self.assertTrue(thread.GetStopDescription(20) == 'watchpoint 2') - - process.Continue() - self.assertTrue(process.GetState() == lldb.eStateStopped, - PROCESS_STOPPED) - self.assertTrue(thread.GetStopDescription(20) == 'step over') - - self.step_inst_for_watchpoint(2) - - def step_inst_for_watchpoint(self, wp_id): - watchpoint_hit = False - current_line = self.frame().GetLineEntry().GetLine() - while self.frame().GetLineEntry().GetLine() == current_line: - self.thread().StepInstruction(False) # step_over=False - stop_reason = self.thread().GetStopReason() - if stop_reason == lldb.eStopReasonWatchpoint: - self.assertFalse(watchpoint_hit, "Watchpoint already hit.") - expected_stop_desc = "watchpoint %d" % wp_id - actual_stop_desc = self.thread().GetStopDescription(20) - self.assertTrue(actual_stop_desc == expected_stop_desc, - "Watchpoint ID didn't match.") - watchpoint_hit = True - else: - self.assertTrue(stop_reason == lldb.eStopReasonPlanComplete, - STOPPED_DUE_TO_STEP_IN) - self.assertTrue(watchpoint_hit, "Watchpoint never hit.") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/step_over_watchpoint/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/step_over_watchpoint/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/step_over_watchpoint/main.c @@ -1,19 +0,0 @@ -char g_watch_me_read; -char g_watch_me_write; -char g_temp; - -void watch_read() { - g_temp = g_watch_me_read; -} - -void watch_write() { - g_watch_me_write = g_temp; -} - -int main() { - watch_read(); - g_temp = g_watch_me_read; - watch_write(); - g_watch_me_write = g_temp; - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/variable_out_of_scope/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/variable_out_of_scope/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/variable_out_of_scope/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/variable_out_of_scope/TestWatchedVarHitWhenInScope.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/variable_out_of_scope/TestWatchedVarHitWhenInScope.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/variable_out_of_scope/TestWatchedVarHitWhenInScope.py @@ -1,84 +0,0 @@ -""" -Test that a variable watchpoint should only hit when in scope. -""" - -from __future__ import print_function - - -import unittest2 -import lldb -from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil -from lldbsuite.test.decorators import * - - -class WatchedVariableHitWhenInScopeTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - # This test depends on not tracking watchpoint expression hits if we have - # left the watchpoint scope. We will provide such an ability at some point - # but the way this was done was incorrect, and it is unclear that for the - # most part that's not what folks mostly want, so we have to provide a - # clearer API to express this. - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Our simple source filename. - self.source = 'main.c' - self.exe_name = self.testMethodName - self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} - - # Test hangs due to a kernel bug, see fdfeff0f in the linux kernel for details - @skipIfTargetAndroid(api_levels=list(range(25+1)), archs=["aarch64", "arm"]) - @skipIf - def test_watched_var_should_only_hit_when_in_scope(self): - """Test that a variable watchpoint should only hit when in scope.""" - self.build(dictionary=self.d) - self.setTearDownCleanup(dictionary=self.d) - - exe = self.getBuildArtifact(self.exe_name) - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # Add a breakpoint to set a watchpoint when stopped in main. - lldbutil.run_break_set_by_symbol( - self, "main", num_expected_locations=-1) - - # Run the program. - self.runCmd("run", RUN_SUCCEEDED) - - # We should be stopped again due to the breakpoint. - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', - 'stop reason = breakpoint']) - - # Now let's set a watchpoint for 'c.a'. - # There should be only one watchpoint hit (see main.c). - self.expect("watchpoint set variable c.a", WATCHPOINT_CREATED, - substrs=['Watchpoint created', 'size = 4', 'type = w']) - - # Use the '-v' option to do verbose listing of the watchpoint. - # The hit count should be 0 initially. - self.expect("watchpoint list -v", - substrs=['hit_count = 0']) - - self.runCmd("process continue") - - # We should be stopped again due to the watchpoint (write type), but - # only once. The stop reason of the thread should be watchpoint. - self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT, - substrs=['stopped', - 'stop reason = watchpoint']) - - self.runCmd("process continue") - # Don't expect the read of 'global' to trigger a stop exception. - # The process status should be 'exited'. - self.expect("process status", - substrs=['exited']) - - # Use the '-v' option to do verbose listing of the watchpoint. - # The hit count should now be 1. - self.expect("watchpoint list -v", - substrs=['hit_count = 1']) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/variable_out_of_scope/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/variable_out_of_scope/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/variable_out_of_scope/main.c @@ -1,15 +0,0 @@ -typedef struct -{ - int a; - float b; -} mystruct; - -int main() -{ - mystruct c; - - c.a = 5; - c.b = 3.6; - - return 0; -} \ No newline at end of file Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/TestWatchpointCommands.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/TestWatchpointCommands.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/TestWatchpointCommands.py @@ -1,375 +0,0 @@ -""" -Test watchpoint list, enable, disable, and delete commands. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class WatchpointCommandsTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Our simple source filename. - self.source = 'main.c' - # Find the line number to break inside main(). - self.line = line_number( - self.source, '// Set break point at this line.') - self.line2 = line_number( - self.source, - '// Set 2nd break point for disable_then_enable test case.') - # And the watchpoint variable declaration line number. - self.decl = line_number(self.source, - '// Watchpoint variable declaration.') - # Build dictionary to have unique executable names for each test - # method. - self.exe_name = self.testMethodName - self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} - - @expectedFailureAll( - oslist=["windows"], - bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") - # Read-write watchpoints not supported on SystemZ - @expectedFailureAll(archs=['s390x']) - def test_rw_watchpoint(self): - """Test read_write watchpoint and expect to stop two times.""" - self.build(dictionary=self.d) - self.setTearDownCleanup(dictionary=self.d) - - exe = self.getBuildArtifact(self.exe_name) - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # Add a breakpoint to set a watchpoint when stopped on the breakpoint. - lldbutil.run_break_set_by_file_and_line( - self, None, self.line, num_expected_locations=1) - - # Run the program. - self.runCmd("run", RUN_SUCCEEDED) - - # We should be stopped again due to the breakpoint. - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', - 'stop reason = breakpoint']) - - # Now let's set a read_write-type watchpoint for 'global'. - # There should be two watchpoint hits (see main.c). - self.expect( - "watchpoint set variable -w read_write global", - WATCHPOINT_CREATED, - substrs=[ - 'Watchpoint created', - 'size = 4', - 'type = rw', - '%s:%d' % - (self.source, - self.decl)]) - - # Use the '-v' option to do verbose listing of the watchpoint. - # The hit count should be 0 initially. - self.expect("watchpoint list -v", - substrs=['Number of supported hardware watchpoints:', - 'hit_count = 0']) - - self.runCmd("process continue") - - # We should be stopped again due to the watchpoint (read_write type). - # The stop reason of the thread should be watchpoint. - self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT, - substrs=['stop reason = watchpoint']) - - self.runCmd("process continue") - - # We should be stopped again due to the watchpoint (read_write type). - # The stop reason of the thread should be watchpoint. - self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT, - substrs=['stop reason = watchpoint']) - - self.runCmd("process continue") - - # There should be no more watchpoint hit and the process status should - # be 'exited'. - self.expect("process status", - substrs=['exited']) - - # Use the '-v' option to do verbose listing of the watchpoint. - # The hit count should now be 2. - self.expect("watchpoint list -v", - substrs=['hit_count = 2']) - - @expectedFailureAll( - oslist=["windows"], - bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") - # Read-write watchpoints not supported on SystemZ - @expectedFailureAll(archs=['s390x']) - def test_rw_watchpoint_delete(self): - """Test delete watchpoint and expect not to stop for watchpoint.""" - self.build(dictionary=self.d) - self.setTearDownCleanup(dictionary=self.d) - - exe = self.getBuildArtifact(self.exe_name) - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # Add a breakpoint to set a watchpoint when stopped on the breakpoint. - lldbutil.run_break_set_by_file_and_line( - self, None, self.line, num_expected_locations=1) - - # Run the program. - self.runCmd("run", RUN_SUCCEEDED) - - # We should be stopped again due to the breakpoint. - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', - 'stop reason = breakpoint']) - - # Now let's set a read_write-type watchpoint for 'global'. - # There should be two watchpoint hits (see main.c). - self.expect( - "watchpoint set variable -w read_write global", - WATCHPOINT_CREATED, - substrs=[ - 'Watchpoint created', - 'size = 4', - 'type = rw', - '%s:%d' % - (self.source, - self.decl)]) - - # Delete the watchpoint immediately, but set auto-confirm to true - # first. - self.runCmd("settings set auto-confirm true") - self.expect("watchpoint delete", - substrs=['All watchpoints removed.']) - # Restore the original setting of auto-confirm. - self.runCmd("settings clear auto-confirm") - - # Use the '-v' option to do verbose listing of the watchpoint. - self.runCmd("watchpoint list -v") - - self.runCmd("process continue") - - # There should be no more watchpoint hit and the process status should - # be 'exited'. - self.expect("process status", - substrs=['exited']) - - @expectedFailureAll( - oslist=["windows"], - bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") - # Read-write watchpoints not supported on SystemZ - @expectedFailureAll(archs=['s390x']) - def test_rw_watchpoint_set_ignore_count(self): - """Test watchpoint ignore count and expect to not to stop at all.""" - self.build(dictionary=self.d) - self.setTearDownCleanup(dictionary=self.d) - - exe = self.getBuildArtifact(self.exe_name) - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # Add a breakpoint to set a watchpoint when stopped on the breakpoint. - lldbutil.run_break_set_by_file_and_line( - self, None, self.line, num_expected_locations=1) - - # Run the program. - self.runCmd("run", RUN_SUCCEEDED) - - # We should be stopped again due to the breakpoint. - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', - 'stop reason = breakpoint']) - - # Now let's set a read_write-type watchpoint for 'global'. - # There should be two watchpoint hits (see main.c). - self.expect( - "watchpoint set variable -w read_write global", - WATCHPOINT_CREATED, - substrs=[ - 'Watchpoint created', - 'size = 4', - 'type = rw', - '%s:%d' % - (self.source, - self.decl)]) - - # Set the ignore count of the watchpoint immediately. - self.expect("watchpoint ignore -i 2", - substrs=['All watchpoints ignored.']) - - # Use the '-v' option to do verbose listing of the watchpoint. - # Expect to find an ignore_count of 2. - self.expect("watchpoint list -v", - substrs=['hit_count = 0', 'ignore_count = 2']) - - self.runCmd("process continue") - - # There should be no more watchpoint hit and the process status should - # be 'exited'. - self.expect("process status", - substrs=['exited']) - - # Use the '-v' option to do verbose listing of the watchpoint. - # Expect to find a hit_count of 2 as well. - self.expect("watchpoint list -v", - substrs=['hit_count = 2', 'ignore_count = 2']) - - @expectedFailureAll( - oslist=["windows"], - bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") - # Read-write watchpoints not supported on SystemZ - @expectedFailureAll(archs=['s390x']) - def test_rw_disable_after_first_stop(self): - """Test read_write watchpoint but disable it after the first stop.""" - self.build(dictionary=self.d) - self.setTearDownCleanup(dictionary=self.d) - - exe = self.getBuildArtifact(self.exe_name) - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # Add a breakpoint to set a watchpoint when stopped on the breakpoint. - lldbutil.run_break_set_by_file_and_line( - self, None, self.line, num_expected_locations=1) - - # Run the program. - self.runCmd("run", RUN_SUCCEEDED) - - # We should be stopped again due to the breakpoint. - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', - 'stop reason = breakpoint']) - - # Now let's set a read_write-type watchpoint for 'global'. - # There should be two watchpoint hits (see main.c). - self.expect( - "watchpoint set variable -w read_write global", - WATCHPOINT_CREATED, - substrs=[ - 'Watchpoint created', - 'size = 4', - 'type = rw', - '%s:%d' % - (self.source, - self.decl)]) - - # Use the '-v' option to do verbose listing of the watchpoint. - # The hit count should be 0 initially. - self.expect("watchpoint list -v", - substrs=['state = enabled', 'hit_count = 0']) - - self.runCmd("process continue") - - # We should be stopped again due to the watchpoint (read_write type). - # The stop reason of the thread should be watchpoint. - self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT, - substrs=['stop reason = watchpoint']) - - # Before continuing, we'll disable the watchpoint, which means we won't - # stop again after this. - self.runCmd("watchpoint disable") - - self.expect("watchpoint list -v", - substrs=['state = disabled', 'hit_count = 1']) - - self.runCmd("process continue") - - # There should be no more watchpoint hit and the process status should - # be 'exited'. - self.expect("process status", - substrs=['exited']) - - # Use the '-v' option to do verbose listing of the watchpoint. - # The hit count should be 1. - self.expect("watchpoint list -v", - substrs=['hit_count = 1']) - - @expectedFailureAll( - oslist=["windows"], - bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") - # Read-write watchpoints not supported on SystemZ - @expectedFailureAll(archs=['s390x']) - def test_rw_disable_then_enable(self): - """Test read_write watchpoint, disable initially, then enable it.""" - self.build(dictionary=self.d) - self.setTearDownCleanup(dictionary=self.d) - - exe = self.getBuildArtifact(self.exe_name) - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # Add a breakpoint to set a watchpoint when stopped on the breakpoint. - lldbutil.run_break_set_by_file_and_line( - self, None, self.line, num_expected_locations=1) - lldbutil.run_break_set_by_file_and_line( - self, None, self.line2, num_expected_locations=1) - - # Run the program. - self.runCmd("run", RUN_SUCCEEDED) - - # We should be stopped again due to the breakpoint. - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', - 'stop reason = breakpoint']) - - # Now let's set a read_write-type watchpoint for 'global'. - # There should be two watchpoint hits (see main.c). - self.expect( - "watchpoint set variable -w read_write global", - WATCHPOINT_CREATED, - substrs=[ - 'Watchpoint created', - 'size = 4', - 'type = rw', - '%s:%d' % - (self.source, - self.decl)]) - - # Immediately, we disable the watchpoint. We won't be stopping due to a - # watchpoint after this. - self.runCmd("watchpoint disable") - - # Use the '-v' option to do verbose listing of the watchpoint. - # The hit count should be 0 initially. - self.expect("watchpoint list -v", - substrs=['state = disabled', 'hit_count = 0']) - - self.runCmd("process continue") - - # We should be stopped again due to the breakpoint. - self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, - substrs=['stop reason = breakpoint']) - - # Before continuing, we'll enable the watchpoint, which means we will - # stop again after this. - self.runCmd("watchpoint enable") - - self.expect("watchpoint list -v", - substrs=['state = enabled', 'hit_count = 0']) - - self.runCmd("process continue") - - # We should be stopped again due to the watchpoint (read_write type). - # The stop reason of the thread should be watchpoint. - self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT, - substrs=['stop reason = watchpoint']) - - self.runCmd("process continue") - - # There should be no more watchpoint hit and the process status should - # be 'exited'. - self.expect("process status", - substrs=['exited']) - - # Use the '-v' option to do verbose listing of the watchpoint. - # The hit count should be 1. - self.expect("watchpoint list -v", - substrs=['hit_count = 1']) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/command/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/command/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/command/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/command/TestWatchpointCommandLLDB.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/command/TestWatchpointCommandLLDB.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/command/TestWatchpointCommandLLDB.py @@ -1,172 +0,0 @@ -""" -Test 'watchpoint command'. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class WatchpointLLDBCommandTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Our simple source filename. - self.source = 'main.cpp' - # Find the line number to break inside main(). - self.line = line_number( - self.source, '// Set break point at this line.') - # And the watchpoint variable declaration line number. - self.decl = line_number(self.source, - '// Watchpoint variable declaration.') - # Build dictionary to have unique executable names for each test - # method. - self.exe_name = 'a%d.out' % self.test_number - self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name} - - @expectedFailureAll( - oslist=["linux"], - archs=["aarch64"], - triple=no_match(".*-android"), - bugnumber="llvm.org/pr27710") # work on android - @expectedFailureAll( - oslist=["windows"], - bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") - @expectedFailureNetBSD - def test_watchpoint_command(self): - """Test 'watchpoint command'.""" - self.build(dictionary=self.d) - self.setTearDownCleanup(dictionary=self.d) - - exe = self.getBuildArtifact(self.exe_name) - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # Add a breakpoint to set a watchpoint when stopped on the breakpoint. - lldbutil.run_break_set_by_file_and_line( - self, None, self.line, num_expected_locations=1) - - # Run the program. - self.runCmd("run", RUN_SUCCEEDED) - - # We should be stopped again due to the breakpoint. - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', - 'stop reason = breakpoint']) - - # Now let's set a write-type watchpoint for 'global'. - self.expect( - "watchpoint set variable -w write global", - WATCHPOINT_CREATED, - substrs=[ - 'Watchpoint created', - 'size = 4', - 'type = w', - '%s:%d' % - (self.source, - self.decl)]) - - self.runCmd('watchpoint command add 1 -o "expr -- cookie = 777"') - - # List the watchpoint command we just added. - self.expect("watchpoint command list 1", - substrs=['expr -- cookie = 777']) - - # Use the '-v' option to do verbose listing of the watchpoint. - # The hit count should be 0 initially. - self.expect("watchpoint list -v", - substrs=['hit_count = 0']) - - self.runCmd("process continue") - - # We should be stopped again due to the watchpoint (write type). - # The stop reason of the thread should be watchpoint. - self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT, - substrs=['stop reason = watchpoint']) - - # Check that the watchpoint snapshoting mechanism is working. - self.expect("watchpoint list -v", - substrs=['old value:', ' = 0', - 'new value:', ' = 1']) - - # The watchpoint command "forced" our global variable 'cookie' to - # become 777. - self.expect("frame variable --show-globals cookie", - substrs=['(int32_t)', 'cookie = 777']) - - @expectedFailureAll( - oslist=["linux"], - archs=["aarch64"], - triple=no_match(".*-android"), - bugnumber="llvm.org/pr27710") # work on android - @expectedFailureAll( - oslist=["windows"], - bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") - def test_watchpoint_command_can_disable_a_watchpoint(self): - """Test that 'watchpoint command' action can disable a watchpoint after it is triggered.""" - self.build(dictionary=self.d) - self.setTearDownCleanup(dictionary=self.d) - - exe = self.getBuildArtifact(self.exe_name) - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # Add a breakpoint to set a watchpoint when stopped on the breakpoint. - lldbutil.run_break_set_by_file_and_line( - self, None, self.line, num_expected_locations=1) - - # Run the program. - self.runCmd("run", RUN_SUCCEEDED) - - # We should be stopped again due to the breakpoint. - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', - 'stop reason = breakpoint']) - - # Now let's set a write-type watchpoint for 'global'. - self.expect( - "watchpoint set variable -w write global", - WATCHPOINT_CREATED, - substrs=[ - 'Watchpoint created', - 'size = 4', - 'type = w', - '%s:%d' % - (self.source, - self.decl)]) - - self.runCmd('watchpoint command add 1 -o "watchpoint disable 1"') - - # List the watchpoint command we just added. - self.expect("watchpoint command list 1", - substrs=['watchpoint disable 1']) - - # Use the '-v' option to do verbose listing of the watchpoint. - # The hit count should be 0 initially. - self.expect("watchpoint list -v", - substrs=['hit_count = 0']) - - self.runCmd("process continue") - - # We should be stopped again due to the watchpoint (write type). - # The stop reason of the thread should be watchpoint. - self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT, - substrs=['stop reason = watchpoint']) - - # Check that the watchpoint has been disabled. - self.expect("watchpoint list -v", - substrs=['disabled']) - - self.runCmd("process continue") - - # There should be no more watchpoint hit and the process status should - # be 'exited'. - self.expect("process status", - substrs=['exited']) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/command/TestWatchpointCommandPython.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/command/TestWatchpointCommandPython.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/command/TestWatchpointCommandPython.py @@ -1,172 +0,0 @@ -""" -Test 'watchpoint command'. -""" - -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 WatchpointPythonCommandTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Our simple source filename. - self.source = 'main.cpp' - # Find the line number to break inside main(). - self.line = line_number( - self.source, '// Set break point at this line.') - # And the watchpoint variable declaration line number. - self.decl = line_number(self.source, - '// Watchpoint variable declaration.') - # Build dictionary to have unique executable names for each test - # method. - self.exe_name = self.testMethodName - self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name} - - @skipIfFreeBSD # timing out on buildbot - @expectedFailureAll( - oslist=["windows"], - bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") - @expectedFailureAll( - oslist=["linux"], - archs=["aarch64"], - triple=no_match(".*-android"), - bugnumber="llvm.org/pr27710") # work on android - @expectedFailureNetBSD - def test_watchpoint_command(self): - """Test 'watchpoint command'.""" - self.build(dictionary=self.d) - self.setTearDownCleanup(dictionary=self.d) - - exe = self.getBuildArtifact(self.exe_name) - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # Add a breakpoint to set a watchpoint when stopped on the breakpoint. - lldbutil.run_break_set_by_file_and_line( - self, None, self.line, num_expected_locations=1) - - # Run the program. - self.runCmd("run", RUN_SUCCEEDED) - - # We should be stopped again due to the breakpoint. - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', - 'stop reason = breakpoint']) - - # Now let's set a write-type watchpoint for 'global'. - self.expect( - "watchpoint set variable -w write global", - WATCHPOINT_CREATED, - substrs=[ - 'Watchpoint created', - 'size = 4', - 'type = w', - '%s:%d' % - (self.source, - self.decl)]) - - self.runCmd( - 'watchpoint command add -s python 1 -o \'frame.EvaluateExpression("cookie = 777")\'') - - # List the watchpoint command we just added. - self.expect("watchpoint command list 1", - substrs=['frame.EvaluateExpression', 'cookie = 777']) - - # Use the '-v' option to do verbose listing of the watchpoint. - # The hit count should be 0 initially. - self.expect("watchpoint list -v", - substrs=['hit_count = 0']) - - self.runCmd("process continue") - - # We should be stopped again due to the watchpoint (write type). - # The stop reason of the thread should be watchpoint. - self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT, - substrs=['stop reason = watchpoint']) - - # Check that the watchpoint snapshoting mechanism is working. - self.expect("watchpoint list -v", - substrs=['old value:', ' = 0', - 'new value:', ' = 1']) - - # The watchpoint command "forced" our global variable 'cookie' to - # become 777. - self.expect("frame variable --show-globals cookie", - substrs=['(int32_t)', 'cookie = 777']) - - @skipIfFreeBSD # timing out on buildbot - @expectedFailureAll( - oslist=["windows"], - bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") - @expectedFailureAll( - oslist=["linux"], - archs=["aarch64"], - triple=no_match(".*-android"), - bugnumber="llvm.org/pr27710") # work on android - @expectedFailureNetBSD - def test_continue_in_watchpoint_command(self): - """Test continue in a watchpoint command.""" - self.build(dictionary=self.d) - self.setTearDownCleanup(dictionary=self.d) - - exe = self.getBuildArtifact(self.exe_name) - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # Add a breakpoint to set a watchpoint when stopped on the breakpoint. - lldbutil.run_break_set_by_file_and_line( - self, None, self.line, num_expected_locations=1) - - # Run the program. - self.runCmd("run", RUN_SUCCEEDED) - - # We should be stopped again due to the breakpoint. - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', - 'stop reason = breakpoint']) - - # Now let's set a write-type watchpoint for 'global'. - self.expect( - "watchpoint set variable -w write global", - WATCHPOINT_CREATED, - substrs=[ - 'Watchpoint created', - 'size = 4', - 'type = w', - '%s:%d' % - (self.source, - self.decl)]) - - cmd_script_file = os.path.join(self.getSourceDir(), - "watchpoint_command.py") - self.runCmd("command script import '%s'" % (cmd_script_file)) - - self.runCmd( - 'watchpoint command add -F watchpoint_command.watchpoint_command') - - # List the watchpoint command we just added. - self.expect("watchpoint command list 1", - substrs=['watchpoint_command.watchpoint_command']) - - self.runCmd("process continue") - - # We should be stopped again due to the watchpoint (write type). - # The stop reason of the thread should be watchpoint. - self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT, - substrs=['stop reason = watchpoint']) - - # We should have hit the watchpoint once, set cookie to 888, then continued to the - # second hit and set it to 999 - self.expect("frame variable --show-globals cookie", - substrs=['(int32_t)', 'cookie = 999']) - Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/command/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/command/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/command/main.cpp @@ -1,27 +0,0 @@ -//===-- main.c --------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -#include -#include - -int32_t global = 0; // Watchpoint variable declaration. -int32_t cookie = 0; - -static void modify(int32_t &var) { - ++var; -} - -int main(int argc, char** argv) { - int local = 0; - printf("&global=%p\n", &global); - printf("about to write to 'global'...\n"); // Set break point at this line. - for (int i = 0; i < 10; ++i) - modify(global); - - printf("global=%d\n", global); - printf("cookie=%d\n", cookie); -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/command/watchpoint_command.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/command/watchpoint_command.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/command/watchpoint_command.py @@ -1,15 +0,0 @@ -import lldb - -num_hits = 0 - - -def watchpoint_command(frame, wp, dict): - global num_hits - if num_hits == 0: - print ("I stopped the first time") - frame.EvaluateExpression("cookie = 888") - num_hits += 1 - frame.thread.process.Continue() - else: - print ("I stopped the %d time" % (num_hits)) - frame.EvaluateExpression("cookie = 999") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/condition/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/condition/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/condition/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/condition/TestWatchpointConditionCmd.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/condition/TestWatchpointConditionCmd.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/condition/TestWatchpointConditionCmd.py @@ -1,96 +0,0 @@ -""" -Test watchpoint modify command to set condition on a watchpoint. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class WatchpointConditionCmdTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Our simple source filename. - self.source = 'main.cpp' - # Find the line number to break inside main(). - self.line = line_number( - self.source, '// Set break point at this line.') - # And the watchpoint variable declaration line number. - self.decl = line_number(self.source, - '// Watchpoint variable declaration.') - # Build dictionary to have unique executable names for each test - # method. - self.exe_name = self.testMethodName - self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name} - - @expectedFailureAll( - oslist=["linux"], - archs=["aarch64"], - triple=no_match(".*-android"), - bugnumber="llvm.org/pr27710") - @expectedFailureAll( - oslist=["windows"], - bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") - @expectedFailureNetBSD - def test_watchpoint_cond(self): - """Test watchpoint condition.""" - self.build(dictionary=self.d) - self.setTearDownCleanup(dictionary=self.d) - - exe = self.getBuildArtifact(self.exe_name) - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # Add a breakpoint to set a watchpoint when stopped on the breakpoint. - lldbutil.run_break_set_by_file_and_line( - self, None, self.line, num_expected_locations=1) - - # Run the program. - self.runCmd("run", RUN_SUCCEEDED) - - # We should be stopped again due to the breakpoint. - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', - 'stop reason = breakpoint']) - - # Now let's set a write-type watchpoint for 'global'. - # With a condition of 'global==5'. - self.expect( - "watchpoint set variable -w write global", - WATCHPOINT_CREATED, - substrs=[ - 'Watchpoint created', - 'size = 4', - 'type = w', - '%s:%d' % - (self.source, - self.decl)]) - - self.runCmd("watchpoint modify -c 'global==5'") - - # Use the '-v' option to do verbose listing of the watchpoint. - # The hit count should be 0 initially. - self.expect("watchpoint list -v", - substrs=['hit_count = 0', 'global==5']) - - self.runCmd("process continue") - - # We should be stopped again due to the watchpoint (write type). - # The stop reason of the thread should be watchpoint. - self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT, - substrs=['stop reason = watchpoint']) - self.expect("frame variable --show-globals global", - substrs=['(int32_t)', 'global = 5']) - - # Use the '-v' option to do verbose listing of the watchpoint. - # The hit count should now be 2. - self.expect("watchpoint list -v", - substrs=['hit_count = 5']) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/condition/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/condition/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/condition/main.cpp @@ -1,27 +0,0 @@ -//===-- main.c --------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -#include -#include - -int32_t global = 0; // Watchpoint variable declaration. - -static void modify(int32_t &var) { - ++var; -} - -int main(int argc, char** argv) { - int local = 0; - printf("&global=%p\n", &global); - printf("about to write to 'global'...\n"); // Set break point at this line. - // When stopped, watch 'global', - // for the condition "global == 5". - for (int i = 0; i < 10; ++i) - modify(global); - - printf("global=%d\n", global); -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/main.c @@ -1,23 +0,0 @@ -//===-- main.c --------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -#include -#include - -int32_t global = 10; // Watchpoint variable declaration. - -int main(int argc, char** argv) { - int local = 0; - printf("&global=%p\n", &global); - printf("about to write to 'global'...\n"); // Set break point at this line. - // When stopped, watch 'global'. - global = 20; - local += argc; - ++local; // Set 2nd break point for disable_then_enable test case. - printf("local: %d\n", local); - printf("global=%d\n", global); -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_disable/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_disable/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_disable/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_disable/TestWatchpointDisable.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_disable/TestWatchpointDisable.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_disable/TestWatchpointDisable.py @@ -1,80 +0,0 @@ -""" -Test that the SBWatchpoint::SetEnable API works. -""" - -import lldb -from lldbsuite.test.lldbtest import * -from lldbsuite.test.decorators import * -from lldbsuite.test import lldbplatform, lldbplatformutil - - -class TestWatchpointSetEnable(TestBase): - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - - @expectedFailureAll( - oslist=["windows"], - bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") - def test_disable_works (self): - """Set a watchpoint, disable it, and make sure it doesn't get hit.""" - self.build() - self.do_test(False) - - @expectedFailureAll( - oslist=["windows"], - bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") - def test_disable_enable_works (self): - """Set a watchpoint, disable it, and make sure it doesn't get hit.""" - self.build() - self.do_test(True) - - def do_test(self, test_enable): - """Set a watchpoint, disable it and make sure it doesn't get hit.""" - - exe = self.getBuildArtifact("a.out") - main_file_spec = lldb.SBFileSpec("main.c") - - # Create a target by the debugger. - self.target = self.dbg.CreateTarget(exe) - self.assertTrue(self.target, VALID_TARGET) - - bkpt_before = self.target.BreakpointCreateBySourceRegex("Set a breakpoint here", main_file_spec) - self.assertEqual(bkpt_before.GetNumLocations(), 1, "Failed setting the before breakpoint.") - - bkpt_after = self.target.BreakpointCreateBySourceRegex("We should have stopped", main_file_spec) - self.assertEqual(bkpt_after.GetNumLocations(), 1, "Failed setting the after breakpoint.") - - process = self.target.LaunchSimple( - None, None, self.get_process_working_directory()) - self.assertTrue(process, PROCESS_IS_VALID) - - thread = lldbutil.get_one_thread_stopped_at_breakpoint(process, bkpt_before) - self.assertTrue(thread.IsValid(), "We didn't stop at the before breakpoint.") - - ret_val = lldb.SBCommandReturnObject() - self.dbg.GetCommandInterpreter().HandleCommand("watchpoint set variable -w write global_var", ret_val) - self.assertTrue(ret_val.Succeeded(), "Watchpoint set variable did not return success.") - - wp = self.target.FindWatchpointByID(1) - self.assertTrue(wp.IsValid(), "Didn't make a valid watchpoint.") - self.assertTrue(wp.GetWatchAddress() != lldb.LLDB_INVALID_ADDRESS, "Watch address is invalid") - - wp.SetEnabled(False) - self.assertTrue(not wp.IsEnabled(), "The watchpoint thinks it is still enabled") - - process.Continue() - - stop_reason = thread.GetStopReason() - - self.assertEqual(stop_reason, lldb.eStopReasonBreakpoint, "We didn't stop at our breakpoint.") - - if test_enable: - wp.SetEnabled(True) - self.assertTrue(wp.IsEnabled(), "The watchpoint thinks it is still disabled.") - process.Continue() - stop_reason = thread.GetStopReason() - self.assertEqual(stop_reason, lldb.eStopReasonWatchpoint, "We didn't stop at our watchpoint") - Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_disable/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_disable/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_disable/main.c @@ -1,13 +0,0 @@ -#include - -int global_var = 10; - -int -main() -{ - printf("Set a breakpoint here: %d.\n", global_var); - global_var = 20; - printf("We should have stopped on the previous line: %d.\n", global_var); - global_var = 30; - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_events/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_events/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_events/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_events/TestWatchpointEvents.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_events/TestWatchpointEvents.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_events/TestWatchpointEvents.py @@ -1,117 +0,0 @@ -"""Test that adding, deleting and modifying watchpoints sends the appropriate events.""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestWatchpointEvents (TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line numbers that we will step to in main: - self.main_source = "main.c" - - @add_test_categories(['pyapi']) - @expectedFailureAll( - oslist=["linux"], - archs=["aarch64"], - triple=no_match(".*-android"), - bugnumber="llvm.org/pr27710") - @expectedFailureAll( - oslist=["windows"], - bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") - def test_with_python_api(self): - """Test that adding, deleting and modifying watchpoints sends the appropriate events.""" - self.build() - - exe = self.getBuildArtifact("a.out") - - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, VALID_TARGET) - - self.main_source_spec = lldb.SBFileSpec(self.main_source) - - break_in_main = target.BreakpointCreateBySourceRegex( - '// Put a breakpoint here.', self.main_source_spec) - self.assertTrue(break_in_main, VALID_BREAKPOINT) - - # Now launch the process, and do not stop at entry point. - process = target.LaunchSimple( - None, None, self.get_process_working_directory()) - - self.assertTrue(process, PROCESS_IS_VALID) - - # The stop reason of the thread should be breakpoint. - threads = lldbutil.get_threads_stopped_at_breakpoint( - process, break_in_main) - - if len(threads) != 1: - self.fail("Failed to stop at first breakpoint in main.") - - thread = threads[0] - frame = thread.GetFrameAtIndex(0) - local_var = frame.FindVariable("local_var") - self.assertTrue(local_var.IsValid()) - - self.listener = lldb.SBListener("com.lldb.testsuite_listener") - self.target_bcast = target.GetBroadcaster() - self.target_bcast.AddListener( - self.listener, lldb.SBTarget.eBroadcastBitWatchpointChanged) - self.listener.StartListeningForEvents( - self.target_bcast, lldb.SBTarget.eBroadcastBitWatchpointChanged) - - error = lldb.SBError() - local_watch = local_var.Watch(True, False, True, error) - if not error.Success(): - self.fail( - "Failed to make watchpoint for local_var: %s" % - (error.GetCString())) - - self.GetWatchpointEvent(lldb.eWatchpointEventTypeAdded) - # Now change some of the features of this watchpoint and make sure we - # get events: - local_watch.SetEnabled(False) - self.GetWatchpointEvent(lldb.eWatchpointEventTypeDisabled) - - local_watch.SetEnabled(True) - self.GetWatchpointEvent(lldb.eWatchpointEventTypeEnabled) - - local_watch.SetIgnoreCount(10) - self.GetWatchpointEvent(lldb.eWatchpointEventTypeIgnoreChanged) - - condition = "1 == 2" - local_watch.SetCondition(condition) - self.GetWatchpointEvent(lldb.eWatchpointEventTypeConditionChanged) - - self.assertTrue(local_watch.GetCondition() == condition, - 'make sure watchpoint condition is "' + condition + '"') - - def GetWatchpointEvent(self, event_type): - # We added a watchpoint so we should get a watchpoint added event. - event = lldb.SBEvent() - success = self.listener.WaitForEvent(1, event) - self.assertTrue(success, "Successfully got watchpoint event") - self.assertTrue( - lldb.SBWatchpoint.EventIsWatchpointEvent(event), - "Event is a watchpoint event.") - found_type = lldb.SBWatchpoint.GetWatchpointEventTypeFromEvent(event) - self.assertTrue( - found_type == event_type, - "Event is not correct type, expected: %d, found: %d" % - (event_type, - found_type)) - # There shouldn't be another event waiting around: - found_event = self.listener.PeekAtNextEventForBroadcasterWithType( - self.target_bcast, lldb.SBTarget.eBroadcastBitBreakpointChanged, event) - if found_event: - print("Found an event I didn't expect: ", event) - - self.assertTrue(not found_event, "Only one event per change.") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_events/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_events/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_events/main.c @@ -1,9 +0,0 @@ -#include - -int -main (int argc, char **argv) -{ - int local_var = 10; - printf ("local_var is: %d.\n", local_var++); // Put a breakpoint here. - return local_var; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_on_vectors/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_on_vectors/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_on_vectors/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_on_vectors/TestValueOfVectorVariable.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_on_vectors/TestValueOfVectorVariable.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_on_vectors/TestValueOfVectorVariable.py @@ -1,50 +0,0 @@ -""" -Test displayed value of a vector variable while doing watchpoint operations -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestValueOfVectorVariableTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @expectedFailureAll( - oslist=["windows"], - bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") - def test_value_of_vector_variable_using_watchpoint_set(self): - """Test verify displayed value of vector variable.""" - exe = self.getBuildArtifact("a.out") - d = {'C_SOURCES': self.source, 'EXE': exe} - self.build(dictionary=d) - self.setTearDownCleanup(dictionary=d) - self.value_of_vector_variable_with_watchpoint_set() - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Our simple source filename. - self.source = 'main.c' - - def value_of_vector_variable_with_watchpoint_set(self): - """Test verify displayed value of vector variable""" - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # Set break to get a frame - self.runCmd("b main") - - # Run the program. - self.runCmd("run", RUN_SUCCEEDED) - - # Value of a vector variable should be displayed correctly - self.expect( - "watchpoint set variable global_vector", - WATCHPOINT_CREATED, - substrs=['new value: (1, 2, 3, 4)']) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_on_vectors/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_on_vectors/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_on_vectors/main.c @@ -1,15 +0,0 @@ -//===-- main.c --------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -typedef signed char v4i8 __attribute__ ((vector_size(4))); -v4i8 global_vector = {1, 2, 3, 4}; - -int -main () -{ - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_set_command/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_set_command/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_set_command/Makefile @@ -1,6 +0,0 @@ -LEVEL = ../../../make - -ENABLE_THREADS := YES -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_set_command/TestWatchLocationWithWatchSet.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_set_command/TestWatchLocationWithWatchSet.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_set_command/TestWatchLocationWithWatchSet.py @@ -1,107 +0,0 @@ -""" -Test lldb watchpoint that uses 'watchpoint set -w write -s size' to watch a pointed location with size. -""" - -from __future__ import print_function - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class WatchLocationUsingWatchpointSetTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Our simple source filename. - self.source = 'main.cpp' - # Find the line number to break inside main(). - self.line = line_number( - self.source, '// Set break point at this line.') - # This is for verifying that watch location works. - self.violating_func = "do_bad_thing_with_location" - # Build dictionary to have unique executable names for each test - # method. - - @expectedFailureAll( - oslist=["linux"], - archs=[ - 'aarch64', - 'arm'], - bugnumber="llvm.org/pr26031") - @expectedFailureAll( - oslist=["windows"], - bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") - @expectedFailureNetBSD - def test_watchlocation_using_watchpoint_set(self): - """Test watching a location with 'watchpoint set expression -w write -s size' option.""" - self.build() - self.setTearDownCleanup() - - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # Add a breakpoint to set a watchpoint when stopped on the breakpoint. - lldbutil.run_break_set_by_file_and_line( - self, None, self.line, num_expected_locations=1) - - # Run the program. - self.runCmd("run", RUN_SUCCEEDED) - - # We should be stopped again due to the breakpoint. - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', - 'stop reason = breakpoint']) - - # Now let's set a write-type watchpoint pointed to by 'g_char_ptr' and - # with offset as 7. - # The main.cpp, by design, misbehaves by not following the agreed upon - # protocol of only accessing the allowable index range of [0, 6]. - self.expect( - "watchpoint set expression -w write -s 1 -- g_char_ptr + 7", - WATCHPOINT_CREATED, - substrs=[ - 'Watchpoint created', - 'size = 1', - 'type = w']) - self.runCmd("expr unsigned val = g_char_ptr[7]; val") - self.expect(self.res.GetOutput().splitlines()[0], exe=False, - endstr=' = 0') - - # Use the '-v' option to do verbose listing of the watchpoint. - # The hit count should be 0 initially. - self.expect("watchpoint list -v", - substrs=['hit_count = 0']) - - self.runCmd("process continue") - - # We should be stopped again due to the watchpoint (write type), but - # only once. The stop reason of the thread should be watchpoint. - self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT, - substrs=['stopped', - 'stop reason = watchpoint', - self.violating_func]) - - # Switch to the thread stopped due to watchpoint and issue some - # commands. - self.switch_to_thread_with_stop_reason(lldb.eStopReasonWatchpoint) - self.runCmd("thread backtrace") - self.runCmd("expr unsigned val = g_char_ptr[7]; val") - self.expect(self.res.GetOutput().splitlines()[0], exe=False, - endstr=' = 99') - - # Use the '-v' option to do verbose listing of the watchpoint. - # The hit count should now be the same as the number of threads that - # stopped on a watchpoint. - threads = lldbutil.get_stopped_threads( - self.process(), lldb.eStopReasonWatchpoint) - self.expect("watchpoint list -v", - substrs=['hit_count = %d' % len(threads)]) - - self.runCmd("thread backtrace all") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_set_command/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_set_command/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_set_command/main.cpp @@ -1,115 +0,0 @@ -//===-- main.cpp ------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include -#include -#include -#include - -std::condition_variable g_condition_variable; -std::mutex g_mutex; -int g_count; - -char *g_char_ptr = nullptr; - -void -barrier_wait() -{ - std::unique_lock lock{g_mutex}; - if (--g_count > 0) - g_condition_variable.wait(lock); - else - g_condition_variable.notify_all(); -} - -void -do_bad_thing_with_location(unsigned index, char *char_ptr, char new_val) -{ - unsigned what = new_val; - printf("new value written to array(%p) and index(%u) = %u\n", char_ptr, index, what); - char_ptr[index] = new_val; -} - -uint32_t -access_pool (bool flag = false) -{ - static std::mutex g_access_mutex; - static unsigned idx = 0; // Well-behaving thread only writes into indexs from 0..6. - if (!flag) - g_access_mutex.lock(); - - // idx valid range is [0, 6]. - if (idx > 6) - idx = 0; - - if (flag) - { - // Write into a forbidden area. - do_bad_thing_with_location(7, g_char_ptr, 99); - } - - unsigned index = idx++; - - if (!flag) - g_access_mutex.unlock(); - return g_char_ptr[index]; -} - -void -thread_func (uint32_t thread_index) -{ - printf ("%s (thread index = %u) startng...\n", __FUNCTION__, thread_index); - - barrier_wait(); - - uint32_t count = 0; - uint32_t val; - while (count++ < 15) - { - printf ("%s (thread = %u) sleeping for 1 second...\n", __FUNCTION__, thread_index); - std::this_thread::sleep_for(std::chrono::seconds(1)); - - if (count < 7) - val = access_pool (); - else - val = access_pool (true); - - printf ("%s (thread = %u) after sleep access_pool returns %d (count=%d)...\n", __FUNCTION__, thread_index, val, count); - } - printf ("%s (thread index = %u) exiting...\n", __FUNCTION__, thread_index); -} - - -int main (int argc, char const *argv[]) -{ - g_count = 4; - std::thread threads[3]; - - g_char_ptr = new char[10]{}; - - // Create 3 threads - for (auto &thread : threads) - thread = std::thread{thread_func, std::distance(threads, &thread)}; - - struct { - int a; - int b; - int c; - } MyAggregateDataType; - - printf ("Before turning all three threads loose...\n"); // Set break point at this line. - barrier_wait(); - - // Join all of our threads - for (auto &thread : threads) - thread.join(); - - delete[] g_char_ptr; - - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_size/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_size/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_size/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_size/TestWatchpointSizes.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_size/TestWatchpointSizes.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_size/TestWatchpointSizes.py @@ -1,132 +0,0 @@ -""" -Test watchpoint size cases (1-byte, 2-byte, 4-byte). -Make sure we can watch all bytes, words or double words individually -when they are packed in a 8-byte region. - -""" - -from __future__ import print_function - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class WatchpointSizeTestCase(TestBase): - NO_DEBUG_INFO_TESTCASE = True - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - - # Source filename. - self.source = 'main.c' - - # Output filename. - self.exe_name = self.getBuildArtifact("a.out") - self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} - - @expectedFailureAll( - oslist=["windows"], - bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") - # Read-write watchpoints not supported on SystemZ - @expectedFailureAll(archs=['s390x']) - def test_byte_size_watchpoints_with_byte_selection(self): - """Test to selectively watch different bytes in a 8-byte array.""" - self.run_watchpoint_size_test('byteArray', 8, '1') - - @expectedFailureAll( - oslist=["windows"], - bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") - # Read-write watchpoints not supported on SystemZ - @expectedFailureAll(archs=['s390x']) - def test_two_byte_watchpoints_with_word_selection(self): - """Test to selectively watch different words in an 8-byte word array.""" - self.run_watchpoint_size_test('wordArray', 4, '2') - - @expectedFailureAll( - oslist=["windows"], - bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") - # Read-write watchpoints not supported on SystemZ - @expectedFailureAll(archs=['s390x']) - def test_four_byte_watchpoints_with_dword_selection(self): - """Test to selectively watch two double words in an 8-byte dword array.""" - self.run_watchpoint_size_test('dwordArray', 2, '4') - - def run_watchpoint_size_test(self, arrayName, array_size, watchsize): - self.build(dictionary=self.d) - self.setTearDownCleanup(dictionary=self.d) - - exe = self.getBuildArtifact(self.exe_name) - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # Detect line number after which we are going to increment arrayName. - loc_line = line_number('main.c', '// About to write ' + arrayName) - - # Set a breakpoint on the line detected above. - lldbutil.run_break_set_by_file_and_line( - self, "main.c", loc_line, num_expected_locations=1, loc_exact=True) - - # Run the program. - self.runCmd("run", RUN_SUCCEEDED) - - for i in range(array_size): - # We should be stopped again due to the breakpoint. - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', 'stop reason = breakpoint']) - - # Set a read_write type watchpoint arrayName - watch_loc = arrayName + "[" + str(i) + "]" - self.expect( - "watchpoint set variable -w read_write " + - watch_loc, - WATCHPOINT_CREATED, - substrs=[ - 'Watchpoint created', - 'size = ' + - watchsize, - 'type = rw']) - - # Use the '-v' option to do verbose listing of the watchpoint. - # The hit count should be 0 initially. - self.expect("watchpoint list -v", substrs=['hit_count = 0']) - - self.runCmd("process continue") - - # We should be stopped due to the watchpoint. - # The stop reason of the thread should be watchpoint. - self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT, - substrs=['stopped', 'stop reason = watchpoint']) - - # Use the '-v' option to do verbose listing of the watchpoint. - # The hit count should now be 1. - self.expect("watchpoint list -v", - substrs=['hit_count = 1']) - - self.runCmd("process continue") - - # We should be stopped due to the watchpoint. - # The stop reason of the thread should be watchpoint. - self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT, - substrs=['stopped', 'stop reason = watchpoint']) - - # Use the '-v' option to do verbose listing of the watchpoint. - # The hit count should now be 1. - # Verify hit_count has been updated after value has been read. - self.expect("watchpoint list -v", - substrs=['hit_count = 2']) - - # Delete the watchpoint immediately, but set auto-confirm to true - # first. - self.runCmd("settings set auto-confirm true") - self.expect( - "watchpoint delete", - substrs=['All watchpoints removed.']) - # Restore the original setting of auto-confirm. - self.runCmd("settings clear auto-confirm") - - self.runCmd("process continue") Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_size/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_size/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_size/main.c @@ -1,65 +0,0 @@ -//===-- main.c --------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -#include -#include - -uint64_t pad0 = 0; -uint8_t byteArray[8] = {0}; -uint64_t pad1 = 0; -uint16_t wordArray[4] = {0}; -uint64_t pad2 = 0; -uint32_t dwordArray[2] = {0}; - -int main(int argc, char** argv) { - - int i; - uint8_t localByte; - uint16_t localWord; - uint32_t localDword; - - for (i = 0; i < 8; i++) - { - printf("About to write byteArray[%d] ...\n", i); // About to write byteArray - pad0++; - byteArray[i] = 7; - pad1++; - localByte = byteArray[i]; // Here onwards we should'nt be stopped in loop - byteArray[i]++; - localByte = byteArray[i]; - } - - pad0 = 0; - pad1 = 0; - - for (i = 0; i < 4; i++) - { - printf("About to write wordArray[%d] ...\n", i); // About to write wordArray - pad0++; - wordArray[i] = 7; - pad1++; - localWord = wordArray[i]; // Here onwards we should'nt be stopped in loop - wordArray[i]++; - localWord = wordArray[i]; - } - - pad0 = 0; - pad1 = 0; - - for (i = 0; i < 2; i++) - { - printf("About to write dwordArray[%d] ...\n", i); // About to write dwordArray - pad0++; - dwordArray[i] = 7; - pad1++; - localDword = dwordArray[i]; // Here onwards we shouldn't be stopped in loop - dwordArray[i]++; - localDword = dwordArray[i]; - } - - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/help/TestHelp.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/help/TestHelp.py +++ lldb/trunk/packages/Python/lldbsuite/test/help/TestHelp.py @@ -1,266 +0,0 @@ -""" -Test some lldb help commands. - -See also CommandInterpreter::OutputFormattedHelpText(). -""" - -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 HelpCommandTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @no_debug_info_test - def test_simplehelp(self): - """A simple test of 'help' command and its output.""" - self.expect("help", - startstr='Debugger commands:') - - self.expect("help -a", matching=False, - substrs=['next']) - - self.expect("help", matching=True, - substrs=['next']) - - @no_debug_info_test - def test_help_on_help(self): - """Testing the help on the help facility.""" - self.expect("help help", matching=True, - substrs=['--hide-aliases', - '--hide-user-commands']) - - @no_debug_info_test - def version_number_string(self): - """Helper function to find the version number string of lldb.""" - plist = os.path.join( - os.environ["LLDB_SRC"], - "resources", - "LLDB-Info.plist") - try: - CFBundleVersionSegFound = False - with open(plist, 'r') as f: - for line in f: - if CFBundleVersionSegFound: - version_line = line.strip() - import re - m = re.match("(.*)", version_line) - if m: - version = m.group(1) - return version - else: - # Unsuccessful, let's juts break out of the for - # loop. - break - - if line.find("CFBundleVersion") != -1: - # Found our match. The next line contains our version - # string, for example: - # - # 38 - CFBundleVersionSegFound = True - - except: - # Just fallthrough... - import traceback - traceback.print_exc() - - # Use None to signify that we are not able to grok the version number. - return None - - @no_debug_info_test - def test_help_arch(self): - """Test 'help arch' which should list of supported architectures.""" - self.expect("help arch", - substrs=['arm', 'x86_64', 'i386']) - - @no_debug_info_test - def test_help_version(self): - """Test 'help version' and 'version' commands.""" - self.expect("help version", - substrs=['Show the LLDB debugger version.']) - import re - version_str = self.version_number_string() - match = re.match('[0-9]+', version_str) - search_regexp = ['lldb( version|-' + (version_str if match else '[0-9]+') + ').*\n'] - - self.expect("version", - patterns=search_regexp) - - @no_debug_info_test - def test_help_should_not_crash_lldb(self): - """Command 'help disasm' should not crash lldb.""" - self.runCmd("help disasm", check=False) - self.runCmd("help unsigned-integer") - - @no_debug_info_test - def test_help_should_not_hang_emacsshell(self): - """Command 'settings set term-width 0' should not hang the help command.""" - self.expect( - "settings set term-width 0", - COMMAND_FAILED_AS_EXPECTED, - error=True, - substrs=['error: 0 is out of range, valid values must be between']) - # self.runCmd("settings set term-width 0") - self.expect("help", - startstr='Debugger commands:') - - @no_debug_info_test - def test_help_breakpoint_set(self): - """Test that 'help breakpoint set' does not print out redundant lines of: - 'breakpoint set [-s ] ...'.""" - self.expect("help breakpoint set", matching=False, - substrs=['breakpoint set [-s ]']) - - @no_debug_info_test - def test_help_image_dump_symtab_should_not_crash(self): - """Command 'help image dump symtab' should not crash lldb.""" - # 'image' is an alias for 'target modules'. - self.expect("help image dump symtab", - substrs=['dump symtab', - 'sort-order']) - - @no_debug_info_test - def test_help_image_du_sym_is_ambiguous(self): - """Command 'help image du sym' is ambiguous and spits out the list of candidates.""" - self.expect("help image du sym", - COMMAND_FAILED_AS_EXPECTED, error=True, - substrs=['error: ambiguous command image du sym', - 'symfile', - 'symtab']) - - @no_debug_info_test - def test_help_image_du_line_should_work(self): - """Command 'help image du line-table' is not ambiguous and should work.""" - # 'image' is an alias for 'target modules'. - self.expect("help image du line", substrs=[ - 'Dump the line table for one or more compilation units']) - - @no_debug_info_test - def test_help_target_variable_syntax(self): - """Command 'help target variable' should display ...""" - self.expect("help target variable", - substrs=[' [ [...]]']) - - @no_debug_info_test - def test_help_watchpoint_and_its_args(self): - """Command 'help watchpoint', 'help watchpt-id', and 'help watchpt-id-list' should work.""" - self.expect("help watchpoint", - substrs=['delete', 'disable', 'enable', 'list']) - self.expect("help watchpt-id", - substrs=['']) - self.expect("help watchpt-id-list", - substrs=['']) - - @no_debug_info_test - def test_help_watchpoint_set(self): - """Test that 'help watchpoint set' prints out 'expression' and 'variable' - as the possible subcommands.""" - self.expect("help watchpoint set", - substrs=['The following subcommands are supported:'], - patterns=['expression +--', - 'variable +--']) - - @no_debug_info_test - def test_help_po_hides_options(self): - """Test that 'help po' does not show all the options for expression""" - self.expect( - "help po", - substrs=[ - '--show-all-children', - '--object-description'], - matching=False) - - @no_debug_info_test - def test_help_run_hides_options(self): - """Test that 'help run' does not show all the options for process launch""" - self.expect("help run", - substrs=['--arch', '--environment'], matching=False) - - @no_debug_info_test - def test_help_next_shows_options(self): - """Test that 'help next' shows all the options for thread step-over""" - self.expect("help next", - substrs=['--python-class', '--run-mode'], matching=True) - - @no_debug_info_test - def test_help_provides_alternatives(self): - """Test that help on commands that don't exist provides information on additional help avenues""" - self.expect( - "help thisisnotadebuggercommand", - substrs=[ - "'thisisnotadebuggercommand' is not a known command.", - "Try 'help' to see a current list of commands.", - "Try 'apropos thisisnotadebuggercommand' for a list of related commands.", - "Try 'type lookup thisisnotadebuggercommand' for information on types, methods, functions, modules, etc."], - error=True) - - self.expect( - "help process thisisnotadebuggercommand", - substrs=[ - "'process thisisnotadebuggercommand' is not a known command.", - "Try 'help' to see a current list of commands.", - "Try 'apropos thisisnotadebuggercommand' for a list of related commands.", - "Try 'type lookup thisisnotadebuggercommand' for information on types, methods, functions, modules, etc."]) - - @no_debug_info_test - def test_custom_help_alias(self): - """Test that aliases pick up custom help text.""" - def cleanup(): - self.runCmd('command unalias afriendlyalias', check=False) - self.runCmd('command unalias averyfriendlyalias', check=False) - - self.addTearDownHook(cleanup) - self.runCmd( - 'command alias --help "I am a friendly alias" -- afriendlyalias help') - self.expect( - "help afriendlyalias", - matching=True, - substrs=['I am a friendly alias']) - self.runCmd( - 'command alias --long-help "I am a very friendly alias" -- averyfriendlyalias help') - self.expect("help averyfriendlyalias", matching=True, - substrs=['I am a very friendly alias']) - @no_debug_info_test - def test_alias_prints_origin(self): - """Test that 'help ' prints the alias origin.""" - def cleanup(): - self.runCmd('command unalias alongaliasname', check=False) - - self.addTearDownHook(cleanup) - self.runCmd('command alias alongaliasname help') - self.expect("help alongaliasna", matching=True, - substrs=["'alongaliasna' is an abbreviation for 'help'"]) - - @no_debug_info_test - def test_hidden_help(self): - self.expect("help -h", - substrs=["_regexp-bt"]) - - @no_debug_info_test - def test_help_ambiguous(self): - self.expect("help g", - substrs=["Help requested with ambiguous command name, possible completions:", - "gdb-remote", "gui"]) - - @no_debug_info_test - def test_help_unknown_flag(self): - self.expect("help -z", error=True, - substrs=["unknown or ambiguous option"]) - - @no_debug_info_test - def test_help_format_output(self): - """Test that help output reaches TerminalWidth.""" - self.runCmd( - 'settings set term-width 108') - self.expect( - "help format", - matching=True, - substrs=[' -- One of the format names']) Index: lldb/trunk/packages/Python/lldbsuite/test/logging/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/logging/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/logging/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/logging/TestLogging.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/logging/TestLogging.py +++ lldb/trunk/packages/Python/lldbsuite/test/logging/TestLogging.py @@ -1,93 +0,0 @@ -""" -Test lldb logging. This test just makes sure logging doesn't crash, and produces some output. -""" - -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 LogTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - NO_DEBUG_INFO_TESTCASE = True - - def setUp(self): - super(LogTestCase, self).setUp() - self.log_file = self.getBuildArtifact("log-file.txt") - - def test(self): - self.build() - exe = self.getBuildArtifact("a.out") - self.expect("file " + exe, - patterns=["Current executable set to .*a.out"]) - - log_file = os.path.join(self.getBuildDir(), "lldb-commands-log.txt") - - if (os.path.exists(log_file)): - os.remove(log_file) - - # By default, Debugger::EnableLog() will set log options to - # PREPEND_THREAD_NAME + OPTION_THREADSAFE. We don't want the - # threadnames here, so we enable just threadsafe (-t). - self.runCmd("log enable -t -f '%s' lldb commands" % (log_file)) - - self.runCmd("command alias bp breakpoint") - - self.runCmd("bp set -n main") - - self.runCmd("bp l") - - self.runCmd("log disable lldb") - - self.assertTrue(os.path.isfile(log_file)) - - f = open(log_file) - log_lines = f.readlines() - f.close() - os.remove(log_file) - - self.assertGreater( - len(log_lines), - 0, - "Something was written to the log file.") - - # Check that lldb truncates its log files - def test_log_truncate(self): - # put something in our log file - with open(self.log_file, "w") as f: - for i in range(1, 1000): - f.write("bacon\n") - - self.runCmd("log enable -t -f '%s' lldb commands" % self.log_file) - self.runCmd("help log") - self.runCmd("log disable lldb") - - self.assertTrue(os.path.isfile(self.log_file)) - with open(self.log_file, "r") as f: - contents = f.read() - - # check that it got removed - self.assertEquals(contents.find("bacon"), -1) - - # Check that lldb can append to a log file - def test_log_append(self): - # put something in our log file - with open(self.log_file, "w") as f: - f.write("bacon\n") - - self.runCmd( "log enable -t -a -f '%s' lldb commands" % self.log_file) - self.runCmd("help log") - self.runCmd("log disable lldb") - - self.assertTrue(os.path.isfile(self.log_file)) - with open(self.log_file, "r") as f: - contents = f.read() - - # check that it is still there - self.assertEquals(contents.find("bacon"), 0) Index: lldb/trunk/packages/Python/lldbsuite/test/logging/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/logging/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/logging/main.cpp @@ -1,61 +0,0 @@ -//===-- main.cpp ------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include -#include -#include -#include - -int -product (int x, int y) -{ - int result = x * y; - return result; -} - -int -sum (int a, int b) -{ - int result = a + b; - return result; -} - -int -strange_max (int m, int n) -{ - if (m > n) - return m; - else if (n > m) - return n; - else - return 0; -} - -int -foo (int i, int j) -{ - if (strange_max (i, j) == i) - return product (i, j); - else if (strange_max (i, j) == j) - return sum (i, j); - else - return product (sum (i, i), sum (j, j)); -} - -int -main(int argc, char const *argv[]) -{ - - int array[3]; - - array[0] = foo (1238, 78392); - array[1] = foo (379265, 23674); - array[2] = foo (872934, 234); - - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/quit/TestQuit.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/quit/TestQuit.py +++ lldb/trunk/packages/Python/lldbsuite/test/quit/TestQuit.py @@ -1,32 +0,0 @@ -""" -Test lldb's quit command. -""" - -from __future__ import print_function - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class QuitCommandTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @no_debug_info_test - def test_quit_exit_code_disallow(self): - self.ci.AllowExitCodeOnQuit(False) - self.expect( - "quit 20", - substrs=[ - "error: The current driver doesn't allow custom exit codes for the quit command"], - error=True) - self.assertFalse(self.ci.HasCustomQuitExitCode()) - - @no_debug_info_test - def test_quit_exit_code_allow(self): - self.ci.AllowExitCodeOnQuit(True) - self.runCmd("quit 10", check=False) - self.assertTrue(self.ci.HasCustomQuitExitCode()) - self.assertEqual(self.ci.GetQuitStatus(), 10) Index: lldb/trunk/packages/Python/lldbsuite/test/settings/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/settings/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/settings/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/settings/TestSettings.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/settings/TestSettings.py +++ lldb/trunk/packages/Python/lldbsuite/test/settings/TestSettings.py @@ -1,602 +0,0 @@ -""" -Test lldb settings command. -""" - -from __future__ import print_function - - -import os -import re -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class SettingsCommandTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - NO_DEBUG_INFO_TESTCASE = True - - def test_apropos_should_also_search_settings_description(self): - """Test that 'apropos' command should also search descriptions for the settings variables.""" - - self.expect("apropos 'environment variable'", - substrs=["target.env-vars", - "environment variables", - "executable's environment"]) - - def test_append_target_env_vars(self): - """Test that 'append target.run-args' works.""" - # Append the env-vars. - self.runCmd('settings append target.env-vars MY_ENV_VAR=YES') - # And add hooks to restore the settings during tearDown(). - self.addTearDownHook( - lambda: self.runCmd("settings clear target.env-vars")) - - # Check it immediately! - self.expect('settings show target.env-vars', - substrs=['MY_ENV_VAR=YES']) - - def test_insert_before_and_after_target_run_args(self): - """Test that 'insert-before/after target.run-args' works.""" - # Set the run-args first. - self.runCmd('settings set target.run-args a b c') - # And add hooks to restore the settings during tearDown(). - self.addTearDownHook( - lambda: self.runCmd("settings clear target.run-args")) - - # Now insert-before the index-0 element with '__a__'. - self.runCmd('settings insert-before target.run-args 0 __a__') - # And insert-after the index-1 element with '__A__'. - self.runCmd('settings insert-after target.run-args 1 __A__') - # Check it immediately! - self.expect('settings show target.run-args', - substrs=['target.run-args', - '[0]: "__a__"', - '[1]: "a"', - '[2]: "__A__"', - '[3]: "b"', - '[4]: "c"']) - - def test_replace_target_run_args(self): - """Test that 'replace target.run-args' works.""" - # Set the run-args and then replace the index-0 element. - self.runCmd('settings set target.run-args a b c') - # And add hooks to restore the settings during tearDown(). - self.addTearDownHook( - lambda: self.runCmd("settings clear target.run-args")) - - # Now replace the index-0 element with 'A', instead. - self.runCmd('settings replace target.run-args 0 A') - # Check it immediately! - self.expect('settings show target.run-args', - substrs=['target.run-args (arguments) =', - '[0]: "A"', - '[1]: "b"', - '[2]: "c"']) - - def test_set_prompt(self): - """Test that 'set prompt' actually changes the prompt.""" - - # Set prompt to 'lldb2'. - self.runCmd("settings set prompt 'lldb2 '") - - # Immediately test the setting. - self.expect("settings show prompt", SETTING_MSG("prompt"), - startstr='prompt (string) = "lldb2 "') - - # The overall display should also reflect the new setting. - self.expect("settings show", SETTING_MSG("prompt"), - substrs=['prompt (string) = "lldb2 "']) - - # Use '-r' option to reset to the original default prompt. - self.runCmd("settings clear prompt") - - def test_set_term_width(self): - """Test that 'set term-width' actually changes the term-width.""" - - self.runCmd("settings set term-width 70") - - # Immediately test the setting. - self.expect("settings show term-width", SETTING_MSG("term-width"), - startstr="term-width (int) = 70") - - # The overall display should also reflect the new setting. - self.expect("settings show", SETTING_MSG("term-width"), - substrs=["term-width (int) = 70"]) - - # rdar://problem/10712130 - def test_set_frame_format(self): - """Test that 'set frame-format' with a backtick char in the format string works as well as fullpath.""" - self.build() - - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - def cleanup(): - self.runCmd( - "settings set frame-format %s" % - self.format_string, check=False) - - # Execute the cleanup function during test case tear down. - self.addTearDownHook(cleanup) - - self.runCmd("settings show frame-format") - m = re.match( - '^frame-format \(format-string\) = "(.*)\"$', - self.res.GetOutput()) - self.assertTrue(m, "Bad settings string") - self.format_string = m.group(1) - - # Change the default format to print function.name rather than - # function.name-with-args - format_string = "frame #${frame.index}: ${frame.pc}{ ${module.file.basename}\`${function.name}{${function.pc-offset}}}{ at ${line.file.fullpath}:${line.number}}{, lang=${language}}\n" - self.runCmd("settings set frame-format %s" % format_string) - - # Immediately test the setting. - self.expect("settings show frame-format", SETTING_MSG("frame-format"), - substrs=[format_string]) - - self.runCmd("breakpoint set -n main") - self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()), - RUN_SUCCEEDED) - self.expect("thread backtrace", - substrs=["`main", self.getSourceDir()]) - - def test_set_auto_confirm(self): - """Test that after 'set auto-confirm true', manual confirmation should not kick in.""" - self.build() - - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - self.runCmd("settings set auto-confirm true") - - # Immediately test the setting. - self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"), - startstr="auto-confirm (boolean) = true") - - # Now 'breakpoint delete' should just work fine without confirmation - # prompt from the command interpreter. - self.runCmd("breakpoint set -n main") - self.expect("breakpoint delete", - startstr="All breakpoints removed") - - # Restore the original setting of auto-confirm. - self.runCmd("settings clear auto-confirm") - self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"), - startstr="auto-confirm (boolean) = false") - - @skipIf(archs=no_match(['x86_64', 'i386', 'i686'])) - def test_disassembler_settings(self): - """Test that user options for the disassembler take effect.""" - self.build() - - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # AT&T syntax - self.runCmd("settings set target.x86-disassembly-flavor att") - self.runCmd("settings set target.use-hex-immediates false") - self.expect("disassemble -n numberfn", - substrs=["$90"]) - self.runCmd("settings set target.use-hex-immediates true") - self.runCmd("settings set target.hex-immediate-style c") - self.expect("disassemble -n numberfn", - substrs=["$0x5a"]) - self.runCmd("settings set target.hex-immediate-style asm") - self.expect("disassemble -n numberfn", - substrs=["$5ah"]) - - # Intel syntax - self.runCmd("settings set target.x86-disassembly-flavor intel") - self.runCmd("settings set target.use-hex-immediates false") - self.expect("disassemble -n numberfn", - substrs=["90"]) - self.runCmd("settings set target.use-hex-immediates true") - self.runCmd("settings set target.hex-immediate-style c") - self.expect("disassemble -n numberfn", - substrs=["0x5a"]) - self.runCmd("settings set target.hex-immediate-style asm") - self.expect("disassemble -n numberfn", - substrs=["5ah"]) - - @skipIfDarwinEmbedded # debugserver on ios etc can't write files - def test_run_args_and_env_vars(self): - """Test that run-args and env-vars are passed to the launched process.""" - self.build() - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # Set the run-args and the env-vars. - # And add hooks to restore the settings during tearDown(). - self.runCmd('settings set target.run-args A B C') - self.addTearDownHook( - lambda: self.runCmd("settings clear target.run-args")) - self.runCmd('settings set target.env-vars ["MY_ENV_VAR"]=YES') - self.addTearDownHook( - lambda: self.runCmd("settings clear target.env-vars")) - - self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()), - RUN_SUCCEEDED) - - # Read the output file produced by running the program. - output = lldbutil.read_file_from_process_wd(self, "output2.txt") - - self.expect( - output, - exe=False, - substrs=[ - "argv[1] matches", - "argv[2] matches", - "argv[3] matches", - "Environment variable 'MY_ENV_VAR' successfully passed."]) - - @skipIfRemote # it doesn't make sense to send host env to remote target - def test_pass_host_env_vars(self): - """Test that the host env vars are passed to the launched process.""" - self.build() - - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # By default, inherit-env is 'true'. - self.expect( - 'settings show target.inherit-env', - "Default inherit-env is 'true'", - startstr="target.inherit-env (boolean) = true") - - # Set some host environment variables now. - os.environ["MY_HOST_ENV_VAR1"] = "VAR1" - os.environ["MY_HOST_ENV_VAR2"] = "VAR2" - - # This is the function to unset the two env variables set above. - def unset_env_variables(): - os.environ.pop("MY_HOST_ENV_VAR1") - os.environ.pop("MY_HOST_ENV_VAR2") - - self.addTearDownHook(unset_env_variables) - self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()), - RUN_SUCCEEDED) - - # Read the output file produced by running the program. - output = lldbutil.read_file_from_process_wd(self, "output1.txt") - - self.expect( - output, - exe=False, - substrs=[ - "The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.", - "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."]) - - @skipIfDarwinEmbedded # debugserver on ios etc can't write files - def test_set_error_output_path(self): - """Test that setting target.error/output-path for the launched process works.""" - self.build() - - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # Set the error-path and output-path and verify both are set. - self.runCmd("settings set target.error-path '{0}'".format( - lldbutil.append_to_process_working_directory(self, "stderr.txt"))) - self.runCmd("settings set target.output-path '{0}".format( - lldbutil.append_to_process_working_directory(self, "stdout.txt"))) - # And add hooks to restore the original settings during tearDown(). - self.addTearDownHook( - lambda: self.runCmd("settings clear target.output-path")) - self.addTearDownHook( - lambda: self.runCmd("settings clear target.error-path")) - - self.expect("settings show target.error-path", - SETTING_MSG("target.error-path"), - substrs=['target.error-path (file)', 'stderr.txt"']) - - self.expect("settings show target.output-path", - SETTING_MSG("target.output-path"), - substrs=['target.output-path (file)', 'stdout.txt"']) - - self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()), - RUN_SUCCEEDED) - - output = lldbutil.read_file_from_process_wd(self, "stderr.txt") - message = "This message should go to standard error." - if lldbplatformutil.hasChattyStderr(self): - self.expect(output, exe=False, substrs=[message]) - else: - self.expect(output, exe=False, startstr=message) - - output = lldbutil.read_file_from_process_wd(self, "stdout.txt") - self.expect(output, exe=False, - startstr="This message should go to standard out.") - - def test_print_dictionary_setting(self): - self.runCmd("settings clear target.env-vars") - self.runCmd("settings set target.env-vars [\"MY_VAR\"]=some-value") - self.expect("settings show target.env-vars", - substrs=["MY_VAR=some-value"]) - self.runCmd("settings clear target.env-vars") - - def test_print_array_setting(self): - self.runCmd("settings clear target.run-args") - self.runCmd("settings set target.run-args gobbledy-gook") - self.expect("settings show target.run-args", - substrs=['[0]: "gobbledy-gook"']) - self.runCmd("settings clear target.run-args") - - def test_settings_with_quotes(self): - self.runCmd("settings clear target.run-args") - self.runCmd("settings set target.run-args a b c") - self.expect("settings show target.run-args", - substrs=['[0]: "a"', - '[1]: "b"', - '[2]: "c"']) - self.runCmd("settings set target.run-args 'a b c'") - self.expect("settings show target.run-args", - substrs=['[0]: "a b c"']) - self.runCmd("settings clear target.run-args") - self.runCmd("settings clear target.env-vars") - self.runCmd( - 'settings set target.env-vars ["MY_FILE"]="this is a file name with spaces.txt"') - self.expect("settings show target.env-vars", - substrs=['MY_FILE=this is a file name with spaces.txt']) - self.runCmd("settings clear target.env-vars") - # Test and make sure that setting "format-string" settings obeys quotes - # if they are provided - self.runCmd("settings set thread-format 'abc def' ") - self.expect("settings show thread-format", - 'thread-format (format-string) = "abc def"') - self.runCmd('settings set thread-format "abc def" ') - self.expect("settings show thread-format", - 'thread-format (format-string) = "abc def"') - # Make sure when no quotes are provided that we maintain any trailing - # spaces - self.runCmd('settings set thread-format abc def ') - self.expect("settings show thread-format", - 'thread-format (format-string) = "abc def "') - self.runCmd('settings clear thread-format') - - def test_settings_with_trailing_whitespace(self): - - # boolean - # Set to known value - self.runCmd("settings set target.skip-prologue true") - # Set to new value with trailing whitespace - self.runCmd("settings set target.skip-prologue false ") - # Make sure the setting was correctly set to "false" - self.expect( - "settings show target.skip-prologue", - SETTING_MSG("target.skip-prologue"), - startstr="target.skip-prologue (boolean) = false") - self.runCmd("settings clear target.skip-prologue", check=False) - # integer - self.runCmd("settings set term-width 70") # Set to known value - # Set to new value with trailing whitespaces - self.runCmd("settings set term-width 60 \t") - self.expect("settings show term-width", SETTING_MSG("term-width"), - startstr="term-width (int) = 60") - self.runCmd("settings clear term-width", check=False) - # string - self.runCmd("settings set target.arg0 abc") # Set to known value - # Set to new value with trailing whitespaces - self.runCmd("settings set target.arg0 cde\t ") - self.expect("settings show target.arg0", SETTING_MSG("target.arg0"), - startstr='target.arg0 (string) = "cde"') - self.runCmd("settings clear target.arg0", check=False) - # file - path1 = self.getBuildArtifact("path1.txt") - path2 = self.getBuildArtifact("path2.txt") - self.runCmd( - "settings set target.output-path %s" % - path1) # Set to known value - self.expect( - "settings show target.output-path", - SETTING_MSG("target.output-path"), - startstr='target.output-path (file) = ', - substrs=[path1]) - self.runCmd("settings set target.output-path %s " % - path2) # Set to new value with trailing whitespaces - self.expect( - "settings show target.output-path", - SETTING_MSG("target.output-path"), - startstr='target.output-path (file) = ', - substrs=[path2]) - self.runCmd("settings clear target.output-path", check=False) - # enum - # Set to known value - self.runCmd("settings set stop-disassembly-display never") - # Set to new value with trailing whitespaces - self.runCmd("settings set stop-disassembly-display always ") - self.expect( - "settings show stop-disassembly-display", - SETTING_MSG("stop-disassembly-display"), - startstr='stop-disassembly-display (enum) = always') - self.runCmd("settings clear stop-disassembly-display", check=False) - # language - # Set to known value - self.runCmd("settings set target.language c89") - # Set to new value with trailing whitespace - self.runCmd("settings set target.language c11 ") - self.expect( - "settings show target.language", - SETTING_MSG("target.language"), - startstr="target.language (language) = c11") - self.runCmd("settings clear target.language", check=False) - # arguments - self.runCmd("settings set target.run-args 1 2 3") # Set to known value - # Set to new value with trailing whitespaces - self.runCmd("settings set target.run-args 3 4 5 ") - self.expect( - "settings show target.run-args", - SETTING_MSG("target.run-args"), - substrs=[ - 'target.run-args (arguments) =', - '[0]: "3"', - '[1]: "4"', - '[2]: "5"']) - self.runCmd("settings set target.run-args 1 2 3") # Set to known value - # Set to new value with trailing whitespaces - self.runCmd("settings set target.run-args 3 \ \ ") - self.expect( - "settings show target.run-args", - SETTING_MSG("target.run-args"), - substrs=[ - 'target.run-args (arguments) =', - '[0]: "3"', - '[1]: " "', - '[2]: " "']) - self.runCmd("settings clear target.run-args", check=False) - # dictionaries - self.runCmd("settings clear target.env-vars") # Set to known value - # Set to new value with trailing whitespaces - self.runCmd("settings set target.env-vars A=B C=D\t ") - self.expect( - "settings show target.env-vars", - SETTING_MSG("target.env-vars"), - substrs=[ - 'target.env-vars (dictionary of strings) =', - 'A=B', - 'C=D']) - self.runCmd("settings clear target.env-vars", check=False) - # regex - # Set to known value - self.runCmd("settings clear target.process.thread.step-avoid-regexp") - # Set to new value with trailing whitespaces - self.runCmd( - "settings set target.process.thread.step-avoid-regexp foo\\ ") - self.expect( - "settings show target.process.thread.step-avoid-regexp", - SETTING_MSG("target.process.thread.step-avoid-regexp"), - substrs=['target.process.thread.step-avoid-regexp (regex) = foo\\ ']) - self.runCmd( - "settings clear target.process.thread.step-avoid-regexp", - check=False) - # format-string - self.runCmd("settings clear disassembly-format") # Set to known value - # Set to new value with trailing whitespaces - self.runCmd("settings set disassembly-format foo ") - self.expect("settings show disassembly-format", - SETTING_MSG("disassembly-format"), - substrs=['disassembly-format (format-string) = "foo "']) - self.runCmd("settings clear disassembly-format", check=False) - - def test_settings_list(self): - # List settings (and optionally test the filter to only show 'target' settings). - self.expect("settings list target", substrs=["language", "arg0", "detach-on-error"]) - self.expect("settings list target", matching=False, substrs=["packet-timeout"]) - self.expect("settings list", substrs=["language", "arg0", "detach-on-error", "packet-timeout"]) - - def test_settings_remove_single(self): - # Set some environment variables and use 'remove' to delete them. - self.runCmd("settings set target.env-vars a=b c=d") - self.expect("settings show target.env-vars", substrs=["a=b", "c=d"]) - self.runCmd("settings remove target.env-vars a") - self.expect("settings show target.env-vars", matching=False, substrs=["a=b"]) - self.expect("settings show target.env-vars", substrs=["c=d"]) - self.runCmd("settings remove target.env-vars c") - self.expect("settings show target.env-vars", matching=False, substrs=["a=b", "c=d"]) - - def test_settings_remove_multiple(self): - self.runCmd("settings set target.env-vars a=b c=d e=f") - self.expect("settings show target.env-vars", substrs=["a=b", "c=d", "e=f"]) - self.runCmd("settings remove target.env-vars a e") - self.expect("settings show target.env-vars", matching=False, substrs=["a=b", "e=f"]) - self.expect("settings show target.env-vars", substrs=["c=d"]) - - def test_settings_remove_nonexistent_value(self): - self.expect("settings remove target.env-vars doesntexist", error=True, - substrs=["no value found named 'doesntexist'"]) - - def test_settings_remove_nonexistent_settings(self): - self.expect("settings remove doesntexist alsodoesntexist", error=True, - substrs=["error: invalid value path 'doesntexist'"]) - - def test_settings_remove_missing_arg(self): - self.expect("settings remove", error=True, - substrs=["'settings remove' takes an array or dictionary item, or"]) - - def test_settings_remove_empty_arg(self): - self.expect("settings remove ''", error=True, - substrs=["'settings remove' command requires a valid variable name"]) - - def test_all_settings_exist(self): - self.expect("settings show", - substrs=["auto-confirm", - "frame-format", - "notify-void", - "prompt", - "script-lang", - "stop-disassembly-count", - "stop-disassembly-display", - "stop-line-count-after", - "stop-line-count-before", - "stop-show-column", - "term-width", - "thread-format", - "use-external-editor", - "target.default-arch", - "target.move-to-nearest-code", - "target.expr-prefix", - "target.language", - "target.prefer-dynamic-value", - "target.enable-synthetic-value", - "target.skip-prologue", - "target.source-map", - "target.exec-search-paths", - "target.max-children-count", - "target.max-string-summary-length", - "target.breakpoints-use-platform-avoid-list", - "target.run-args", - "target.env-vars", - "target.inherit-env", - "target.input-path", - "target.output-path", - "target.error-path", - "target.disable-aslr", - "target.disable-stdio", - "target.x86-disassembly-flavor", - "target.use-hex-immediates", - "target.hex-immediate-style", - "target.process.disable-memory-cache", - "target.process.extra-startup-command", - "target.process.thread.step-avoid-regexp", - "target.process.thread.trace-thread"]) - - # settings under an ".experimental" domain should have two properties: - # 1. If the name does not exist with "experimental" in the name path, - # the name lookup should try to find it without "experimental". So - # a previously-experimental setting that has been promoted to a - # "real" setting will still be set by the original name. - # 2. Changing a setting with .experimental., name, where the setting - # does not exist either with ".experimental." or without, should - # not generate an error. So if an experimental setting is removed, - # people who may have that in their ~/.lldbinit files should not see - # any errors. - def test_experimental_settings(self): - cmdinterp = self.dbg.GetCommandInterpreter() - result = lldb.SBCommandReturnObject() - - # Set target.arg0 to a known value, check that we can retrieve it via - # the actual name and via .experimental. - self.expect('settings set target.arg0 first-value') - self.expect('settings show target.arg0', substrs=['first-value']) - self.expect('settings show target.experimental.arg0', substrs=['first-value'], error=False) - - # Set target.arg0 to a new value via a target.experimental.arg0 name, - # verify that we can read it back via both .experimental., and not. - self.expect('settings set target.experimental.arg0 second-value', error=False) - self.expect('settings show target.arg0', substrs=['second-value']) - self.expect('settings show target.experimental.arg0', substrs=['second-value'], error=False) - - # showing & setting an undefined .experimental. setting should generate no errors. - self.expect('settings show target.experimental.setting-which-does-not-exist', patterns=['^\s$'], error=False) - self.expect('settings set target.experimental.setting-which-does-not-exist true', error=False) - - # A domain component before .experimental. which does not exist should give an error - # But the code does not yet do that. - # self.expect('settings set target.setting-which-does-not-exist.experimental.arg0 true', error=True) - - # finally, confirm that trying to set a setting that does not exist still fails. - # (SHOWING a setting that does not exist does not currently yield an error.) - self.expect('settings set target.setting-which-does-not-exist true', error=True) Index: lldb/trunk/packages/Python/lldbsuite/test/settings/main.cpp =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/settings/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/settings/main.cpp @@ -1,74 +0,0 @@ -//===-- main.cpp ------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include -#include -#include -#include - -int numberfn() -{ - return 0x5a; -} - -int -main(int argc, char const *argv[]) -{ - // The program writes its output to the following file: - // - // o "output1.txt" for test_pass_host_env_vars() test case - // o "output2.txt" for test_run_args_and_env_vars_with_dsym() test case - // o "output2.txt" for test_run_args_and_env_vars_with_dwarf() test case - std::ofstream outfile; - if (argc == 1) - outfile.open("output1.txt"); - else - outfile.open("output2.txt"); - - for (unsigned i = 0; i < argc; ++i) { - std::string theArg(argv[i]); - if (i == 1 && "A" == theArg) - outfile << "argv[1] matches\n"; - - if (i == 2 && "B" == theArg) - outfile << "argv[2] matches\n"; - - if (i == 3 && "C" == theArg) - outfile << "argv[3] matches\n"; - } - - // For passing environment vars from the debugger to the launched process. - if (::getenv("MY_ENV_VAR")) { - std::string MY_ENV_VAR(getenv("MY_ENV_VAR")); - if ("YES" == MY_ENV_VAR) { - outfile << "Environment variable 'MY_ENV_VAR' successfully passed.\n"; - } - } - - - // For passing host environment vars to the launched process. - if (::getenv("MY_HOST_ENV_VAR1")) { - std::string MY_HOST_ENV_VAR1(getenv("MY_HOST_ENV_VAR1")); - if ("VAR1" == MY_HOST_ENV_VAR1) { - outfile << "The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.\n"; - } - } - - if (::getenv("MY_HOST_ENV_VAR2")) { - std::string MY_HOST_ENV_VAR2(getenv("MY_HOST_ENV_VAR2")); - if ("VAR2" == MY_HOST_ENV_VAR2) { - outfile << "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed.\n"; - } - } - - std::cerr << "This message should go to standard error.\n"; - std::cout << "This message should go to standard out.\n"; - - outfile.close(); - return numberfn(); -} Index: lldb/trunk/packages/Python/lldbsuite/test/settings/quoting/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/settings/quoting/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/settings/quoting/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/settings/quoting/TestQuoting.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/settings/quoting/TestQuoting.py +++ lldb/trunk/packages/Python/lldbsuite/test/settings/quoting/TestQuoting.py @@ -1,94 +0,0 @@ -""" -Test quoting of arguments to lldb commands -""" - -from __future__ import print_function - - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class SettingsCommandTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @classmethod - def classCleanup(cls): - """Cleanup the test byproducts.""" - cls.RemoveTempFile("stdout.txt") - - @no_debug_info_test - def test_no_quote(self): - self.do_test_args("a b c", "a\0b\0c\0") - - @no_debug_info_test - def test_single_quote(self): - self.do_test_args("'a b c'", "a b c\0") - - @no_debug_info_test - def test_double_quote(self): - self.do_test_args('"a b c"', "a b c\0") - - @no_debug_info_test - def test_single_quote_escape(self): - self.do_test_args("'a b\\' c", "a b\\\0c\0") - - @no_debug_info_test - def test_double_quote_escape(self): - self.do_test_args('"a b\\" c"', 'a b" c\0') - - @no_debug_info_test - def test_double_quote_escape2(self): - self.do_test_args('"a b\\\\" c', 'a b\\\0c\0') - - @no_debug_info_test - def test_single_in_double(self): - self.do_test_args('"a\'b"', "a'b\0") - - @no_debug_info_test - def test_double_in_single(self): - self.do_test_args("'a\"b'", 'a"b\0') - - @no_debug_info_test - def test_combined(self): - self.do_test_args('"a b"c\'d e\'', 'a bcd e\0') - - @no_debug_info_test - def test_bare_single(self): - self.do_test_args("a\\'b", "a'b\0") - - @no_debug_info_test - def test_bare_double(self): - self.do_test_args('a\\"b', 'a"b\0') - - def do_test_args(self, args_in, args_out): - """Test argument parsing. Run the program with args_in. The program dumps its arguments - to stdout. Compare the stdout with args_out.""" - self.buildDefault() - - exe = self.getBuildArtifact("a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - local_outfile = self.getBuildArtifact("output.txt") - if lldb.remote_platform: - remote_outfile = "output.txt" # Relative to platform's PWD - else: - remote_outfile = local_outfile - - self.runCmd("process launch -- %s %s" %(remote_outfile, args_in)) - - if lldb.remote_platform: - src_file_spec = lldb.SBFileSpec(remote_outfile, False) - dst_file_spec = lldb.SBFileSpec(local_outfile, True) - lldb.remote_platform.Get(src_file_spec, dst_file_spec) - - with open(local_outfile, 'r') as f: - output = f.read() - - self.RemoveTempFile(local_outfile) - - self.assertEqual(output, args_out) Index: lldb/trunk/packages/Python/lldbsuite/test/settings/quoting/main.c =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/settings/quoting/main.c +++ lldb/trunk/packages/Python/lldbsuite/test/settings/quoting/main.c @@ -1,21 +0,0 @@ -#include -#include -#include - -/* This program writes its arguments (separated by '\0') to stdout. */ -int -main(int argc, char const *argv[]) -{ - int i; - - FILE *output = fopen (argv[1], "w"); - if (output == NULL) - exit (1); - - for (i = 2; i < argc; ++i) - fwrite(argv[i], strlen(argv[i])+1, 1, output); - - fclose (output); - - return 0; -} Index: lldb/trunk/packages/Python/lldbsuite/test/warnings/uuid/Makefile =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/warnings/uuid/Makefile +++ lldb/trunk/packages/Python/lldbsuite/test/warnings/uuid/Makefile @@ -1,5 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -include $(LEVEL)/Makefile.rules Index: lldb/trunk/packages/Python/lldbsuite/test/warnings/uuid/TestAddDsymCommand.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/warnings/uuid/TestAddDsymCommand.py +++ lldb/trunk/packages/Python/lldbsuite/test/warnings/uuid/TestAddDsymCommand.py @@ -1,131 +0,0 @@ -"""Test that the 'add-dsym', aka 'target symbols add', command informs the user about success or failure.""" - -from __future__ import print_function - - -import os -import time -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -@skipUnlessDarwin -class AddDsymCommandCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - TestBase.setUp(self) - self.template = 'main.cpp.template' - self.source = 'main.cpp' - self.teardown_hook_added = False - - @no_debug_info_test - def test_add_dsym_command_with_error(self): - """Test that the 'add-dsym' command informs the user about failures.""" - - # Call the program generator to produce main.cpp, version 1. - self.generate_main_cpp(version=1) - self.buildDefault(dictionary={'MAKE_DSYM':'YES'}) - - # Insert some delay and then call the program generator to produce - # main.cpp, version 2. - time.sleep(5) - self.generate_main_cpp(version=101) - # Now call make again, but this time don't generate the dSYM. - self.buildDefault(dictionary={'MAKE_DSYM':'NO'}) - - self.exe_name = 'a.out' - self.do_add_dsym_with_error(self.exe_name) - - @no_debug_info_test - def test_add_dsym_command_with_success(self): - """Test that the 'add-dsym' command informs the user about success.""" - - # Call the program generator to produce main.cpp, version 1. - self.generate_main_cpp(version=1) - self.buildDefault(dictionary={'MAKE_DSYM':'YES'}) - - self.exe_name = 'a.out' - self.do_add_dsym_with_success(self.exe_name) - - @no_debug_info_test - def test_add_dsym_with_dSYM_bundle(self): - """Test that the 'add-dsym' command informs the user about success.""" - - # Call the program generator to produce main.cpp, version 1. - self.generate_main_cpp(version=1) - self.buildDefault(dictionary={'MAKE_DSYM':'YES'}) - - self.exe_name = 'a.out' - self.do_add_dsym_with_dSYM_bundle(self.exe_name) - - def generate_main_cpp(self, version=0): - """Generate main.cpp from main.cpp.template.""" - temp = os.path.join(self.getSourceDir(), self.template) - with open(temp, 'r') as f: - content = f.read() - - new_content = content.replace( - '%ADD_EXTRA_CODE%', - 'printf("This is version %d\\n");' % - version) - src = os.path.join(self.getBuildDir(), self.source) - with open(src, 'w') as f: - f.write(new_content) - - # The main.cpp has been generated, add a teardown hook to remove it. - if not self.teardown_hook_added: - self.addTearDownHook(lambda: os.remove(src)) - self.teardown_hook_added = True - - def do_add_dsym_with_error(self, exe_name): - """Test that the 'add-dsym' command informs the user about failures.""" - exe_path = self.getBuildArtifact(exe_name) - self.runCmd("file " + exe_path, CURRENT_EXECUTABLE_SET) - - wrong_path = os.path.join(self.getBuildDir(), - "%s.dSYM" % exe_name, "Contents") - self.expect("add-dsym " + wrong_path, error=True, - substrs=['invalid module path']) - - right_path = os.path.join( - self.getBuildDir(), - "%s.dSYM" % - exe_path, - "Contents", - "Resources", - "DWARF", - exe_name) - self.expect("add-dsym " + right_path, error=True, - substrs=['symbol file', 'does not match']) - - def do_add_dsym_with_success(self, exe_name): - """Test that the 'add-dsym' command informs the user about success.""" - exe_path = self.getBuildArtifact(exe_name) - self.runCmd("file " + exe_path, CURRENT_EXECUTABLE_SET) - - # This time, the UUID should match and we expect some feedback from - # lldb. - right_path = os.path.join( - self.getBuildDir(), - "%s.dSYM" % - exe_path, - "Contents", - "Resources", - "DWARF", - exe_name) - self.expect("add-dsym " + right_path, - substrs=['symbol file', 'has been added to']) - - def do_add_dsym_with_dSYM_bundle(self, exe_name): - """Test that the 'add-dsym' command informs the user about success when loading files in bundles.""" - exe_path = self.getBuildArtifact(exe_name) - self.runCmd("file " + exe_path, CURRENT_EXECUTABLE_SET) - - # This time, the UUID should be found inside the bundle - right_path = "%s.dSYM" % exe_path - self.expect("add-dsym " + right_path, - substrs=['symbol file', 'has been added to']) Index: lldb/trunk/packages/Python/lldbsuite/test/warnings/uuid/main.cpp.template =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/warnings/uuid/main.cpp.template +++ lldb/trunk/packages/Python/lldbsuite/test/warnings/uuid/main.cpp.template @@ -1,18 +0,0 @@ -//===-- main.cpp ------------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include - -int -main(int argc, char const *argv[]) -{ - int my_int = argc + 3; - printf("Hello UUID Mismatch: %d\n", my_int); // Set breakpoint here. - %ADD_EXTRA_CODE% - return 0; -}