lawrence_danna created this revision.
lawrence_danna added reviewers: JDevlieghere, jasonmolenda, labath.
Herald added a project: LLDB.
lawrence_danna added a parent revision: D68433: SBFile: add a bunch of tests 
that should eventually work..

This patch adds FileSP versions of SetInputFile(),
SetOutputFile, and SetErrorFile().   SWIG will convert native
python file objects into FileSP.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68734

Files:
  lldb/include/lldb/API/SBDebugger.h
  lldb/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py
  lldb/scripts/interface/SBDebugger.i
  lldb/source/API/SBDebugger.cpp

Index: lldb/source/API/SBDebugger.cpp
===================================================================
--- lldb/source/API/SBDebugger.cpp
+++ lldb/source/API/SBDebugger.cpp
@@ -292,6 +292,11 @@
   SetInputFile((FileSP)std::make_shared<NativeFile>(fh, transfer_ownership));
 }
 
+SBError SBDebugger::SetInputFile(FileSP file_sp) {
+  LLDB_RECORD_METHOD(SBError, SBDebugger, SetInputFile, (FileSP), file_sp);
+  return SetInputFile(SBFile(file_sp));
+}
+
 // Shouldn't really be settable after initialization as this could cause lots
 // of problems; don't want users trying to switch modes in the middle of a
 // debugging session.
@@ -332,6 +337,11 @@
   return error;
 }
 
+SBError SBDebugger::SetOutputFile(FileSP file_sp) {
+  LLDB_RECORD_METHOD(SBError, SBDebugger, SetOutputFile, (FileSP), file_sp);
+  return SetOutputFile(SBFile(file_sp));
+}
+
 void SBDebugger::SetOutputFileHandle(FILE *fh, bool transfer_ownership) {
   LLDB_RECORD_METHOD(void, SBDebugger, SetOutputFileHandle, (FILE *, bool), fh,
                      transfer_ownership);
@@ -359,6 +369,11 @@
   SetErrorFile((FileSP)std::make_shared<NativeFile>(fh, transfer_ownership));
 }
 
+SBError SBDebugger::SetErrorFile(FileSP file_sp) {
+  LLDB_RECORD_METHOD(SBError, SBDebugger, SetErrorFile, (FileSP), file_sp);
+  return SetErrorFile(SBFile(file_sp));
+}
+
 SBError SBDebugger::SetErrorFile(SBFile file) {
   LLDB_RECORD_METHOD(SBError, SBDebugger, SetErrorFile, (SBFile file), file);
   SBError error;
@@ -1601,6 +1616,8 @@
 
 static SBError SetFileRedirect(SBDebugger *, SBFile file) { return SBError(); }
 
+static SBError SetFileRedirect(SBDebugger *, FileSP file) { return SBError(); }
+
 static bool GetDefaultArchitectureRedirect(char *arch_name,
                                            size_t arch_name_len) {
   // The function is writing to its argument. Without the redirect it would
@@ -1631,6 +1648,16 @@
                  SBFile)>::method<&SBDebugger::SetErrorFile>::doit,
              &SetFileRedirect);
 
+  R.Register(&invoke<SBError (SBDebugger::*)(
+                 FileSP)>::method<&SBDebugger::SetInputFile>::doit,
+             &SetFileRedirect);
+  R.Register(&invoke<SBError (SBDebugger::*)(
+                 FileSP)>::method<&SBDebugger::SetOutputFile>::doit,
+             &SetFileRedirect);
+  R.Register(&invoke<SBError (SBDebugger::*)(
+                 FileSP)>::method<&SBDebugger::SetErrorFile>::doit,
+             &SetFileRedirect);
+
   LLDB_REGISTER_CONSTRUCTOR(SBDebugger, ());
   LLDB_REGISTER_CONSTRUCTOR(SBDebugger, (const lldb::DebuggerSP &));
   LLDB_REGISTER_CONSTRUCTOR(SBDebugger, (const lldb::SBDebugger &));
Index: lldb/scripts/interface/SBDebugger.i
===================================================================
--- lldb/scripts/interface/SBDebugger.i
+++ lldb/scripts/interface/SBDebugger.i
@@ -165,21 +165,27 @@
     void
     SkipLLDBInitFiles (bool b);
 
+    %feature("autodoc", "DEPRECATED, use SetInputFile");
     void
     SetInputFileHandle (FILE *f, bool transfer_ownership);
 
+    %feature("autodoc", "DEPRECATED, use SetOutputFile");
     void
     SetOutputFileHandle (FILE *f, bool transfer_ownership);
 
+    %feature("autodoc", "DEPRECATED, use SetErrorFile");
     void
     SetErrorFileHandle (FILE *f, bool transfer_ownership);
 
+    %feature("autodoc", "DEPRECATED, use GetInputFile");
     FILE *
     GetInputFileHandle ();
 
+    %feature("autodoc", "DEPRECATED, use GetOutputFile");
     FILE *
     GetOutputFileHandle ();
 
+    %feature("autodoc", "DEPRECATED, use GetErrorFile");
     FILE *
     GetErrorFileHandle ();
 
@@ -192,6 +198,15 @@
     SBError
     SetErrorFile (SBFile file);
 
+    SBError
+    SetInputFile (FileSP file);
+
+    SBError
+    SetOutputFile (FileSP file);
+
+    SBError
+    SetErrorFile (FileSP file);
+
     SBFile
     GetInputFile ();
 
Index: lldb/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py
+++ lldb/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py
@@ -551,7 +551,6 @@
 
     @add_test_categories(['pyapi'])
     @skipIf(py_version=['<', (3,)])
-    @expectedFailure # fixme multiple problems with this
     def test_string_out(self):
         f = io.StringIO()
         status = self.debugger.SetOutputFile(f)
@@ -561,7 +560,6 @@
 
 
     @add_test_categories(['pyapi'])
-    @expectedFailure # FIXME need FileSP version of SBDebugger::SetErrorFile
     @skipIf(py_version=['<', (3,)])
     def test_string_error(self):
         f = io.StringIO()
@@ -632,7 +630,6 @@
 
 
     @add_test_categories(['pyapi'])
-    @expectedFailure # FIXME need FileSP version of SBDebugger::SetErrorFile
     @skipIf(py_version=['<', (3,)])
     def test_file_out(self):
         with open(self.out_filename, 'w') as f:
@@ -656,7 +653,6 @@
 
 
     @add_test_categories(['pyapi'])
-    @expectedFailure # FIXME need FileSP version of SBDebugger::SetErrorFile
     def test_file_error(self):
         with open(self.out_filename, 'w') as f:
             status = self.debugger.SetErrorFile(f)
@@ -748,7 +744,6 @@
 
 
     @add_test_categories(['pyapi'])
-    @expectedFailure # FIXME need FileSP version of SBDebugger::SetOutputFile
     def test_close(self):
         debugger = self.debugger
         with open(self.out_filename, 'w') as f:
@@ -769,7 +764,6 @@
 
     @add_test_categories(['pyapi'])
     @skipIf(py_version=['<', (3,)])
-    @expectedFailure # FIXME need FileSP version of SBDebugger::SetOutputFile
     def test_stdout(self):
         f = io.StringIO()
         status = self.debugger.SetOutputFile(f)
Index: lldb/include/lldb/API/SBDebugger.h
===================================================================
--- lldb/include/lldb/API/SBDebugger.h
+++ lldb/include/lldb/API/SBDebugger.h
@@ -94,6 +94,12 @@
 
   SBError SetErrorFile(SBFile file);
 
+  SBError SetInputFile(FileSP file);
+
+  SBError SetOutputFile(FileSP file);
+
+  SBError SetErrorFile(FileSP file);
+
   SBFile GetInputFile();
 
   SBFile GetOutputFile();
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to