summaryrefslogtreecommitdiffstats
path: root/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command
diff options
context:
space:
mode:
authorpatrick <patrick@openbsd.org>2020-08-03 14:33:06 +0000
committerpatrick <patrick@openbsd.org>2020-08-03 14:33:06 +0000
commit061da546b983eb767bad15e67af1174fb0bcf31c (patch)
tree83c78b820819d70aa40c36d90447978b300078c5 /gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command
parentImport LLVM 10.0.0 release including clang, lld and lldb. (diff)
downloadwireguard-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/command')
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/.categories1
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/delete/TestCommandDelete.py17
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/history/TestCommandHistory.py106
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/invalid-args/TestInvalidArgsCommand.py58
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/nested_alias/Makefile3
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/nested_alias/TestNestedAlias.py99
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/nested_alias/main.cpp21
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/Makefile3
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/TestCommandScript.py167
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/bug11569.py6
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/callables.py62
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/decorated.py35
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/Makefile4
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/TestImport.py71
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/bar/bar.py15
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/bar/barutil.py2
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/dummymodule.py2
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/foo/bar/foobar.py6
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/foo/foo.py6
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/foo/foo2.py11
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/main.c15
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/rdar-12586188/Makefile1
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/rdar-12586188/TestRdar12586188.py31
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/rdar-12586188/fail12586188.py4
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/rdar-12586188/fail212586188.py4
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/thepackage/TPunitA.py7
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/thepackage/TPunitB.py7
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/thepackage/__init__.py11
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/main.cpp69
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/mysto.py22
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/py_import32
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/welcome.py53
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script_alias/TestCommandScriptAlias.py35
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script_alias/tcsacmd.py11
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/source/.lldb2
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/source/TestCommandSource.py34
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/source/commands.txt2
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/source/my.py7
38 files changed, 1042 insertions, 0 deletions
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/.categories b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/.categories
new file mode 100644
index 00000000000..3a3f4df6416
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/.categories
@@ -0,0 +1 @@
+cmdline
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/delete/TestCommandDelete.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/delete/TestCommandDelete.py
new file mode 100644
index 00000000000..3fa654d20aa
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/delete/TestCommandDelete.py
@@ -0,0 +1,17 @@
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.decorators import *
+
+class DeleteCommandTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @no_debug_info_test
+ def test_delete_builtin(self):
+ self.expect("command delete settings", error=True,
+ substrs=["'settings' is a permanent debugger command and cannot be removed."])
+
+ @no_debug_info_test
+ def test_delete_alias(self):
+ self.expect("command delete bt", error=True,
+ substrs=["'bt' is not a known command."])
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/history/TestCommandHistory.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/history/TestCommandHistory.py
new file mode 100644
index 00000000000..c866198f26b
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/history/TestCommandHistory.py
@@ -0,0 +1,106 @@
+"""
+Test the command history mechanism
+"""
+
+
+
+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'])
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/invalid-args/TestInvalidArgsCommand.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/invalid-args/TestInvalidArgsCommand.py
new file mode 100644
index 00000000000..47d77b0e569
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/invalid-args/TestInvalidArgsCommand.py
@@ -0,0 +1,58 @@
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.decorators import *
+
+class InvalidArgsCommandTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @no_debug_info_test
+ def test_script_add(self):
+ self.expect("command script add 1 2", error=True,
+ substrs=["'command script add' requires one argument"])
+
+ self.expect("command script add", error=True,
+ substrs=["'command script add' requires one argument"])
+
+ @no_debug_info_test
+ def test_script_clear(self):
+ self.expect("command script clear f", error=True,
+ substrs=["'command script clear' doesn't take any arguments"])
+
+ @no_debug_info_test
+ def test_script_list(self):
+ self.expect("command script list f", error=True,
+ substrs=["'command script list' doesn't take any arguments"])
+
+ @no_debug_info_test
+ def test_script_import(self):
+ self.expect("command script import", error=True,
+ substrs=["command script import needs one or more arguments"])
+
+ @no_debug_info_test
+ def test_alias(self):
+ self.expect("command alias", error=True,
+ substrs=["'command alias' requires at least two arguments"])
+
+ self.expect("command alias blub foo", error=True,
+ substrs=["error: invalid command given to 'command alias'. 'foo' does not begin with a valid command. No alias created."])
+
+ @no_debug_info_test
+ def test_unalias(self):
+ self.expect("command unalias", error=True,
+ substrs=["must call 'unalias' with a valid alias"])
+
+ @no_debug_info_test
+ def test_delete(self):
+ self.expect("command delete", error=True,
+ substrs=["must call 'command delete' with one or more valid user"])
+
+ @no_debug_info_test
+ def test_regex(self):
+ self.expect("command regex", error=True,
+ substrs=["usage: 'command regex <command-name> "])
+
+ @no_debug_info_test
+ def test_source(self):
+ self.expect("command source", error=True,
+ substrs=["'command source' takes exactly one executable filename argument."])
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/nested_alias/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/nested_alias/Makefile
new file mode 100644
index 00000000000..99998b20bcb
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/nested_alias/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/nested_alias/TestNestedAlias.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/nested_alias/TestNestedAlias.py
new file mode 100644
index 00000000000..a1374a9c716
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/nested_alias/TestNestedAlias.py
@@ -0,0 +1,99 @@
+"""
+Test that an alias can reference other aliases without crashing.
+"""
+
+
+
+import lldb
+from lldbsuite.test.lldbtest import *
+import lldbsuite.test.lldbutil as lldbutil
+
+
+class NestedAliasTestCase(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.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)
+
+ # Check that foself was resolved and is now independent of 'fo'.
+ self.runCmd('command unalias fo')
+ self.expect(
+ 'help foself',
+ substrs=[
+ 'Show variables for the current',
+ 'stack frame.'],
+ matching=True)
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/nested_alias/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/nested_alias/main.cpp
new file mode 100644
index 00000000000..4df7eed40a5
--- /dev/null
+++ b/gnu/llvm/lldb/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 <stdio.h>
+
+int main (int argc, char const *argv[])
+{
+ void* my_ptr[] = {
+ reinterpret_cast<void*>(0xDEADBEEF),
+ reinterpret_cast<void*>(main),
+ reinterpret_cast<void*>(0xFEEDBEEF),
+ reinterpret_cast<void*>(0xFEEDDEAD),
+ reinterpret_cast<void*>(0xDEADFEED)
+ };
+ return 0; // break here
+}
+
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/Makefile
new file mode 100644
index 00000000000..99998b20bcb
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/TestCommandScript.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/TestCommandScript.py
new file mode 100644
index 00000000000..de449612a37
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/TestCommandScript.py
@@ -0,0 +1,167 @@
+"""
+Test lldb Python commands.
+"""
+
+
+import sys
+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")
+
+ # Test a bunch of different kinds of python callables with
+ # both 4 and 5 positional arguments.
+ self.expect("foobar", substrs=["All good"])
+ self.expect("foobar4", substrs=["All good"])
+ self.expect("vfoobar", substrs=["All good"])
+ self.expect("v5foobar", substrs=["All good"])
+ self.expect("sfoobar", substrs=["All good"])
+ self.expect("cfoobar", substrs=["All good"])
+ self.expect("ifoobar", substrs=["All good"])
+ self.expect("sfoobar4", substrs=["All good"])
+ self.expect("cfoobar4", substrs=["All good"])
+ self.expect("ifoobar4", substrs=["All good"])
+ self.expect("ofoobar", substrs=["All good"])
+ self.expect("ofoobar4", substrs=["All good"])
+
+ # 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)
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/bug11569.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/bug11569.py
new file mode 100644
index 00000000000..3c124de79bf
--- /dev/null
+++ b/gnu/llvm/lldb/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"]
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/callables.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/callables.py
new file mode 100644
index 00000000000..c31e84cbb53
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/callables.py
@@ -0,0 +1,62 @@
+
+
+import lldb
+
+# bunch of different kinds of python callables that should
+# all work as commands.
+
+def check(debugger, command, context, result, internal_dict):
+ if (not isinstance(debugger, lldb.SBDebugger) or
+ not isinstance(command, str) or
+ not isinstance(result, lldb.SBCommandReturnObject) or
+ not isinstance(internal_dict, dict) or
+ (not context is None and
+ not isinstance(context, lldb.SBExecutionContext))):
+ raise Exception()
+ result.AppendMessage("All good.")
+
+def vfoobar(*args):
+ check(*args)
+
+def v5foobar(debugger, command, context, result, internal_dict, *args):
+ check(debugger, command, context, result, internal_dict)
+
+def foobar(debugger, command, context, result, internal_dict):
+ check(debugger, command, context, result, internal_dict)
+
+def foobar4(debugger, command, result, internal_dict):
+ check(debugger, command, None, result, internal_dict)
+
+class FooBar:
+ @staticmethod
+ def sfoobar(debugger, command, context, result, internal_dict):
+ check(debugger, command, context, result, internal_dict)
+
+ @classmethod
+ def cfoobar(cls, debugger, command, context, result, internal_dict):
+ check(debugger, command, context, result, internal_dict)
+
+ def ifoobar(self, debugger, command, context, result, internal_dict):
+ check(debugger, command, context, result, internal_dict)
+
+ def __call__(self, debugger, command, context, result, internal_dict):
+ check(debugger, command, context, result, internal_dict)
+
+ @staticmethod
+ def sfoobar4(debugger, command, result, internal_dict):
+ check(debugger, command, None, result, internal_dict)
+
+ @classmethod
+ def cfoobar4(cls, debugger, command, result, internal_dict):
+ check(debugger, command, None, result, internal_dict)
+
+ def ifoobar4(self, debugger, command, result, internal_dict):
+ check(debugger, command, None, result, internal_dict)
+
+class FooBar4:
+ def __call__(self, debugger, command, result, internal_dict):
+ check(debugger, command, None, result, internal_dict)
+
+FooBarObj = FooBar()
+
+FooBar4Obj = FooBar4() \ No newline at end of file
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/decorated.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/decorated.py
new file mode 100644
index 00000000000..f9707a5706a
--- /dev/null
+++ b/gnu/llvm/lldb/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)
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/Makefile
new file mode 100644
index 00000000000..d9ee1cc4116
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/Makefile
@@ -0,0 +1,4 @@
+C_SOURCES := main.c
+EXE := hello_world
+
+include Makefile.rules
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/TestImport.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/TestImport.py
new file mode 100644
index 00000000000..a10c23bad1f
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/TestImport.py
@@ -0,0 +1,71 @@
+"""Test custom import command to import files by path."""
+
+
+
+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 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'])
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/bar/bar.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/bar/bar.py
new file mode 100644
index 00000000000..444e00976ad
--- /dev/null
+++ b/gnu/llvm/lldb/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
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/bar/barutil.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/bar/barutil.py
new file mode 100644
index 00000000000..70ecea30057
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/bar/barutil.py
@@ -0,0 +1,2 @@
+def barutil_function(x):
+ return "barutil says: " + x
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/dummymodule.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/dummymodule.py
new file mode 100644
index 00000000000..668a5b90ea4
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/dummymodule.py
@@ -0,0 +1,2 @@
+def no_useful_code(foo):
+ return foo
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/foo/bar/foobar.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/foo/bar/foobar.py
new file mode 100644
index 00000000000..6ef71064c9a
--- /dev/null
+++ b/gnu/llvm/lldb/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
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/foo/foo.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/foo/foo.py
new file mode 100644
index 00000000000..1ccc3892939
--- /dev/null
+++ b/gnu/llvm/lldb/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
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/foo/foo2.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/foo/foo2.py
new file mode 100644
index 00000000000..71657c299c2
--- /dev/null
+++ b/gnu/llvm/lldb/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
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/main.c b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/main.c
new file mode 100644
index 00000000000..dffc8c77b04
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/main.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+
+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");
+}
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/rdar-12586188/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/rdar-12586188/Makefile
new file mode 100644
index 00000000000..22f1051530f
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/rdar-12586188/Makefile
@@ -0,0 +1 @@
+include Makefile.rules
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/rdar-12586188/TestRdar12586188.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/rdar-12586188/TestRdar12586188.py
new file mode 100644
index 00000000000..478cfa38d03
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/rdar-12586188/TestRdar12586188.py
@@ -0,0 +1,31 @@
+"""Check that we handle an ImportError in a special way when command script importing files."""
+
+
+
+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 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")'])
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/rdar-12586188/fail12586188.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/rdar-12586188/fail12586188.py
new file mode 100644
index 00000000000..ea385e03e04
--- /dev/null
+++ b/gnu/llvm/lldb/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")
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/rdar-12586188/fail212586188.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/rdar-12586188/fail212586188.py
new file mode 100644
index 00000000000..8dbc0e67ba1
--- /dev/null
+++ b/gnu/llvm/lldb/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")
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/thepackage/TPunitA.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/thepackage/TPunitA.py
new file mode 100644
index 00000000000..9694b084295
--- /dev/null
+++ b/gnu/llvm/lldb/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
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/thepackage/TPunitB.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/thepackage/TPunitB.py
new file mode 100644
index 00000000000..94a333bc696
--- /dev/null
+++ b/gnu/llvm/lldb/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
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/thepackage/__init__.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/import/thepackage/__init__.py
new file mode 100644
index 00000000000..24cdea60f2c
--- /dev/null
+++ b/gnu/llvm/lldb/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")
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/main.cpp
new file mode 100644
index 00000000000..a0e9efd6ee0
--- /dev/null
+++ b/gnu/llvm/lldb/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 <cstdlib>
+#include <cstring>
+#include <string>
+#include <fstream>
+#include <iostream>
+
+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;
+}
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/mysto.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/mysto.py
new file mode 100644
index 00000000000..04eceb7eb93
--- /dev/null
+++ b/gnu/llvm/lldb/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
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/py_import b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/py_import
new file mode 100644
index 00000000000..4372d32b0ad
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/py_import
@@ -0,0 +1,32 @@
+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
+
+
+command script import callables.py
+
+command script add -f callables.foobar foobar
+command script add -f callables.foobar4 foobar4
+command script add -f callables.vfoobar vfoobar
+command script add -f callables.v5foobar v5foobar
+
+command script add -f callables.FooBar.sfoobar sfoobar
+command script add -f callables.FooBar.cfoobar cfoobar
+command script add -f callables.FooBarObj.ifoobar ifoobar
+
+command script add -f callables.FooBar.sfoobar4 sfoobar4
+command script add -f callables.FooBar.cfoobar4 cfoobar4
+command script add -f callables.FooBarObj.ifoobar4 ifoobar4
+
+command script add -f callables.FooBarObj ofoobar
+command script add -f callables.FooBar4Obj ofoobar4
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/welcome.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script/welcome.py
new file mode 100644
index 00000000000..0539d7c1721
--- /dev/null
+++ b/gnu/llvm/lldb/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)
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script_alias/TestCommandScriptAlias.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script_alias/TestCommandScriptAlias.py
new file mode 100644
index 00000000000..3f2e8ccec29
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script_alias/TestCommandScriptAlias.py
@@ -0,0 +1,35 @@
+"""
+Test lldb Python commands.
+"""
+
+
+
+import lldb
+from lldbsuite.test.lldbtest import *
+
+
+class CommandScriptAliasTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+ NO_DEBUG_INFO_TESTCASE = True
+
+ def test_pycmd(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)
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script_alias/tcsacmd.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/script_alias/tcsacmd.py
new file mode 100644
index 00000000000..8d3248c2723
--- /dev/null
+++ b/gnu/llvm/lldb/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
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/source/.lldb b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/source/.lldb
new file mode 100644
index 00000000000..ecbdcff4462
--- /dev/null
+++ b/gnu/llvm/lldb/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
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/source/TestCommandSource.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/source/TestCommandSource.py
new file mode 100644
index 00000000000..6d2717b16e2
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/source/TestCommandSource.py
@@ -0,0 +1,34 @@
+"""
+Test that lldb command "command source" works correctly.
+"""
+
+
+
+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())])
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/source/commands.txt b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/source/commands.txt
new file mode 100644
index 00000000000..8e4de66d469
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/source/commands.txt
@@ -0,0 +1,2 @@
+script import my
+p 1 + 1
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/source/my.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/command/source/my.py
new file mode 100644
index 00000000000..bd97fda3cbb
--- /dev/null
+++ b/gnu/llvm/lldb/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)