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