|
| 1 | +"""Test convenience variables when you drop in from lldb prompt into an embedded interpreter.""" |
| 2 | + |
| 3 | +import os |
| 4 | +import unittest2 |
| 5 | +import lldb |
| 6 | +import pexpect |
| 7 | +from lldbtest import * |
| 8 | + |
| 9 | +class ConvenienceVariablesCase(TestBase): |
| 10 | + |
| 11 | + mydir = "embedded_interpreter" |
| 12 | + |
| 13 | + @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
| 14 | + def test_with_dsym_and_run_command(self): |
| 15 | + """Test convenience variables lldb.debugger, lldb.target, lldb.process, lldb.thread, and lldb.frame.""" |
| 16 | + self.buildDsym() |
| 17 | + self.convenience_variables() |
| 18 | + |
| 19 | + @python_api_test |
| 20 | + def test_with_dwarf_and_process_launch_api(self): |
| 21 | + """Test convenience variables lldb.debugger, lldb.target, lldb.process, lldb.thread, and lldb.frame.""" |
| 22 | + self.buildDwarf() |
| 23 | + self.convenience_variables() |
| 24 | + |
| 25 | + def setUp(self): |
| 26 | + # Call super's setUp(). |
| 27 | + TestBase.setUp(self) |
| 28 | + # Find the line number to break on inside main.cpp. |
| 29 | + self.line = line_number('main.c', 'Hello world.') |
| 30 | + |
| 31 | + def convenience_variables(self): |
| 32 | + """Test convenience variables lldb.debugger, lldb.target, lldb.process, lldb.thread, and lldb.frame.""" |
| 33 | + exe = os.path.join(os.getcwd(), "a.out") |
| 34 | + prompt = "(lldb) " |
| 35 | + python_prompt = ">>> " |
| 36 | + |
| 37 | + # So that the child gets torn down after the test. |
| 38 | + self.child = pexpect.spawn('%s %s' % (self.lldbExec, exe)) |
| 39 | + child = self.child |
| 40 | + # Turn on logging for what the child sends back. |
| 41 | + if self.TraceOn(): |
| 42 | + child.logfile_read = sys.stdout |
| 43 | + |
| 44 | + # Set the breakpoint, run the inferior, when it breaks, issue print on |
| 45 | + # the various convenience variables. |
| 46 | + child.expect_exact(prompt) |
| 47 | + child.sendline('breakpoint set -f main.c -l %d' % self.line) |
| 48 | + child.expect_exact(prompt) |
| 49 | + child.sendline('run') |
| 50 | + child.expect_exact(prompt) |
| 51 | + child.sendline('script') |
| 52 | + child.expect_exact(python_prompt) |
| 53 | + |
| 54 | + # Set a flag so that we know during teardown time, we need to exit the |
| 55 | + # Python interpreter, then the lldb interpreter. |
| 56 | + self.child_in_script_interpreter = True |
| 57 | + |
| 58 | + child.sendline('print lldb.debugger') |
| 59 | + child.expect_exact(python_prompt) |
| 60 | + self.expect(child.before, exe=False, |
| 61 | + patterns = ['Debugger \(instance: .*, id: \d\)']) |
| 62 | + |
| 63 | + child.sendline('print lldb.target') |
| 64 | + child.expect_exact(python_prompt) |
| 65 | + self.expect(child.before, exe=False, |
| 66 | + substrs = ['a.out']) |
| 67 | + |
| 68 | + child.sendline('print lldb.process') |
| 69 | + child.expect_exact(python_prompt) |
| 70 | + self.expect(child.before, exe=False, |
| 71 | + patterns = ['SBProcess: pid = \d+, state = stopped, threads = \d, executable = a.out']) |
| 72 | + |
| 73 | + child.sendline('print lldb.thread') |
| 74 | + child.expect_exact(python_prompt) |
| 75 | + self.expect(child.before, exe=False, |
| 76 | + patterns = ['SBThread: tid = 0x[0-9a-f]+']) |
| 77 | + |
| 78 | + child.sendline('print lldb.frame') |
| 79 | + child.expect_exact(python_prompt) |
| 80 | + self.expect(child.before, exe=False, |
| 81 | + substrs = ['frame #0', 'main.c:%d' % self.line]) |
| 82 | + |
| 83 | + |
| 84 | +if __name__ == '__main__': |
| 85 | + import atexit |
| 86 | + lldb.SBDebugger.Initialize() |
| 87 | + atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 88 | + unittest2.main() |
0 commit comments