NO_DEBUG_INFO_TESTCASE = True
mydir = lldbtest.Base.compute_mydir(__file__)
- # The way this class interacts with the debugger is different
- # than normal. Most of these test cases will mess with the
- # debugger I/O streams, so we want a fresh debugger for each
- # test so those mutations don't interfere with each other.
- #
- # Also, the way normal tests evaluate debugger commands is
+ # The way normal tests evaluate debugger commands is
# by using a SBCommandInterpreter directly, which captures
# the output in a result object. For many of tests tests
# we want the debugger to write the output directly to
def setUp(self):
super(FileHandleTestCase, self).setUp()
- self.debugger = lldb.SBDebugger.Create()
self.out_filename = self.getBuildArtifact('output')
self.in_filename = self.getBuildArtifact('input')
def tearDown(self):
- lldb.SBDebugger.Destroy(self.debugger)
super(FileHandleTestCase, self).tearDown()
for name in (self.out_filename, self.in_filename):
if os.path.exists(name):
os.unlink(name)
- # Similar to runCmd(), but this uses the per-test debugger, and it
- # supports, letting the debugger just print the results instead
- # of collecting them.
+ # Similar to runCmd(), but letting the debugger just print the results
+ # instead of collecting them.
def handleCmd(self, cmd, check=True, collect_result=True):
assert not check or collect_result
ret = lldb.SBCommandReturnObject()
if collect_result:
- interpreter = self.debugger.GetCommandInterpreter()
+ interpreter = self.dbg.GetCommandInterpreter()
interpreter.HandleCommand(cmd, ret)
else:
- self.debugger.HandleCommand(cmd)
- self.debugger.GetOutputFile().Flush()
- self.debugger.GetErrorFile().Flush()
+ self.dbg.HandleCommand(cmd)
+ self.dbg.GetOutputFile().Flush()
+ self.dbg.GetErrorFile().Flush()
if collect_result and check:
self.assertTrue(ret.Succeeded())
return ret.GetOutput()
@add_test_categories(['pyapi'])
def test_legacy_file_out_script(self):
with open(self.out_filename, 'w') as f:
- self.debugger.SetOutputFileHandle(f, False)
+ self.dbg.SetOutputFileHandle(f, False)
# scripts print to output even if you capture the results
# I'm not sure I love that behavior, but that's the way
# it's been for a long time. That's why this test works
# even with collect_result=True.
self.handleCmd('script 1+1')
- self.debugger.GetOutputFileHandle().write('FOO\n')
- lldb.SBDebugger.Destroy(self.debugger)
+ self.dbg.GetOutputFileHandle().write('FOO\n')
with open(self.out_filename, 'r') as f:
self.assertEqual(readStrippedLines(f), ['2', 'FOO'])
@add_test_categories(['pyapi'])
def test_legacy_file_out(self):
with open(self.out_filename, 'w') as f:
- self.debugger.SetOutputFileHandle(f, False)
+ self.dbg.SetOutputFileHandle(f, False)
self.handleCmd('p/x 3735928559', collect_result=False, check=False)
- lldb.SBDebugger.Destroy(self.debugger)
with open(self.out_filename, 'r') as f:
self.assertIn('deadbeef', f.read())
@add_test_categories(['pyapi'])
def test_legacy_file_err_with_get(self):
with open(self.out_filename, 'w') as f:
- self.debugger.SetErrorFileHandle(f, False)
+ self.dbg.SetErrorFileHandle(f, False)
self.handleCmd('lolwut', check=False, collect_result=False)
- f2 = self.debugger.GetErrorFileHandle()
+ f2 = self.dbg.GetErrorFileHandle()
f2.write('FOOBAR\n')
f2.flush()
- lldb.SBDebugger.Destroy(self.debugger)
with open(self.out_filename, 'r') as f:
errors = f.read()
self.assertTrue(re.search(r'error:.*lolwut', errors))
@add_test_categories(['pyapi'])
def test_legacy_file_err(self):
with open(self.out_filename, 'w') as f:
- self.debugger.SetErrorFileHandle(f, False)
+ self.dbg.SetErrorFileHandle(f, False)
self.handleCmd('lol', check=False, collect_result=False)
- lldb.SBDebugger.Destroy(self.debugger)
with open(self.out_filename, 'r') as f:
self.assertIn("is not a valid command", f.read())
@add_test_categories(['pyapi'])
def test_legacy_file_error(self):
- debugger = self.debugger
with open(self.out_filename, 'w') as f:
- debugger.SetErrorFileHandle(f, False)
+ self.dbg.SetErrorFileHandle(f, False)
self.handleCmd('lolwut', check=False, collect_result=False)
with open(self.out_filename, 'r') as f:
errors = f.read()
def test_fileno_out(self):
with open(self.out_filename, 'w') as f:
sbf = lldb.SBFile(f.fileno(), "w", False)
- status = self.debugger.SetOutputFile(sbf)
+ status = self.dbg.SetOutputFile(sbf)
self.assertTrue(status.Success())
self.handleCmd('script 1+2')
- self.debugger.GetOutputFile().Write(b'quux')
+ self.dbg.GetOutputFile().Write(b'quux')
with open(self.out_filename, 'r') as f:
self.assertEqual(readStrippedLines(f), ['3', 'quux'])
def test_fileno_help(self):
with open(self.out_filename, 'w') as f:
sbf = lldb.SBFile(f.fileno(), "w", False)
- status = self.debugger.SetOutputFile(sbf)
+ status = self.dbg.SetOutputFile(sbf)
self.assertTrue(status.Success())
self.handleCmd("help help", collect_result=False, check=False)
with open(self.out_filename, 'r') as f:
@add_test_categories(['pyapi'])
def test_help(self):
- debugger = self.debugger
with open(self.out_filename, 'w') as f:
- status = debugger.SetOutputFile(lldb.SBFile(f))
+ status = self.dbg.SetOutputFile(lldb.SBFile(f))
self.assertTrue(status.Success())
self.handleCmd("help help", check=False, collect_result=False)
with open(self.out_filename, 'r') as f:
with open(self.out_filename, 'w') as f:
ret = lldb.SBCommandReturnObject()
ret.SetImmediateOutputFile(f)
- interpreter = self.debugger.GetCommandInterpreter()
+ interpreter = self.dbg.GetCommandInterpreter()
interpreter.HandleCommand("help help", ret)
# make sure the file wasn't closed early.
f.write("\nQUUX\n")
f = io.StringIO()
ret = lldb.SBCommandReturnObject()
ret.SetImmediateOutputFile(f)
- interpreter = self.debugger.GetCommandInterpreter()
+ interpreter = self.dbg.GetCommandInterpreter()
interpreter.HandleCommand("help help", ret)
# make sure the file wasn't closed early.
f.write("\nQUUX\n")
f = io.StringIO()
ret = lldb.SBCommandReturnObject()
ret.SetImmediateOutputFile(lldb.SBFile(f))
- interpreter = self.debugger.GetCommandInterpreter()
+ interpreter = self.dbg.GetCommandInterpreter()
interpreter.HandleCommand("help help", ret)
output = f.getvalue()
ret = None # call destructor and flush streams
with open(self.out_filename, 'w') as outf, open(self.in_filename, 'r') as inf:
outsbf = lldb.SBFile(outf.fileno(), "w", False)
- status = self.debugger.SetOutputFile(outsbf)
+ status = self.dbg.SetOutputFile(outsbf)
self.assertTrue(status.Success())
insbf = lldb.SBFile(inf.fileno(), "r", False)
- status = self.debugger.SetInputFile(insbf)
+ status = self.dbg.SetInputFile(insbf)
self.assertTrue(status.Success())
opts = lldb.SBCommandInterpreterRunOptions()
- self.debugger.RunCommandInterpreter(True, False, opts, 0, False, False)
- self.debugger.GetOutputFile().Flush()
+ self.dbg.RunCommandInterpreter(True, False, opts, 0, False, False)
+ self.dbg.GetOutputFile().Flush()
with open(self.out_filename, 'r') as f:
self.assertTrue(re.search(r'Show a list of all debugger commands', f.read()))
f.write("help help\n")
with open(self.out_filename, 'w') as outf, \
open(self.in_filename, 'r') as inf:
- status = self.debugger.SetOutputFile(lldb.SBFile(outf))
+ status = self.dbg.SetOutputFile(lldb.SBFile(outf))
self.assertTrue(status.Success())
- status = self.debugger.SetInputFile(lldb.SBFile(inf))
+ status = self.dbg.SetInputFile(lldb.SBFile(inf))
self.assertTrue(status.Success())
opts = lldb.SBCommandInterpreterRunOptions()
- self.debugger.RunCommandInterpreter(True, False, opts, 0, False, False)
- self.debugger.GetOutputFile().Flush()
+ self.dbg.RunCommandInterpreter(True, False, opts, 0, False, False)
+ self.dbg.GetOutputFile().Flush()
with open(self.out_filename, 'r') as f:
output = f.read()
self.assertIn('Show a list of all debugger commands', output)
@add_test_categories(['pyapi'])
def test_binary_inout(self):
- debugger = self.debugger
with open(self.in_filename, 'w') as f:
f.write("help help\n")
with open(self.out_filename, 'wb') as outf, \
open(self.in_filename, 'rb') as inf:
- status = debugger.SetOutputFile(lldb.SBFile(outf))
+ status = self.dbg.SetOutputFile(lldb.SBFile(outf))
self.assertTrue(status.Success())
- status = debugger.SetInputFile(lldb.SBFile(inf))
+ status = self.dbg.SetInputFile(lldb.SBFile(inf))
self.assertTrue(status.Success())
opts = lldb.SBCommandInterpreterRunOptions()
- debugger.RunCommandInterpreter(True, False, opts, 0, False, False)
- debugger.GetOutputFile().Flush()
+ self.dbg.RunCommandInterpreter(True, False, opts, 0, False, False)
+ self.dbg.GetOutputFile().Flush()
with open(self.out_filename, 'r') as f:
output = f.read()
self.assertIn('Show a list of all debugger commands', output)
def test_string_inout(self):
inf = io.StringIO("help help\np/x ~0\n")
outf = io.StringIO()
- status = self.debugger.SetOutputFile(lldb.SBFile(outf))
+ status = self.dbg.SetOutputFile(lldb.SBFile(outf))
self.assertTrue(status.Success())
- status = self.debugger.SetInputFile(lldb.SBFile(inf))
+ status = self.dbg.SetInputFile(lldb.SBFile(inf))
self.assertTrue(status.Success())
opts = lldb.SBCommandInterpreterRunOptions()
- self.debugger.RunCommandInterpreter(True, False, opts, 0, False, False)
- self.debugger.GetOutputFile().Flush()
+ self.dbg.RunCommandInterpreter(True, False, opts, 0, False, False)
+ self.dbg.GetOutputFile().Flush()
output = outf.getvalue()
self.assertIn('Show a list of all debugger commands', output)
self.assertIn('0xfff', output)
def test_bytes_inout(self):
inf = io.BytesIO(b"help help\nhelp b\n")
outf = io.BytesIO()
- status = self.debugger.SetOutputFile(lldb.SBFile(outf))
+ status = self.dbg.SetOutputFile(lldb.SBFile(outf))
self.assertTrue(status.Success())
- status = self.debugger.SetInputFile(lldb.SBFile(inf))
+ status = self.dbg.SetInputFile(lldb.SBFile(inf))
self.assertTrue(status.Success())
opts = lldb.SBCommandInterpreterRunOptions()
- self.debugger.RunCommandInterpreter(True, False, opts, 0, False, False)
- self.debugger.GetOutputFile().Flush()
+ self.dbg.RunCommandInterpreter(True, False, opts, 0, False, False)
+ self.dbg.GetOutputFile().Flush()
output = outf.getvalue()
self.assertIn(b'Show a list of all debugger commands', output)
self.assertIn(b'Set a breakpoint', output)
with open(self.out_filename, 'w') as f:
sbf = lldb.SBFile(f.fileno(), 'w', False)
- status = self.debugger.SetErrorFile(sbf)
+ status = self.dbg.SetErrorFile(sbf)
self.assertTrue(status.Success())
self.handleCmd('lolwut', check=False, collect_result=False)
- self.debugger.GetErrorFile().Write(b'\nzork\n')
+ self.dbg.GetErrorFile().Write(b'\nzork\n')
with open(self.out_filename, 'r') as f:
errors = f.read()
@add_test_categories(['pyapi'])
def test_replace_stdout_with_nonfile(self):
- debugger = self.debugger
f = io.StringIO()
with replace_stdout(f):
class Nothing():
@skipIf(py_version=['<', (3,)])
def test_string_out(self):
f = io.StringIO()
- status = self.debugger.SetOutputFile(f)
+ status = self.dbg.SetOutputFile(f)
self.assertTrue(status.Success())
self.handleCmd("script 'foobar'")
self.assertEqual(f.getvalue().strip(), "'foobar'")
@skipIf(py_version=['<', (3,)])
def test_string_error(self):
f = io.StringIO()
- debugger = self.debugger
- status = debugger.SetErrorFile(f)
+ status = self.dbg.SetErrorFile(f)
self.assertTrue(status.Success())
self.handleCmd('lolwut', check=False, collect_result=False)
errors = f.getvalue()
def test_sbfile_out(self):
with open(self.out_filename, 'w') as f:
sbf = lldb.SBFile(f)
- status = self.debugger.SetOutputFile(sbf)
+ status = self.dbg.SetOutputFile(sbf)
self.assertTrue(status.Success())
self.handleCmd('script 2+2')
with open(self.out_filename, 'r') as f:
@skipIf(py_version=['<', (3,)])
def test_file_out(self):
with open(self.out_filename, 'w') as f:
- status = self.debugger.SetOutputFile(f)
+ status = self.dbg.SetOutputFile(f)
self.assertTrue(status.Success())
self.handleCmd('script 2+2')
with open(self.out_filename, 'r') as f:
def test_sbfile_error(self):
with open(self.out_filename, 'w') as f:
sbf = lldb.SBFile(f)
- status = self.debugger.SetErrorFile(sbf)
+ status = self.dbg.SetErrorFile(sbf)
self.assertTrue(status.Success())
self.handleCmd('lolwut', check=False, collect_result=False)
with open(self.out_filename, 'r') as f:
@add_test_categories(['pyapi'])
def test_file_error(self):
with open(self.out_filename, 'w') as f:
- status = self.debugger.SetErrorFile(f)
+ status = self.dbg.SetErrorFile(f)
self.assertTrue(status.Success())
self.handleCmd('lolwut', check=False, collect_result=False)
with open(self.out_filename, 'r') as f:
@skipIf(py_version=['<', (3,)])
def test_exceptions_logged(self):
messages = list()
- self.debugger.SetLoggingCallback(messages.append)
+ self.dbg.SetLoggingCallback(messages.append)
self.handleCmd('log enable lldb script')
- self.debugger.SetOutputFile(lldb.SBFile(BadIO()))
+ self.dbg.SetOutputFile(lldb.SBFile(BadIO()))
self.handleCmd('script 1+1')
self.assertTrue(any('OH NOE' in msg for msg in messages))
@add_test_categories(['pyapi'])
def test_close(self):
- debugger = self.debugger
with open(self.out_filename, 'w') as f:
- status = debugger.SetOutputFile(f)
+ status = self.dbg.SetOutputFile(f)
self.assertTrue(status.Success())
self.handleCmd("help help", check=False, collect_result=False)
# make sure the file wasn't closed early.
f.write("\nZAP\n")
- lldb.SBDebugger.Destroy(debugger)
+ lldb.SBDebugger.Destroy(self.dbg)
# check that output file was closed when debugger was destroyed.
with self.assertRaises(ValueError):
f.write("\nQUUX\n")
@skipIf(py_version=['<', (3,)])
def test_stdout(self):
f = io.StringIO()
- status = self.debugger.SetOutputFile(f)
+ status = self.dbg.SetOutputFile(f)
self.assertTrue(status.Success())
self.handleCmd(r"script sys.stdout.write('foobar\n')")
self.assertEqual(f.getvalue().strip().split(), ["foobar", "7"])
@add_test_categories(['pyapi'])
def test_stdout_file(self):
with open(self.out_filename, 'w') as f:
- status = self.debugger.SetOutputFile(f)
+ status = self.dbg.SetOutputFile(f)
self.assertTrue(status.Success())
self.handleCmd(r"script sys.stdout.write('foobar\n')")
with open(self.out_filename, 'r') as f:
@add_test_categories(['pyapi'])
def test_set_filehandle_none(self):
- self.assertRaises(Exception, self.debugger.SetOutputFile, None)
- self.assertRaises(Exception, self.debugger.SetOutputFile, "ham sandwich")
- self.assertRaises(Exception, self.debugger.SetOutputFileHandle, "ham sandwich")
- self.assertRaises(Exception, self.debugger.SetInputFile, None)
- self.assertRaises(Exception, self.debugger.SetInputFile, "ham sandwich")
- self.assertRaises(Exception, self.debugger.SetInputFileHandle, "ham sandwich")
- self.assertRaises(Exception, self.debugger.SetErrorFile, None)
- self.assertRaises(Exception, self.debugger.SetErrorFile, "ham sandwich")
- self.assertRaises(Exception, self.debugger.SetErrorFileHandle, "ham sandwich")
+ self.assertRaises(Exception, self.dbg.SetOutputFile, None)
+ self.assertRaises(Exception, self.dbg.SetOutputFile, "ham sandwich")
+ self.assertRaises(Exception, self.dbg.SetOutputFileHandle, "ham sandwich")
+ self.assertRaises(Exception, self.dbg.SetInputFile, None)
+ self.assertRaises(Exception, self.dbg.SetInputFile, "ham sandwich")
+ self.assertRaises(Exception, self.dbg.SetInputFileHandle, "ham sandwich")
+ self.assertRaises(Exception, self.dbg.SetErrorFile, None)
+ self.assertRaises(Exception, self.dbg.SetErrorFile, "ham sandwich")
+ self.assertRaises(Exception, self.dbg.SetErrorFileHandle, "ham sandwich")
with open(self.out_filename, 'w') as f:
- status = self.debugger.SetOutputFile(f)
+ status = self.dbg.SetOutputFile(f)
self.assertTrue(status.Success())
- status = self.debugger.SetErrorFile(f)
+ status = self.dbg.SetErrorFile(f)
self.assertTrue(status.Success())
- self.debugger.SetOutputFileHandle(None, False)
- self.debugger.SetErrorFileHandle(None, False)
- sbf = self.debugger.GetOutputFile()
+ self.dbg.SetOutputFileHandle(None, False)
+ self.dbg.SetErrorFileHandle(None, False)
+ sbf = self.dbg.GetOutputFile()
if sys.version_info.major >= 3:
# python 2 lacks PyFile_FromFd, so GetFile() will
# have to duplicate the file descriptor and make a FILE*
# in order to convert a NativeFile it back to a python
# file.
self.assertEqual(sbf.GetFile().fileno(), 1)
- sbf = self.debugger.GetErrorFile()
+ sbf = self.dbg.GetErrorFile()
if sys.version_info.major >= 3:
self.assertEqual(sbf.GetFile().fileno(), 2)
with open(self.out_filename, 'r') as f:
- status = self.debugger.SetInputFile(f)
+ status = self.dbg.SetInputFile(f)
self.assertTrue(status.Success())
- self.debugger.SetInputFileHandle(None, False)
- sbf = self.debugger.GetInputFile()
+ self.dbg.SetInputFileHandle(None, False)
+ sbf = self.dbg.GetInputFile()
if sys.version_info.major >= 3:
self.assertEqual(sbf.GetFile().fileno(), 0)