diff options
author | 2020-08-03 14:33:06 +0000 | |
---|---|---|
committer | 2020-08-03 14:33:06 +0000 | |
commit | 061da546b983eb767bad15e67af1174fb0bcf31c (patch) | |
tree | 83c78b820819d70aa40c36d90447978b300078c5 /gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target | |
parent | Import LLVM 10.0.0 release including clang, lld and lldb. (diff) | |
download | wireguard-openbsd-061da546b983eb767bad15e67af1174fb0bcf31c.tar.xz wireguard-openbsd-061da546b983eb767bad15e67af1174fb0bcf31c.zip |
Import LLVM 10.0.0 release including clang, lld and lldb.
ok hackroom
tested by plenty
Diffstat (limited to 'gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target')
19 files changed, 821 insertions, 0 deletions
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/basic/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/basic/Makefile new file mode 100644 index 00000000000..b31e594019f --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/basic/Makefile @@ -0,0 +1,6 @@ +# Example: +# +# C_SOURCES := b.c +# EXE := b.out + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/basic/TestTargetCommand.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/basic/TestTargetCommand.py new file mode 100644 index 00000000000..6152a6a9673 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/basic/TestTargetCommand.py @@ -0,0 +1,439 @@ +""" +Test some target commands: create, list, select, variable. +""" + +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"]) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/basic/a.c b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/basic/a.c new file mode 100644 index 00000000000..ec4824ad4ad --- /dev/null +++ b/gnu/llvm/lldb/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 <stdio.h> + +int main(int argc, const char* argv[]) +{ + int *null_ptr = 0; + printf("Hello, segfault!\n"); + printf("Now crash %d\n", *null_ptr); // Crash here. +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/basic/b.c b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/basic/b.c new file mode 100644 index 00000000000..bcc466c8f96 --- /dev/null +++ b/gnu/llvm/lldb/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. +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/basic/c.c b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/basic/c.c new file mode 100644 index 00000000000..a2cb5995aa5 --- /dev/null +++ b/gnu/llvm/lldb/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 <stdio.h> + +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. +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/basic/globals.c b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/basic/globals.c new file mode 100644 index 00000000000..421b34c0cbc --- /dev/null +++ b/gnu/llvm/lldb/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 <stdio.h> + +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; +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/basic/invalid_core_file b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/basic/invalid_core_file new file mode 100644 index 00000000000..39802f64280 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/basic/invalid_core_file @@ -0,0 +1 @@ +stub diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/create-deps/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/create-deps/Makefile new file mode 100644 index 00000000000..3e5b1049b5a --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/create-deps/Makefile @@ -0,0 +1,10 @@ +LD_EXTRAS := -L. -lload_a +CXX_SOURCES := main.cpp + +a.out: libload_a + +include Makefile.rules + +libload_a: + $(MAKE) -f $(MAKEFILE_RULES) \ + DYLIB_ONLY=YES DYLIB_NAME=load_a DYLIB_CXX_SOURCES=a.cpp diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/create-deps/TestTargetCreateDeps.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/create-deps/TestTargetCreateDeps.py new file mode 100644 index 00000000000..31be1cc86fa --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/create-deps/TestTargetCreateDeps.py @@ -0,0 +1,113 @@ +""" +Test that loading of dependents works correctly for all the potential +combinations. +""" + + +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) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/create-deps/a.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/create-deps/a.cpp new file mode 100644 index 00000000000..e80612bd5cc --- /dev/null +++ b/gnu/llvm/lldb/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; +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/create-deps/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/create-deps/main.cpp new file mode 100644 index 00000000000..7ee1981a4c2 --- /dev/null +++ b/gnu/llvm/lldb/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(); +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/create-no-such-arch/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/create-no-such-arch/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/create-no-such-arch/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/create-no-such-arch/TestNoSuchArch.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/create-no-such-arch/TestNoSuchArch.py new file mode 100644 index 00000000000..622a813ed41 --- /dev/null +++ b/gnu/llvm/lldb/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. +""" + + +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + + +class NoSuchArchTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True + + 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 create --arch nothingtoseehere %s" % + (exe), error=True, substrs=["error: invalid triple 'nothingtoseehere'"]) + + # 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") diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/create-no-such-arch/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/create-no-such-arch/main.cpp new file mode 100644 index 00000000000..4cce7f667ff --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/create-no-such-arch/main.cpp @@ -0,0 +1,3 @@ +int main() { + return 0; +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/dump-symtab-demangle/TestDumpSymtabDemangle.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/dump-symtab-demangle/TestDumpSymtabDemangle.py new file mode 100644 index 00000000000..9f95a11f387 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/dump-symtab-demangle/TestDumpSymtabDemangle.py @@ -0,0 +1,30 @@ +""" +Test 'target modules dump symtab -m' doesn't demangle symbols. +""" + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @no_debug_info_test + def test(self): + src_dir = self.getSourceDir() + yaml_path = os.path.join(src_dir, "a.yaml") + yaml_base, ext = os.path.splitext(yaml_path) + obj_path = self.getBuildArtifact("main.o") + self.yaml2obj(yaml_path, obj_path) + + # Create a target with the object file we just created from YAML + target = self.dbg.CreateTarget(obj_path) + self.assertTrue(target, VALID_TARGET) + + # First test that we demangle by default and our mangled symbol isn't in the output. + self.expect("target modules dump symtab", substrs=["foo::bar(int)"]) + self.expect("target modules dump symtab", matching=False, substrs=["_ZN3foo3barEi"]) + + # Turn off demangling and make sure that we now see the mangled name in the output. + self.expect("target modules dump symtab -m", substrs=["_ZN3foo3barEi"]) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/dump-symtab-demangle/a.yaml b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/dump-symtab-demangle/a.yaml new file mode 100644 index 00000000000..ed591d7c1c1 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/dump-symtab-demangle/a.yaml @@ -0,0 +1,18 @@ +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000010 + Content: 554889E5897DFC5DC3 +Symbols: + - Name: _ZN3foo3barEi + Type: STT_FUNC + Section: .text + Size: 0x0000000000000009 +... diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/stop-hooks/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/stop-hooks/Makefile new file mode 100644 index 00000000000..695335e068c --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/stop-hooks/Makefile @@ -0,0 +1,4 @@ +C_SOURCES := main.c +CFLAGS_EXTRAS := -std=c99 + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/stop-hooks/TestStopHooks.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/stop-hooks/TestStopHooks.py new file mode 100644 index 00000000000..64686afe627 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/stop-hooks/TestStopHooks.py @@ -0,0 +1,40 @@ +""" +Test that stop hooks trigger on "step-out" +""" + + + +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 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") + + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/stop-hooks/main.c b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/stop-hooks/main.c new file mode 100644 index 00000000000..d08ad14776b --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/target/stop-hooks/main.c @@ -0,0 +1,14 @@ +#include <stdio.h> + +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(); +} |