1 """Test convenience variables when you drop in from lldb prompt into an embedded interpreter."""
3 from __future__ import print_function
9 from lldbsuite.test.lldbtest import *
11 class ConvenienceVariablesCase(TestBase):
13 mydir = TestBase.compute_mydir(__file__)
16 # Call super's setUp().
18 # Find the line number to break on inside main.cpp.
19 self.line = line_number('main.c', 'Hello world.')
21 @skipIfFreeBSD # llvm.org/pr17228
23 @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
24 def test_with_run_commands(self):
25 """Test convenience variables lldb.debugger, lldb.target, lldb.process, lldb.thread, and lldb.frame."""
28 exe = os.path.join(os.getcwd(), "a.out")
30 python_prompt = ">>> "
32 # So that the child gets torn down after the test.
33 self.child = pexpect.spawn('%s %s %s' % (lldbtest_config.lldbExec, self.lldbOption, exe))
35 # Turn on logging for what the child sends back.
37 child.logfile_read = sys.stdout
39 # Set the breakpoint, run the inferior, when it breaks, issue print on
40 # the various convenience variables.
41 child.expect_exact(prompt)
42 child.sendline('breakpoint set -f main.c -l %d' % self.line)
43 child.expect_exact(prompt)
45 child.expect_exact("stop reason = breakpoint 1.1")
46 child.expect_exact(prompt)
47 child.sendline('script')
48 child.expect_exact(python_prompt)
50 # Set a flag so that we know during teardown time, we need to exit the
51 # Python interpreter, then the lldb interpreter.
52 self.child_in_script_interpreter = True
54 child.sendline('print(lldb.debugger)')
55 child.expect_exact(python_prompt)
56 self.expect(child.before, exe=False,
57 patterns = ['Debugger \(instance: .*, id: \d\)'])
59 child.sendline('print(lldb.target)')
60 child.expect_exact(python_prompt)
61 self.expect(child.before, exe=False,
64 child.sendline('print(lldb.process)')
65 child.expect_exact(python_prompt)
66 self.expect(child.before, exe=False,
67 patterns = ['SBProcess: pid = \d+, state = stopped, threads = \d, executable = a.out'])
69 child.sendline('print(lldb.thread)')
70 child.expect_exact(python_prompt)
71 # Linux outputs decimal tid and 'name' instead of 'queue'
72 self.expect(child.before, exe=False,
73 patterns = ['thread #1: tid = (0x[0-9a-f]+|[0-9]+), 0x[0-9a-f]+ a\.out`main\(argc=1, argv=0x[0-9a-f]+\) \+ \d+ at main\.c:%d, (name|queue) = \'.+\', stop reason = breakpoint 1\.1' % self.line])
75 child.sendline('print(lldb.frame)')
76 child.expect_exact(python_prompt)
77 self.expect(child.before, exe=False,
78 patterns = ['frame #0: 0x[0-9a-f]+ a\.out`main\(argc=1, argv=0x[0-9a-f]+\) \+ \d+ at main\.c:%d' % self.line])