示例#1
0
 def test_string_inout(self):
     inf = io.StringIO("help help\np/x ~0\n")
     outf = io.StringIO()
     status = self.dbg.SetOutputFile(lldb.SBFile(outf))
     self.assertSuccess(status)
     status = self.dbg.SetInputFile(lldb.SBFile(inf))
     self.assertSuccess(status)
     opts = lldb.SBCommandInterpreterRunOptions()
     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)
示例#2
0
    def test_set_sbstream(self):
        with open(self.out_filename, 'w') as outf:
            outsbf = lldb.SBFile(outf.fileno(), "w", False)
            status = self.dbg.SetOutputFile(outsbf)
            self.assertSuccess(status)
            self.dbg.SetInputString("help apropos\nhelp help\n")

            opts = lldb.SBCommandInterpreterRunOptions()
            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)
            self.assertIn('List debugger commands related to a word', output)
示例#3
0
 def test_binary_inout(self):
     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 = self.dbg.SetOutputFile(lldb.SBFile(outf))
         self.assertSuccess(status)
         status = self.dbg.SetInputFile(lldb.SBFile(inf))
         self.assertSuccess(status)
         opts = lldb.SBCommandInterpreterRunOptions()
         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)
示例#4
0
    def test_fileno_inout(self):
        with open(self.in_filename, 'w') as f:
            f.write("help help\n")

        with open(self.out_filename, 'w') as outf, open(self.in_filename, 'r') as inf:

            outsbf = lldb.SBFile(outf.fileno(), "w", False)
            status = self.dbg.SetOutputFile(outsbf)
            self.assertSuccess(status)

            insbf = lldb.SBFile(inf.fileno(), "r", False)
            status = self.dbg.SetInputFile(insbf)
            self.assertSuccess(status)

            opts = lldb.SBCommandInterpreterRunOptions()
            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()))
示例#5
0
 def execute_command_in_frame(self, command, frame):
     # set up evaluation context
     if frame is not None:
         self.set_selected_frame(frame)
     # evaluate
     interp = self.debugger.GetCommandInterpreter()
     result = lldb.SBCommandReturnObject()
     if '\n' not in command:
         interp.HandleCommand(to_lldb_str(command), result)
     else:
         # multiline command
         tmp_file = tempfile.NamedTemporaryFile()
         log.info('multiline command in %s', tmp_file.name)
         tmp_file.write(to_lldb_str(command))
         tmp_file.flush()
         filespec = lldb.SBFileSpec()
         filespec.SetDirectory(os.path.dirname(tmp_file.name))
         filespec.SetFilename(os.path.basename(tmp_file.name))
         context = lldb.SBExecutionContext(frame)
         options = lldb.SBCommandInterpreterRunOptions()
         interp.HandleCommandsFromFile(filespec, context, options, result)
     sys.stdout.flush()
     return result