diff options
author | Jan Kratochvil <jan.kratochvil@redhat.com> | 2019-10-04 19:32:57 +0000 |
---|---|---|
committer | Jan Kratochvil <jan.kratochvil@redhat.com> | 2019-10-04 19:32:57 +0000 |
commit | 4112b4733502f746b766861853c414af0e01d6f9 (patch) | |
tree | f28f290ceef9830b8e82c639255a7b16b3d6ba99 /lldb/packages/Python/lldbsuite/test | |
parent | f7766b1ed41aa07b6a784d0ebf074c63ada1940d (diff) | |
download | bcm5719-llvm-4112b4733502f746b766861853c414af0e01d6f9.tar.gz bcm5719-llvm-4112b4733502f746b766861853c414af0e01d6f9.zip |
[lldb] Fix crash on SBCommandReturnObject & assignment
I was writing an SB API client and it was crashing on:
bool DoExecute(SBDebugger dbg, char **command, SBCommandReturnObject &result) {
result = subcommand(dbg, "help");
That is because SBCommandReturnObject &result gets initialized inside LLDB by:
bool DoExecute(Args &command, CommandReturnObject &result) override {
// std::unique_ptr gets initialized here from `&result`!!!
SBCommandReturnObject sb_return(&result);
DoExecute(...);
sb_return.Release();
Differential revision: https://reviews.llvm.org/D67589
llvm-svn: 373775
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test')
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); +} |