summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/packages/Python/lldbsuite')
-rw-r--r--lldb/packages/Python/lldbsuite/test/api/command-return-object/Makefile3
-rw-r--r--lldb/packages/Python/lldbsuite/test/api/command-return-object/TestSBCommandReturnObject.py31
-rw-r--r--lldb/packages/Python/lldbsuite/test/api/command-return-object/main.cpp35
3 files changed, 69 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/api/command-return-object/Makefile b/lldb/packages/Python/lldbsuite/test/api/command-return-object/Makefile
new file mode 100644
index 00000000000..99998b20bcb
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/api/command-return-object/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
diff --git a/lldb/packages/Python/lldbsuite/test/api/command-return-object/TestSBCommandReturnObject.py b/lldb/packages/Python/lldbsuite/test/api/command-return-object/TestSBCommandReturnObject.py
new file mode 100644
index 00000000000..cf7dbe58daa
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/api/command-return-object/TestSBCommandReturnObject.py
@@ -0,0 +1,31 @@
+"""Test the lldb public C++ api for returning SBCommandReturnObject."""
+
+from __future__ import print_function
+
+
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestSBCommandReturnObject(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+ NO_DEBUG_INFO_TESTCASE = True
+
+ @skipIfNoSBHeaders
+ def test_sb_command_return_object(self):
+ env = {self.dylibPath: self.getLLDBLibraryEnvVal()}
+
+ self.driver_exe = self.getBuildArtifact("command-return-object")
+ self.buildDriver('main.cpp', self.driver_exe)
+ self.addTearDownHook(lambda: os.remove(self.driver_exe))
+ self.signBinary(self.driver_exe)
+
+ if self.TraceOn():
+ print("Running test %s" % self.driver_exe)
+ check_call([self.driver_exe, self.driver_exe], env=env)
+ else:
+ with open(os.devnull, 'w') as fnull:
+ check_call([self.driver_exe, self.driver_exe],
+ env=env, stdout=fnull, stderr=fnull)
diff --git a/lldb/packages/Python/lldbsuite/test/api/command-return-object/main.cpp b/lldb/packages/Python/lldbsuite/test/api/command-return-object/main.cpp
new file mode 100644
index 00000000000..4aeaf3fd5fd
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/api/command-return-object/main.cpp
@@ -0,0 +1,35 @@
+#include "lldb/API/SBCommandInterpreter.h"
+#include "lldb/API/SBCommandReturnObject.h"
+#include "lldb/API/SBDebugger.h"
+
+using namespace lldb;
+
+static SBCommandReturnObject subcommand(SBDebugger &dbg, const char *cmd) {
+ SBCommandReturnObject Result;
+ dbg.GetCommandInterpreter().HandleCommand(cmd, Result);
+ return Result;
+}
+
+class CommandCrasher : public SBCommandPluginInterface {
+public:
+ bool DoExecute(SBDebugger dbg, char **command,
+ SBCommandReturnObject &result) {
+ // Test assignment from a different SBCommandReturnObject instance.
+ result = subcommand(dbg, "help");
+ // Test also whether self-assignment is handled correctly.
+ result = result;
+ if (!result.Succeeded())
+ return false;
+ return true;
+ }
+};
+
+int main() {
+ SBDebugger::Initialize();
+ SBDebugger dbg = SBDebugger::Create(false /*source_init_files*/);
+ SBCommandInterpreter interp = dbg.GetCommandInterpreter();
+ static CommandCrasher crasher;
+ interp.AddCommand("crasher", &crasher, nullptr /*help*/);
+ SBCommandReturnObject Result;
+ dbg.GetCommandInterpreter().HandleCommand("crasher", Result);
+}
OpenPOWER on IntegriCloud