diff --git a/lldb/bindings/interface/SBPlatform.i b/lldb/bindings/interface/SBPlatform.i --- a/lldb/bindings/interface/SBPlatform.i +++ b/lldb/bindings/interface/SBPlatform.i @@ -115,6 +115,8 @@ ~SBPlatform(); + static SBPlatform GetHostPlatform(); + bool IsValid () const; diff --git a/lldb/include/lldb/API/SBPlatform.h b/lldb/include/lldb/API/SBPlatform.h --- a/lldb/include/lldb/API/SBPlatform.h +++ b/lldb/include/lldb/API/SBPlatform.h @@ -97,6 +97,8 @@ ~SBPlatform(); + static SBPlatform GetHostPlatform(); + explicit operator bool() const; bool IsValid() const; diff --git a/lldb/packages/Python/lldbsuite/test/decorators.py b/lldb/packages/Python/lldbsuite/test/decorators.py --- a/lldb/packages/Python/lldbsuite/test/decorators.py +++ b/lldb/packages/Python/lldbsuite/test/decorators.py @@ -172,7 +172,7 @@ skip_for_debug_info = _match_decorator_property( debug_info, self.getDebugInfo()) skip_for_triple = _match_decorator_property( - triple, lldb.DBG.GetSelectedPlatform().GetTriple()) + triple, lldb.selected_platform.GetTriple()) skip_for_remote = _match_decorator_property( remote, lldb.remote_platform is not None) diff --git a/lldb/packages/Python/lldbsuite/test/dotest.py b/lldb/packages/Python/lldbsuite/test/dotest.py --- a/lldb/packages/Python/lldbsuite/test/dotest.py +++ b/lldb/packages/Python/lldbsuite/test/dotest.py @@ -774,16 +774,6 @@ raise -def setSetting(setting, value): - import lldb - ci = lldb.DBG.GetCommandInterpreter() - res = lldb.SBCommandReturnObject() - cmd = 'setting set %s %s'%(setting, value) - print(cmd) - ci.HandleCommand(cmd, res, False) - if not res.Succeeded(): - raise Exception('failed to run "%s"'%cmd) - # ======================================== # # # # Execution of the test driver starts here # @@ -809,6 +799,8 @@ def exitTestSuite(exitCode=None): + # lldb.py does SBDebugger.Initialize(). + # Call SBDebugger.Terminate() on exit. import lldb lldb.SBDebugger.Terminate() if exitCode: @@ -931,7 +923,7 @@ def checkDebugInfoSupport(): import lldb - platform = lldb.DBG.GetSelectedPlatform().GetTriple().split('-')[2] + platform = lldb.selected_platform.GetTriple().split('-')[2] compiler = configuration.compiler skipped = [] for cat in test_categories.debug_info_categories: @@ -961,17 +953,13 @@ setupSysPath() - - # For the time being, let's bracket the test runner within the - # lldb.SBDebugger.Initialize()/Terminate() pair. import lldb + # Use host platform by default. + lldb.selected_platform = lldb.SBPlatform.GetHostPlatform() # Now we can also import lldbutil from lldbsuite.test import lldbutil - # Create a singleton SBDebugger in the lldb namespace. - lldb.DBG = lldb.SBDebugger.Create() - if configuration.lldb_platform_name: print("Setting up remote platform '%s'" % (configuration.lldb_platform_name)) @@ -1020,7 +1008,7 @@ if not lldb.remote_platform.SetWorkingDirectory( configuration.lldb_platform_working_dir): raise Exception("failed to set working directory '%s'" % configuration.lldb_platform_working_dir) - lldb.DBG.SetSelectedPlatform(lldb.remote_platform) + lldb.selected_platform = lldb.remote_platform else: lldb.remote_platform = None configuration.lldb_platform_working_dir = None @@ -1031,7 +1019,7 @@ build_dir = configuration.test_build_dir lldbutil.mkdir_p(build_dir) - target_platform = lldb.DBG.GetSelectedPlatform().GetTriple().split('-')[2] + target_platform = lldb.selected_platform.GetTriple().split('-')[2] checkLibcxxSupport() checkLibstdcxxSupport() @@ -1059,10 +1047,6 @@ # Now that we have loaded all the test cases, run the whole test suite. # - # Set any user-overridden settings. - for key, value in configuration.settings: - setSetting(key, value) - # Install the control-c handler. unittest2.signals.installHandler() diff --git a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py --- a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py +++ b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py @@ -57,7 +57,7 @@ def target_is_android(): if not hasattr(target_is_android, 'result'): - triple = lldb.DBG.GetSelectedPlatform().GetTriple() + triple = lldb.selected_platform.GetTriple() match = re.match(".*-.*-.*-android", triple) target_is_android.result = match is not None return target_is_android.result @@ -129,7 +129,7 @@ def getPlatform(): """Returns the target platform which the tests are running on.""" - triple = lldb.DBG.GetSelectedPlatform().GetTriple() + triple = lldb.selected_platform.GetTriple() if triple is None: # It might be an unconnected remote platform. return '' diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py --- a/lldb/packages/Python/lldbsuite/test/lldbtest.py +++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py @@ -703,6 +703,11 @@ configuration.lldb_module_cache_dir), "settings set use-color false", ] + + # Set any user-overridden settings. + for setting, value in configuration.settings: + commands.append('setting set %s %s'%(setting, value)) + # Make sure that a sanitizer LLDB's environment doesn't get passed on. if cls.platformContext and cls.platformContext.shlib_environment_var in os.environ: commands.append('settings set target.env-vars {}='.format( @@ -803,11 +808,11 @@ # set environment variable names for finding shared libraries self.dylibPath = self.platformContext.shlib_environment_var - # Create the debugger instance if necessary. - try: - self.dbg = lldb.DBG - except AttributeError: - self.dbg = lldb.SBDebugger.Create() + # Create the debugger instance. + self.dbg = lldb.SBDebugger.Create() + # Copy selected platform from a global instance if it exists. + if lldb.selected_platform is not None: + self.dbg.SetSelectedPlatform(lldb.selected_platform) if not self.dbg: raise Exception('Invalid debugger instance') @@ -1018,6 +1023,11 @@ for dict in reversed(self.dicts): self.cleanup(dictionary=dict) + # This must be the last statement, otherwise teardown hooks or other + # lines might depend on this still being active. + lldb.SBDebugger.Destroy(self.dbg) + del self.dbg + # ========================================================= # Various callbacks to allow introspection of test progress # ========================================================= @@ -1994,10 +2004,6 @@ # Do this last, to make sure it's in reverse order from how we setup. Base.tearDown(self) - # This must be the last statement, otherwise teardown hooks or other - # lines might depend on this still being active. - del self.dbg - def switch_to_thread_with_stop_reason(self, stop_reason): """ Run the 'thread list' command, and select the thread with stop reason as diff --git a/lldb/source/API/SBPlatform.cpp b/lldb/source/API/SBPlatform.cpp --- a/lldb/source/API/SBPlatform.cpp +++ b/lldb/source/API/SBPlatform.cpp @@ -303,6 +303,12 @@ SBPlatform::~SBPlatform() = default; +SBPlatform SBPlatform::GetHostPlatform() { + SBPlatform host_platform; + host_platform.m_opaque_sp = Platform::GetHostPlatform(); + return host_platform; +} + bool SBPlatform::IsValid() const { LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBPlatform, IsValid); return this->operator bool(); diff --git a/lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py b/lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py --- a/lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py +++ b/lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py @@ -13,14 +13,6 @@ class TestAutoInstallMainExecutable(gdbremote_testcase.GdbRemoteTestCaseBase): mydir = TestBase.compute_mydir(__file__) - def setUp(self): - super(TestAutoInstallMainExecutable, self).setUp() - self._initial_platform = lldb.DBG.GetSelectedPlatform() - - def tearDown(self): - lldb.DBG.SetSelectedPlatform(self._initial_platform) - super(TestAutoInstallMainExecutable, self).tearDown() - @llgs_test @no_debug_info_test @skipIf(remote=False) @@ -61,16 +53,11 @@ # Wait for the new process gets ready. time.sleep(0.1) - new_debugger = lldb.SBDebugger.Create() - new_debugger.SetAsync(False) - - def del_debugger(new_debugger=new_debugger): - del new_debugger - self.addTearDownHook(del_debugger) + self.dbg.SetAsync(False) new_platform = lldb.SBPlatform(lldb.remote_platform.GetName()) - new_debugger.SetSelectedPlatform(new_platform) - new_interpreter = new_debugger.GetCommandInterpreter() + self.dbg.SetSelectedPlatform(new_platform) + interpreter = self.dbg.GetCommandInterpreter() connect_url = "%s://%s:%s" % (protocol, hostname, str(hostport+1)) @@ -79,7 +66,7 @@ result = lldb.SBCommandReturnObject() # Test the default setting. - new_interpreter.HandleCommand("settings show target.auto-install-main-executable", result) + interpreter.HandleCommand("settings show target.auto-install-main-executable", result) self.assertTrue( result.Succeeded() and "target.auto-install-main-executable (boolean) = true" in result.GetOutput(), @@ -87,16 +74,16 @@ (result.GetOutput(), result.GetError())) # Disable the auto install. - new_interpreter.HandleCommand("settings set target.auto-install-main-executable false", result) - new_interpreter.HandleCommand("settings show target.auto-install-main-executable", result) + interpreter.HandleCommand("settings set target.auto-install-main-executable false", result) + interpreter.HandleCommand("settings show target.auto-install-main-executable", result) self.assertTrue( result.Succeeded() and "target.auto-install-main-executable (boolean) = false" in result.GetOutput(), "Default settings for target.auto-install-main-executable failed.: %s - %s" % (result.GetOutput(), result.GetError())) - new_interpreter.HandleCommand("platform select %s"%configuration.lldb_platform_name, result) - new_interpreter.HandleCommand(command, result) + interpreter.HandleCommand("platform select %s"%configuration.lldb_platform_name, result) + interpreter.HandleCommand(command, result) self.assertTrue( result.Succeeded(), @@ -104,7 +91,7 @@ (result.GetOutput(),result.GetError())) # Create the target with the original file. - new_interpreter.HandleCommand("target create --remote-file %s %s "% + interpreter.HandleCommand("target create --remote-file %s %s "% (os.path.join(working_dir,dest.GetFilename()), self.getBuildArtifact("a.out")), result) self.assertTrue( @@ -128,7 +115,7 @@ frame = thread.GetFrameAtIndex(0) self.assertEqual(frame.GetFunction().GetName(), "main") - new_interpreter.HandleCommand("target variable build", result) + interpreter.HandleCommand("target variable build", result) self.assertTrue( result.Succeeded() and '"device"' in result.GetOutput(), diff --git a/lldb/test/API/functionalities/breakpoint/breakpoint_in_delayslot/TestAvoidBreakpointInDelaySlot.py b/lldb/test/API/functionalities/breakpoint/breakpoint_in_delayslot/TestAvoidBreakpointInDelaySlot.py --- a/lldb/test/API/functionalities/breakpoint/breakpoint_in_delayslot/TestAvoidBreakpointInDelaySlot.py +++ b/lldb/test/API/functionalities/breakpoint/breakpoint_in_delayslot/TestAvoidBreakpointInDelaySlot.py @@ -79,9 +79,3 @@ i += 1 else: i += 1 - -if __name__ == '__main__': - import atexit - lldb.SBDebugger.Initialize() - atexit.register(lambda: lldb.SBDebugger.Terminate()) - unittest2.main() diff --git a/lldb/test/API/functionalities/breakpoint/step_over_breakpoint/TestStepOverBreakpoint.py b/lldb/test/API/functionalities/breakpoint/step_over_breakpoint/TestStepOverBreakpoint.py --- a/lldb/test/API/functionalities/breakpoint/step_over_breakpoint/TestStepOverBreakpoint.py +++ b/lldb/test/API/functionalities/breakpoint/step_over_breakpoint/TestStepOverBreakpoint.py @@ -87,7 +87,6 @@ @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 diff --git a/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py b/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py --- a/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py +++ b/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py @@ -11,14 +11,6 @@ def readRegisters(self): return '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' - def setUp(self): - super(TestGDBRemoteClient, self).setUp() - self._initial_platform = lldb.DBG.GetSelectedPlatform() - - def tearDown(self): - lldb.DBG.SetSelectedPlatform(self._initial_platform) - super(TestGDBRemoteClient, self).tearDown() - def test_connect(self): """Test connecting to a remote gdb server""" target = self.createTarget("a.yaml") diff --git a/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteLoad.py b/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteLoad.py --- a/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteLoad.py +++ b/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteLoad.py @@ -6,14 +6,6 @@ class TestGDBRemoteLoad(GDBRemoteTestBase): - def setUp(self): - super(TestGDBRemoteLoad, self).setUp() - self._initial_platform = lldb.DBG.GetSelectedPlatform() - - def tearDown(self): - lldb.DBG.SetSelectedPlatform(self._initial_platform) - super(TestGDBRemoteLoad, self).tearDown() - def test_module_load_address(self): """Test that setting the load address of a module uses virtual addresses""" target = self.createTarget("a.yaml") diff --git a/lldb/test/API/functionalities/gdb_remote_client/TestWasm.py b/lldb/test/API/functionalities/gdb_remote_client/TestWasm.py --- a/lldb/test/API/functionalities/gdb_remote_client/TestWasm.py +++ b/lldb/test/API/functionalities/gdb_remote_client/TestWasm.py @@ -86,14 +86,6 @@ class TestWasm(GDBRemoteTestBase): - def setUp(self): - super(TestWasm, self).setUp() - self._initial_platform = lldb.DBG.GetSelectedPlatform() - - def tearDown(self): - lldb.DBG.SetSelectedPlatform(self._initial_platform) - super(TestWasm, self).tearDown() - @skipIfAsan @skipIfXmlSupportMissing def test_load_module_with_embedded_symbols_from_remote(self): diff --git a/lldb/test/API/functionalities/gdb_remote_client/TestWriteMemory.py b/lldb/test/API/functionalities/gdb_remote_client/TestWriteMemory.py --- a/lldb/test/API/functionalities/gdb_remote_client/TestWriteMemory.py +++ b/lldb/test/API/functionalities/gdb_remote_client/TestWriteMemory.py @@ -6,15 +6,6 @@ class TestWriteMemory(GDBRemoteTestBase): - def setUp(self): - super(TestWriteMemory, self).setUp() - self._initial_platform = lldb.DBG.GetSelectedPlatform() - - def tearDown(self): - lldb.DBG.SetSelectedPlatform(self._initial_platform) - super(TestWriteMemory, self).tearDown() - - def test(self): class MyResponder(MockGDBServerResponder): diff --git a/lldb/test/API/functionalities/gdb_remote_client/TestqOffsets.py b/lldb/test/API/functionalities/gdb_remote_client/TestqOffsets.py --- a/lldb/test/API/functionalities/gdb_remote_client/TestqOffsets.py +++ b/lldb/test/API/functionalities/gdb_remote_client/TestqOffsets.py @@ -10,14 +10,6 @@ def qOffsets(self): return 'Text=470000;Data=470000' - def setUp(self): - super(TestqOffsets, self).setUp() - self._initial_platform = lldb.DBG.GetSelectedPlatform() - - def tearDown(self): - lldb.DBG.SetSelectedPlatform(self._initial_platform) - super(TestqOffsets, self).tearDown() - def test(self): self.server.responder = TestqOffsets.Responder() target = self.createTarget("qOffsets.yaml") diff --git a/lldb/test/API/functionalities/plugins/command_plugin/TestPluginCommands.py b/lldb/test/API/functionalities/plugins/command_plugin/TestPluginCommands.py --- a/lldb/test/API/functionalities/plugins/command_plugin/TestPluginCommands.py +++ b/lldb/test/API/functionalities/plugins/command_plugin/TestPluginCommands.py @@ -37,16 +37,14 @@ # Invoke the library build rule. self.buildLibrary("plugin.cpp", plugin_name) - debugger = lldb.SBDebugger.Create() - retobj = lldb.SBCommandReturnObject() - retval = debugger.GetCommandInterpreter().HandleCommand( + retval = self.dbg.GetCommandInterpreter().HandleCommand( "plugin load %s" % self.getBuildArtifact(plugin_lib_name), retobj) retobj.Clear() - retval = debugger.GetCommandInterpreter().HandleCommand( + retval = self.dbg.GetCommandInterpreter().HandleCommand( "plugin_loaded_command child abc def ghi", retobj) if self.TraceOn(): @@ -57,7 +55,7 @@ retobj.Clear() # check that abbreviations work correctly in plugin commands. - retval = debugger.GetCommandInterpreter().HandleCommand( + retval = self.dbg.GetCommandInterpreter().HandleCommand( "plugin_loaded_ ch abc def ghi", retobj) if self.TraceOn(): diff --git a/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py b/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py --- a/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py +++ b/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py @@ -33,14 +33,6 @@ _mips_regions = 5 _ppc64le_regions = 2 - def setUp(self): - super(LinuxCoreTestCase, self).setUp() - self._initial_platform = lldb.DBG.GetSelectedPlatform() - - def tearDown(self): - lldb.DBG.SetSelectedPlatform(self._initial_platform) - super(LinuxCoreTestCase, self).tearDown() - @skipIf(triple='^mips') @skipIfLLVMTargetMissing("X86") def test_i386(self): diff --git a/lldb/test/API/functionalities/postmortem/elf-core/gcore/TestGCore.py b/lldb/test/API/functionalities/postmortem/elf-core/gcore/TestGCore.py --- a/lldb/test/API/functionalities/postmortem/elf-core/gcore/TestGCore.py +++ b/lldb/test/API/functionalities/postmortem/elf-core/gcore/TestGCore.py @@ -14,13 +14,6 @@ NO_DEBUG_INFO_TESTCASE = True mydir = TestBase.compute_mydir(__file__) - def setUp(self): - super(GCoreTestCase, self).setUp() - self._initial_platform = lldb.DBG.GetSelectedPlatform() - - def tearDown(self): - lldb.DBG.SetSelectedPlatform(self._initial_platform) - super(GCoreTestCase, self).tearDown() _i386_pid = 5586 _x86_64_pid = 5669 diff --git a/lldb/test/API/functionalities/postmortem/elf-core/thread_crash/TestLinuxCoreThreads.py b/lldb/test/API/functionalities/postmortem/elf-core/thread_crash/TestLinuxCoreThreads.py --- a/lldb/test/API/functionalities/postmortem/elf-core/thread_crash/TestLinuxCoreThreads.py +++ b/lldb/test/API/functionalities/postmortem/elf-core/thread_crash/TestLinuxCoreThreads.py @@ -15,14 +15,6 @@ mydir = TestBase.compute_mydir(__file__) - def setUp(self): - super(LinuxCoreThreadsTestCase, self).setUp() - self._initial_platform = lldb.DBG.GetSelectedPlatform() - - def tearDown(self): - lldb.DBG.SetSelectedPlatform(self._initial_platform) - super(LinuxCoreThreadsTestCase, self).tearDown() - _i386_pid = 5193 _x86_64_pid = 5222 diff --git a/lldb/test/API/functionalities/postmortem/mach-core/TestMachCore.py b/lldb/test/API/functionalities/postmortem/mach-core/TestMachCore.py --- a/lldb/test/API/functionalities/postmortem/mach-core/TestMachCore.py +++ b/lldb/test/API/functionalities/postmortem/mach-core/TestMachCore.py @@ -15,14 +15,6 @@ mydir = TestBase.compute_mydir(__file__) - def setUp(self): - super(MachCoreTestCase, self).setUp() - self._initial_platform = lldb.DBG.GetSelectedPlatform() - - def tearDown(self): - lldb.DBG.SetSelectedPlatform(self._initial_platform) - super(MachCoreTestCase, self).tearDown() - # This was originally marked as expected failure on Windows, but it has # started timing out instead, so the expectedFailure attribute no longer # correctly tracks it: llvm.org/pr37371 diff --git a/lldb/test/API/functionalities/postmortem/minidump-new/TestMiniDumpNew.py b/lldb/test/API/functionalities/postmortem/minidump-new/TestMiniDumpNew.py --- a/lldb/test/API/functionalities/postmortem/minidump-new/TestMiniDumpNew.py +++ b/lldb/test/API/functionalities/postmortem/minidump-new/TestMiniDumpNew.py @@ -22,14 +22,6 @@ _linux_x86_64_not_crashed_pid = 29939 _linux_x86_64_not_crashed_pid_offset = 0xD967 - def setUp(self): - super(MiniDumpNewTestCase, self).setUp() - self._initial_platform = lldb.DBG.GetSelectedPlatform() - - def tearDown(self): - lldb.DBG.SetSelectedPlatform(self._initial_platform) - super(MiniDumpNewTestCase, self).tearDown() - def process_from_yaml(self, yaml_file): minidump_path = self.getBuildArtifact(os.path.basename(yaml_file) + ".dmp") self.yaml2obj(yaml_file, minidump_path) diff --git a/lldb/test/API/functionalities/postmortem/minidump-new/TestMiniDumpUUID.py b/lldb/test/API/functionalities/postmortem/minidump-new/TestMiniDumpUUID.py --- a/lldb/test/API/functionalities/postmortem/minidump-new/TestMiniDumpUUID.py +++ b/lldb/test/API/functionalities/postmortem/minidump-new/TestMiniDumpUUID.py @@ -18,14 +18,6 @@ NO_DEBUG_INFO_TESTCASE = True - def setUp(self): - super(MiniDumpUUIDTestCase, self).setUp() - self._initial_platform = lldb.DBG.GetSelectedPlatform() - - def tearDown(self): - lldb.DBG.SetSelectedPlatform(self._initial_platform) - super(MiniDumpUUIDTestCase, self).tearDown() - def verify_module(self, module, verify_path, verify_uuid): uuid = module.GetUUIDString() self.assertEqual(verify_path, module.GetFileSpec().fullpath) diff --git a/lldb/test/API/functionalities/postmortem/netbsd-core/TestNetBSDCore.py b/lldb/test/API/functionalities/postmortem/netbsd-core/TestNetBSDCore.py --- a/lldb/test/API/functionalities/postmortem/netbsd-core/TestNetBSDCore.py +++ b/lldb/test/API/functionalities/postmortem/netbsd-core/TestNetBSDCore.py @@ -18,14 +18,6 @@ mydir = TestBase.compute_mydir(__file__) - def setUp(self): - super(NetBSDCoreCommonTestCase, self).setUp() - self._initial_platform = lldb.DBG.GetSelectedPlatform() - - def tearDown(self): - lldb.DBG.SetSelectedPlatform(self._initial_platform) - super(NetBSDCoreCommonTestCase, self).tearDown() - def check_memory_regions(self, process, region_count): region_list = process.GetMemoryRegions() self.assertEqual(region_list.GetSize(), region_count) diff --git a/lldb/test/API/functionalities/thread/backtrace_all/TestBacktraceAll.py b/lldb/test/API/functionalities/thread/backtrace_all/TestBacktraceAll.py --- a/lldb/test/API/functionalities/thread/backtrace_all/TestBacktraceAll.py +++ b/lldb/test/API/functionalities/thread/backtrace_all/TestBacktraceAll.py @@ -57,9 +57,3 @@ # Run to completion self.runCmd("continue") - -if __name__ == '__main__': - import atexit - lldb.SBDebugger.Initialize() - atexit.register(lambda: lldb.SBDebugger.Terminate()) - unittest2.main() diff --git a/lldb/test/API/functionalities/unwind/noreturn/module-end/TestNoReturnModuleEnd.py b/lldb/test/API/functionalities/unwind/noreturn/module-end/TestNoReturnModuleEnd.py --- a/lldb/test/API/functionalities/unwind/noreturn/module-end/TestNoReturnModuleEnd.py +++ b/lldb/test/API/functionalities/unwind/noreturn/module-end/TestNoReturnModuleEnd.py @@ -15,14 +15,6 @@ NO_DEBUG_INFO_TESTCASE = True mydir = TestBase.compute_mydir(__file__) - def setUp(self): - super(TestNoreturnModuleEnd, self).setUp() - self._initial_platform = lldb.DBG.GetSelectedPlatform() - - def tearDown(self): - lldb.DBG.SetSelectedPlatform(self._initial_platform) - super(TestNoreturnModuleEnd, self).tearDown() - def test(self): target = self.dbg.CreateTarget("test.out") process = target.LoadCore("test.core") diff --git a/lldb/test/API/macosx/load-kext/TestLoadKext.py b/lldb/test/API/macosx/load-kext/TestLoadKext.py --- a/lldb/test/API/macosx/load-kext/TestLoadKext.py +++ b/lldb/test/API/macosx/load-kext/TestLoadKext.py @@ -15,11 +15,6 @@ mydir = TestBase.compute_mydir(__file__) - def setUp(self): - TestBase.setUp(self) - #super(LoadKextTestCase, self).setUp() - #self._initial_platform = lldb.DBG.GetSelectedPlatform() - def test_load_kext(self): """Test that lldb can load a kext binary.""" diff --git a/lldb/test/API/python_api/file_handle/TestFileHandle.py b/lldb/test/API/python_api/file_handle/TestFileHandle.py --- a/lldb/test/API/python_api/file_handle/TestFileHandle.py +++ b/lldb/test/API/python_api/file_handle/TestFileHandle.py @@ -82,12 +82,7 @@ NO_DEBUG_INFO_TESTCASE = True mydir = lldbtest.Base.compute_mydir(__file__) - # The way this class interacts with the debugger is different - # than normal. Most of these test cases will mess with the - # debugger I/O streams, so we want a fresh debugger for each - # test so those mutations don't interfere with each other. - # - # Also, the way normal tests evaluate debugger commands is + # The way normal tests evaluate debugger commands is # by using a SBCommandInterpreter directly, which captures # the output in a result object. For many of tests tests # we want the debugger to write the output directly to @@ -98,30 +93,27 @@ def setUp(self): super(FileHandleTestCase, self).setUp() - self.debugger = lldb.SBDebugger.Create() self.out_filename = self.getBuildArtifact('output') self.in_filename = self.getBuildArtifact('input') def tearDown(self): - lldb.SBDebugger.Destroy(self.debugger) super(FileHandleTestCase, self).tearDown() for name in (self.out_filename, self.in_filename): if os.path.exists(name): os.unlink(name) - # Similar to runCmd(), but this uses the per-test debugger, and it - # supports, letting the debugger just print the results instead - # of collecting them. + # Similar to runCmd(), but letting the debugger just print the results + # instead of collecting them. def handleCmd(self, cmd, check=True, collect_result=True): assert not check or collect_result ret = lldb.SBCommandReturnObject() if collect_result: - interpreter = self.debugger.GetCommandInterpreter() + interpreter = self.dbg.GetCommandInterpreter() interpreter.HandleCommand(cmd, ret) else: - self.debugger.HandleCommand(cmd) - self.debugger.GetOutputFile().Flush() - self.debugger.GetErrorFile().Flush() + self.dbg.HandleCommand(cmd) + self.dbg.GetOutputFile().Flush() + self.dbg.GetErrorFile().Flush() if collect_result and check: self.assertTrue(ret.Succeeded()) return ret.GetOutput() @@ -130,14 +122,13 @@ @add_test_categories(['pyapi']) def test_legacy_file_out_script(self): with open(self.out_filename, 'w') as f: - self.debugger.SetOutputFileHandle(f, False) + self.dbg.SetOutputFileHandle(f, False) # scripts print to output even if you capture the results # I'm not sure I love that behavior, but that's the way # it's been for a long time. That's why this test works # even with collect_result=True. self.handleCmd('script 1+1') - self.debugger.GetOutputFileHandle().write('FOO\n') - lldb.SBDebugger.Destroy(self.debugger) + self.dbg.GetOutputFileHandle().write('FOO\n') with open(self.out_filename, 'r') as f: self.assertEqual(readStrippedLines(f), ['2', 'FOO']) @@ -145,21 +136,19 @@ @add_test_categories(['pyapi']) def test_legacy_file_out(self): with open(self.out_filename, 'w') as f: - self.debugger.SetOutputFileHandle(f, False) + self.dbg.SetOutputFileHandle(f, False) self.handleCmd('p/x 3735928559', collect_result=False, check=False) - lldb.SBDebugger.Destroy(self.debugger) with open(self.out_filename, 'r') as f: self.assertIn('deadbeef', f.read()) @add_test_categories(['pyapi']) def test_legacy_file_err_with_get(self): with open(self.out_filename, 'w') as f: - self.debugger.SetErrorFileHandle(f, False) + self.dbg.SetErrorFileHandle(f, False) self.handleCmd('lolwut', check=False, collect_result=False) - f2 = self.debugger.GetErrorFileHandle() + f2 = self.dbg.GetErrorFileHandle() f2.write('FOOBAR\n') f2.flush() - lldb.SBDebugger.Destroy(self.debugger) with open(self.out_filename, 'r') as f: errors = f.read() self.assertTrue(re.search(r'error:.*lolwut', errors)) @@ -169,18 +158,16 @@ @add_test_categories(['pyapi']) def test_legacy_file_err(self): with open(self.out_filename, 'w') as f: - self.debugger.SetErrorFileHandle(f, False) + self.dbg.SetErrorFileHandle(f, False) self.handleCmd('lol', check=False, collect_result=False) - lldb.SBDebugger.Destroy(self.debugger) with open(self.out_filename, 'r') as f: self.assertIn("is not a valid command", f.read()) @add_test_categories(['pyapi']) def test_legacy_file_error(self): - debugger = self.debugger with open(self.out_filename, 'w') as f: - debugger.SetErrorFileHandle(f, False) + self.dbg.SetErrorFileHandle(f, False) self.handleCmd('lolwut', check=False, collect_result=False) with open(self.out_filename, 'r') as f: errors = f.read() @@ -255,10 +242,10 @@ def test_fileno_out(self): with open(self.out_filename, 'w') as f: sbf = lldb.SBFile(f.fileno(), "w", False) - status = self.debugger.SetOutputFile(sbf) + status = self.dbg.SetOutputFile(sbf) self.assertTrue(status.Success()) self.handleCmd('script 1+2') - self.debugger.GetOutputFile().Write(b'quux') + self.dbg.GetOutputFile().Write(b'quux') with open(self.out_filename, 'r') as f: self.assertEqual(readStrippedLines(f), ['3', 'quux']) @@ -268,7 +255,7 @@ def test_fileno_help(self): with open(self.out_filename, 'w') as f: sbf = lldb.SBFile(f.fileno(), "w", False) - status = self.debugger.SetOutputFile(sbf) + status = self.dbg.SetOutputFile(sbf) self.assertTrue(status.Success()) self.handleCmd("help help", collect_result=False, check=False) with open(self.out_filename, 'r') as f: @@ -277,9 +264,8 @@ @add_test_categories(['pyapi']) def test_help(self): - debugger = self.debugger with open(self.out_filename, 'w') as f: - status = debugger.SetOutputFile(lldb.SBFile(f)) + status = self.dbg.SetOutputFile(lldb.SBFile(f)) self.assertTrue(status.Success()) self.handleCmd("help help", check=False, collect_result=False) with open(self.out_filename, 'r') as f: @@ -291,7 +277,7 @@ with open(self.out_filename, 'w') as f: ret = lldb.SBCommandReturnObject() ret.SetImmediateOutputFile(f) - interpreter = self.debugger.GetCommandInterpreter() + interpreter = self.dbg.GetCommandInterpreter() interpreter.HandleCommand("help help", ret) # make sure the file wasn't closed early. f.write("\nQUUX\n") @@ -308,7 +294,7 @@ f = io.StringIO() ret = lldb.SBCommandReturnObject() ret.SetImmediateOutputFile(f) - interpreter = self.debugger.GetCommandInterpreter() + interpreter = self.dbg.GetCommandInterpreter() interpreter.HandleCommand("help help", ret) # make sure the file wasn't closed early. f.write("\nQUUX\n") @@ -324,7 +310,7 @@ f = io.StringIO() ret = lldb.SBCommandReturnObject() ret.SetImmediateOutputFile(lldb.SBFile(f)) - interpreter = self.debugger.GetCommandInterpreter() + interpreter = self.dbg.GetCommandInterpreter() interpreter.HandleCommand("help help", ret) output = f.getvalue() ret = None # call destructor and flush streams @@ -341,16 +327,16 @@ with open(self.out_filename, 'w') as outf, open(self.in_filename, 'r') as inf: outsbf = lldb.SBFile(outf.fileno(), "w", False) - status = self.debugger.SetOutputFile(outsbf) + status = self.dbg.SetOutputFile(outsbf) self.assertTrue(status.Success()) insbf = lldb.SBFile(inf.fileno(), "r", False) - status = self.debugger.SetInputFile(insbf) + status = self.dbg.SetInputFile(insbf) self.assertTrue(status.Success()) opts = lldb.SBCommandInterpreterRunOptions() - self.debugger.RunCommandInterpreter(True, False, opts, 0, False, False) - self.debugger.GetOutputFile().Flush() + self.dbg.RunCommandInterpreter(True, False, opts, 0, False, False) + self.dbg.GetOutputFile().Flush() with open(self.out_filename, 'r') as f: self.assertTrue(re.search(r'Show a list of all debugger commands', f.read())) @@ -362,13 +348,13 @@ f.write("help help\n") with open(self.out_filename, 'w') as outf, \ open(self.in_filename, 'r') as inf: - status = self.debugger.SetOutputFile(lldb.SBFile(outf)) + status = self.dbg.SetOutputFile(lldb.SBFile(outf)) self.assertTrue(status.Success()) - status = self.debugger.SetInputFile(lldb.SBFile(inf)) + status = self.dbg.SetInputFile(lldb.SBFile(inf)) self.assertTrue(status.Success()) opts = lldb.SBCommandInterpreterRunOptions() - self.debugger.RunCommandInterpreter(True, False, opts, 0, False, False) - self.debugger.GetOutputFile().Flush() + self.dbg.RunCommandInterpreter(True, False, opts, 0, False, False) + self.dbg.GetOutputFile().Flush() with open(self.out_filename, 'r') as f: output = f.read() self.assertIn('Show a list of all debugger commands', output) @@ -376,18 +362,17 @@ @add_test_categories(['pyapi']) def test_binary_inout(self): - debugger = self.debugger with open(self.in_filename, 'w') as f: f.write("help help\n") with open(self.out_filename, 'wb') as outf, \ open(self.in_filename, 'rb') as inf: - status = debugger.SetOutputFile(lldb.SBFile(outf)) + status = self.dbg.SetOutputFile(lldb.SBFile(outf)) self.assertTrue(status.Success()) - status = debugger.SetInputFile(lldb.SBFile(inf)) + status = self.dbg.SetInputFile(lldb.SBFile(inf)) self.assertTrue(status.Success()) opts = lldb.SBCommandInterpreterRunOptions() - debugger.RunCommandInterpreter(True, False, opts, 0, False, False) - debugger.GetOutputFile().Flush() + self.dbg.RunCommandInterpreter(True, False, opts, 0, False, False) + self.dbg.GetOutputFile().Flush() with open(self.out_filename, 'r') as f: output = f.read() self.assertIn('Show a list of all debugger commands', output) @@ -398,13 +383,13 @@ def test_string_inout(self): inf = io.StringIO("help help\np/x ~0\n") outf = io.StringIO() - status = self.debugger.SetOutputFile(lldb.SBFile(outf)) + status = self.dbg.SetOutputFile(lldb.SBFile(outf)) self.assertTrue(status.Success()) - status = self.debugger.SetInputFile(lldb.SBFile(inf)) + status = self.dbg.SetInputFile(lldb.SBFile(inf)) self.assertTrue(status.Success()) opts = lldb.SBCommandInterpreterRunOptions() - self.debugger.RunCommandInterpreter(True, False, opts, 0, False, False) - self.debugger.GetOutputFile().Flush() + self.dbg.RunCommandInterpreter(True, False, opts, 0, False, False) + self.dbg.GetOutputFile().Flush() output = outf.getvalue() self.assertIn('Show a list of all debugger commands', output) self.assertIn('0xfff', output) @@ -415,13 +400,13 @@ def test_bytes_inout(self): inf = io.BytesIO(b"help help\nhelp b\n") outf = io.BytesIO() - status = self.debugger.SetOutputFile(lldb.SBFile(outf)) + status = self.dbg.SetOutputFile(lldb.SBFile(outf)) self.assertTrue(status.Success()) - status = self.debugger.SetInputFile(lldb.SBFile(inf)) + status = self.dbg.SetInputFile(lldb.SBFile(inf)) self.assertTrue(status.Success()) opts = lldb.SBCommandInterpreterRunOptions() - self.debugger.RunCommandInterpreter(True, False, opts, 0, False, False) - self.debugger.GetOutputFile().Flush() + self.dbg.RunCommandInterpreter(True, False, opts, 0, False, False) + self.dbg.GetOutputFile().Flush() output = outf.getvalue() self.assertIn(b'Show a list of all debugger commands', output) self.assertIn(b'Set a breakpoint', output) @@ -432,12 +417,12 @@ with open(self.out_filename, 'w') as f: sbf = lldb.SBFile(f.fileno(), 'w', False) - status = self.debugger.SetErrorFile(sbf) + status = self.dbg.SetErrorFile(sbf) self.assertTrue(status.Success()) self.handleCmd('lolwut', check=False, collect_result=False) - self.debugger.GetErrorFile().Write(b'\nzork\n') + self.dbg.GetErrorFile().Write(b'\nzork\n') with open(self.out_filename, 'r') as f: errors = f.read() @@ -457,7 +442,6 @@ @add_test_categories(['pyapi']) def test_replace_stdout_with_nonfile(self): - debugger = self.debugger f = io.StringIO() with replace_stdout(f): class Nothing(): @@ -545,7 +529,7 @@ @skipIf(py_version=['<', (3,)]) def test_string_out(self): f = io.StringIO() - status = self.debugger.SetOutputFile(f) + status = self.dbg.SetOutputFile(f) self.assertTrue(status.Success()) self.handleCmd("script 'foobar'") self.assertEqual(f.getvalue().strip(), "'foobar'") @@ -555,8 +539,7 @@ @skipIf(py_version=['<', (3,)]) def test_string_error(self): f = io.StringIO() - debugger = self.debugger - status = debugger.SetErrorFile(f) + status = self.dbg.SetErrorFile(f) self.assertTrue(status.Success()) self.handleCmd('lolwut', check=False, collect_result=False) errors = f.getvalue() @@ -614,7 +597,7 @@ def test_sbfile_out(self): with open(self.out_filename, 'w') as f: sbf = lldb.SBFile(f) - status = self.debugger.SetOutputFile(sbf) + status = self.dbg.SetOutputFile(sbf) self.assertTrue(status.Success()) self.handleCmd('script 2+2') with open(self.out_filename, 'r') as f: @@ -625,7 +608,7 @@ @skipIf(py_version=['<', (3,)]) def test_file_out(self): with open(self.out_filename, 'w') as f: - status = self.debugger.SetOutputFile(f) + status = self.dbg.SetOutputFile(f) self.assertTrue(status.Success()) self.handleCmd('script 2+2') with open(self.out_filename, 'r') as f: @@ -636,7 +619,7 @@ def test_sbfile_error(self): with open(self.out_filename, 'w') as f: sbf = lldb.SBFile(f) - status = self.debugger.SetErrorFile(sbf) + status = self.dbg.SetErrorFile(sbf) self.assertTrue(status.Success()) self.handleCmd('lolwut', check=False, collect_result=False) with open(self.out_filename, 'r') as f: @@ -647,7 +630,7 @@ @add_test_categories(['pyapi']) def test_file_error(self): with open(self.out_filename, 'w') as f: - status = self.debugger.SetErrorFile(f) + status = self.dbg.SetErrorFile(f) self.assertTrue(status.Success()) self.handleCmd('lolwut', check=False, collect_result=False) with open(self.out_filename, 'r') as f: @@ -677,9 +660,9 @@ @skipIf(py_version=['<', (3,)]) def test_exceptions_logged(self): messages = list() - self.debugger.SetLoggingCallback(messages.append) + self.dbg.SetLoggingCallback(messages.append) self.handleCmd('log enable lldb script') - self.debugger.SetOutputFile(lldb.SBFile(BadIO())) + self.dbg.SetOutputFile(lldb.SBFile(BadIO())) self.handleCmd('script 1+1') self.assertTrue(any('OH NOE' in msg for msg in messages)) @@ -737,14 +720,13 @@ @add_test_categories(['pyapi']) def test_close(self): - debugger = self.debugger with open(self.out_filename, 'w') as f: - status = debugger.SetOutputFile(f) + status = self.dbg.SetOutputFile(f) self.assertTrue(status.Success()) self.handleCmd("help help", check=False, collect_result=False) # make sure the file wasn't closed early. f.write("\nZAP\n") - lldb.SBDebugger.Destroy(debugger) + lldb.SBDebugger.Destroy(self.dbg) # check that output file was closed when debugger was destroyed. with self.assertRaises(ValueError): f.write("\nQUUX\n") @@ -758,7 +740,7 @@ @skipIf(py_version=['<', (3,)]) def test_stdout(self): f = io.StringIO() - status = self.debugger.SetOutputFile(f) + status = self.dbg.SetOutputFile(f) self.assertTrue(status.Success()) self.handleCmd(r"script sys.stdout.write('foobar\n')") self.assertEqual(f.getvalue().strip().split(), ["foobar", "7"]) @@ -767,7 +749,7 @@ @add_test_categories(['pyapi']) def test_stdout_file(self): with open(self.out_filename, 'w') as f: - status = self.debugger.SetOutputFile(f) + status = self.dbg.SetOutputFile(f) self.assertTrue(status.Success()) self.handleCmd(r"script sys.stdout.write('foobar\n')") with open(self.out_filename, 'r') as f: @@ -856,38 +838,38 @@ @add_test_categories(['pyapi']) def test_set_filehandle_none(self): - self.assertRaises(Exception, self.debugger.SetOutputFile, None) - self.assertRaises(Exception, self.debugger.SetOutputFile, "ham sandwich") - self.assertRaises(Exception, self.debugger.SetOutputFileHandle, "ham sandwich") - self.assertRaises(Exception, self.debugger.SetInputFile, None) - self.assertRaises(Exception, self.debugger.SetInputFile, "ham sandwich") - self.assertRaises(Exception, self.debugger.SetInputFileHandle, "ham sandwich") - self.assertRaises(Exception, self.debugger.SetErrorFile, None) - self.assertRaises(Exception, self.debugger.SetErrorFile, "ham sandwich") - self.assertRaises(Exception, self.debugger.SetErrorFileHandle, "ham sandwich") + self.assertRaises(Exception, self.dbg.SetOutputFile, None) + self.assertRaises(Exception, self.dbg.SetOutputFile, "ham sandwich") + self.assertRaises(Exception, self.dbg.SetOutputFileHandle, "ham sandwich") + self.assertRaises(Exception, self.dbg.SetInputFile, None) + self.assertRaises(Exception, self.dbg.SetInputFile, "ham sandwich") + self.assertRaises(Exception, self.dbg.SetInputFileHandle, "ham sandwich") + self.assertRaises(Exception, self.dbg.SetErrorFile, None) + self.assertRaises(Exception, self.dbg.SetErrorFile, "ham sandwich") + self.assertRaises(Exception, self.dbg.SetErrorFileHandle, "ham sandwich") with open(self.out_filename, 'w') as f: - status = self.debugger.SetOutputFile(f) + status = self.dbg.SetOutputFile(f) self.assertTrue(status.Success()) - status = self.debugger.SetErrorFile(f) + status = self.dbg.SetErrorFile(f) self.assertTrue(status.Success()) - self.debugger.SetOutputFileHandle(None, False) - self.debugger.SetErrorFileHandle(None, False) - sbf = self.debugger.GetOutputFile() + self.dbg.SetOutputFileHandle(None, False) + self.dbg.SetErrorFileHandle(None, False) + sbf = self.dbg.GetOutputFile() if sys.version_info.major >= 3: # python 2 lacks PyFile_FromFd, so GetFile() will # have to duplicate the file descriptor and make a FILE* # in order to convert a NativeFile it back to a python # file. self.assertEqual(sbf.GetFile().fileno(), 1) - sbf = self.debugger.GetErrorFile() + sbf = self.dbg.GetErrorFile() if sys.version_info.major >= 3: self.assertEqual(sbf.GetFile().fileno(), 2) with open(self.out_filename, 'r') as f: - status = self.debugger.SetInputFile(f) + status = self.dbg.SetInputFile(f) self.assertTrue(status.Success()) - self.debugger.SetInputFileHandle(None, False) - sbf = self.debugger.GetInputFile() + self.dbg.SetInputFileHandle(None, False) + sbf = self.dbg.GetInputFile() if sys.version_info.major >= 3: self.assertEqual(sbf.GetFile().fileno(), 0) diff --git a/lldb/test/API/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py b/lldb/test/API/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py --- a/lldb/test/API/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py +++ b/lldb/test/API/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py @@ -10,14 +10,6 @@ class TestPlatformProcessConnect(gdbremote_testcase.GdbRemoteTestCaseBase): mydir = TestBase.compute_mydir(__file__) - def setUp(self): - super(TestPlatformProcessConnect, self).setUp() - self._initial_platform = lldb.DBG.GetSelectedPlatform() - - def tearDown(self): - lldb.DBG.SetSelectedPlatform(self._initial_platform) - super(TestPlatformProcessConnect, self).tearDown() - @llgs_test @no_debug_info_test @skipIf(remote=False) @@ -66,16 +58,10 @@ socket_id = lldbutil.wait_for_file_on_target(self, port_file) - new_debugger = lldb.SBDebugger.Create() - new_debugger.SetAsync(False) - - def del_debugger(new_debugger=new_debugger): - del new_debugger - self.addTearDownHook(del_debugger) + self.dbg.SetAsync(False) new_platform = lldb.SBPlatform(lldb.remote_platform.GetName()) - new_debugger.SetSelectedPlatform(new_platform) - new_interpreter = new_debugger.GetCommandInterpreter() + self.dbg.SetSelectedPlatform(new_platform) if unix_protocol: connect_url = "%s://%s%s" % (protocol, hostname, socket_id) @@ -84,13 +70,13 @@ command = "platform connect %s" % (connect_url) result = lldb.SBCommandReturnObject() - new_interpreter.HandleCommand(command, result) + self.dbg.GetCommandInterpreter().HandleCommand(command, result) self.assertTrue( result.Succeeded(), "platform process connect failed: %s" % result.GetOutput()) - target = new_debugger.GetSelectedTarget() + target = self.dbg.GetSelectedTarget() process = target.GetProcess() thread = process.GetThreadAtIndex(0)