1"""
2Test that commands do not try and hold on to stale CommandInterpreters in a multiple debuggers scenario
3"""
4
5from __future__ import print_function
6
7
8import lldb
9from lldbsuite.test.decorators import *
10from lldbsuite.test.lldbtest import *
11from lldbsuite.test import lldbutil
12
13
14class MultipleDebuggersCommandsTestCase(TestBase):
15
16    mydir = TestBase.compute_mydir(__file__)
17
18    @no_debug_info_test
19    def test_multipledebuggers_commands(self):
20        """Test that commands do not try and hold on to stale CommandInterpreters in a multiple debuggers scenario"""
21        source_init_files = False
22        magic_text = "The following commands may relate to 'env'"
23
24        debugger_1 = lldb.SBDebugger.Create(source_init_files)
25        interpreter_1 = debugger_1.GetCommandInterpreter()
26
27        retobj = lldb.SBCommandReturnObject()
28        interpreter_1.HandleCommand("apropos env", retobj)
29        self.assertTrue(
30            magic_text in str(retobj),
31            "[interpreter_1]: the output does not contain the correct words")
32
33        if self.TraceOn():
34            print(str(retobj))
35
36        lldb.SBDebugger.Destroy(debugger_1)
37
38        # now do this again with a different debugger - we shouldn't crash
39
40        debugger_2 = lldb.SBDebugger.Create(source_init_files)
41        interpreter_2 = debugger_2.GetCommandInterpreter()
42
43        retobj = lldb.SBCommandReturnObject()
44        interpreter_2.HandleCommand("apropos env", retobj)
45        self.assertTrue(
46            magic_text in str(retobj),
47            "[interpreter_2]: the output does not contain the correct words")
48
49        if self.TraceOn():
50            print(str(retobj))
51
52        lldb.SBDebugger.Destroy(debugger_2)
53