]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/embedded_interpreter/TestConvenienceVariables.py
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / embedded_interpreter / TestConvenienceVariables.py
1 """Test convenience variables when you drop in from lldb prompt into an embedded interpreter."""
2
3 from __future__ import print_function
4
5
6
7 import os
8 import lldb
9 from lldbsuite.test.lldbtest import *
10
11 class ConvenienceVariablesCase(TestBase):
12
13     mydir = TestBase.compute_mydir(__file__)
14
15     def setUp(self):
16         # Call super's setUp().
17         TestBase.setUp(self)
18         # Find the line number to break on inside main.cpp.
19         self.line = line_number('main.c', 'Hello world.')
20
21     @skipIfFreeBSD # llvm.org/pr17228
22     @skipIfRemote
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."""
26         self.build()
27         import pexpect
28         exe = os.path.join(os.getcwd(), "a.out")
29         prompt = "(lldb) "
30         python_prompt = ">>> "
31
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))
34         child = self.child
35         # Turn on logging for what the child sends back.
36         if self.TraceOn():
37             child.logfile_read = sys.stdout
38
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)
44         child.sendline('run')
45         child.expect_exact("stop reason = breakpoint 1.1")
46         child.expect_exact(prompt)
47         child.sendline('script')
48         child.expect_exact(python_prompt)
49
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
53
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\)'])
58
59         child.sendline('print(lldb.target)')
60         child.expect_exact(python_prompt)
61         self.expect(child.before, exe=False,
62             substrs = ['a.out'])
63
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'])
68
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])
74
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])