diff options
-rw-r--r-- | lldb/scripts/Python/interface/SBCommandInterpreter.i | 2 | ||||
-rw-r--r-- | lldb/scripts/Python/interface/SBProcess.i | 4 | ||||
-rw-r--r-- | lldb/scripts/Python/python-typemaps.swig | 9 | ||||
-rw-r--r-- | lldb/test/python_api/default-constructor/sb_process.py | 2 | ||||
-rw-r--r-- | lldb/test/python_api/process/io/Makefile | 6 | ||||
-rw-r--r-- | lldb/test/python_api/process/io/TestProcessIO.py | 66 | ||||
-rw-r--r-- | lldb/test/python_api/process/io/main.c | 12 |
7 files changed, 100 insertions, 1 deletions
diff --git a/lldb/scripts/Python/interface/SBCommandInterpreter.i b/lldb/scripts/Python/interface/SBCommandInterpreter.i index 6a5ee2466b0..ec9e51c561a 100644 --- a/lldb/scripts/Python/interface/SBCommandInterpreter.i +++ b/lldb/scripts/Python/interface/SBCommandInterpreter.i @@ -99,8 +99,10 @@ public: lldb::SBProcess GetProcess (); +#if 0 ssize_t WriteToScriptInterpreter (const char *src); +#endif ssize_t WriteToScriptInterpreter (const char *src, size_t src_len); diff --git a/lldb/scripts/Python/interface/SBProcess.i b/lldb/scripts/Python/interface/SBProcess.i index 531cd5903cf..b2ab9231a26 100644 --- a/lldb/scripts/Python/interface/SBProcess.i +++ b/lldb/scripts/Python/interface/SBProcess.i @@ -64,6 +64,10 @@ public: lldb::ByteOrder GetByteOrder() const; + %feature("autodoc", " + Writes data into the current process's stdin. API client specifies a Python + string as the only argument. + ") PutSTDIN; size_t PutSTDIN (const char *src, size_t src_len); diff --git a/lldb/scripts/Python/python-typemaps.swig b/lldb/scripts/Python/python-typemaps.swig index 5fbe161aa4c..55f2819ce0c 100644 --- a/lldb/scripts/Python/python-typemaps.swig +++ b/lldb/scripts/Python/python-typemaps.swig @@ -76,6 +76,15 @@ $1 = (char *) PyString_AsString($input); $2 = PyString_Size($input); } +// Ditto for SBProcess::PutSTDIN(const char *src, size_t src_len). +%typemap(in) (const char *src, size_t src_len) { + if (!PyString_Check($input)) { + PyErr_SetString(PyExc_ValueError, "Expecting a string"); + return NULL; + } + $1 = (char *) PyString_AsString($input); + $2 = PyString_Size($input); +} // And SBProcess::WriteMemory. %typemap(in) (const void *buf, size_t size) { if (!PyString_Check($input)) { diff --git a/lldb/test/python_api/default-constructor/sb_process.py b/lldb/test/python_api/default-constructor/sb_process.py index 4f892e57f14..f74df33ce10 100644 --- a/lldb/test/python_api/default-constructor/sb_process.py +++ b/lldb/test/python_api/default-constructor/sb_process.py @@ -8,7 +8,7 @@ import lldb def fuzz_obj(obj): obj.GetTarget() obj.GetByteOrder() - obj.PutSTDIN("my data", 7) + obj.PutSTDIN("my data") obj.GetSTDOUT(6) obj.GetSTDERR(6) event = lldb.SBEvent() diff --git a/lldb/test/python_api/process/io/Makefile b/lldb/test/python_api/process/io/Makefile new file mode 100644 index 00000000000..5361f2a5bbe --- /dev/null +++ b/lldb/test/python_api/process/io/Makefile @@ -0,0 +1,6 @@ +LEVEL = ../../../make + +C_SOURCES := main.c +EXE := process_io + +include $(LEVEL)/Makefile.rules diff --git a/lldb/test/python_api/process/io/TestProcessIO.py b/lldb/test/python_api/process/io/TestProcessIO.py new file mode 100644 index 00000000000..8c494d15174 --- /dev/null +++ b/lldb/test/python_api/process/io/TestProcessIO.py @@ -0,0 +1,66 @@ +"""Test Python APIs for process IO.""" + +import os, sys, time +import unittest2 +import lldb +from lldbtest import * + +class ProcessIOTestCase(TestBase): + + mydir = os.path.join("python_api", "process", "io") + + @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") + @python_api_test + def test_put_stdin_with_dsym(self): + """Exercise SBProcess.PutSTDIN().""" + self.buildDsym() + self.put_stdin() + + @python_api_test + def test_put_stdin_with_dwarf(self): + """Exercise SBProcess.PutSTDIN().""" + self.buildDwarf() + self.put_stdin() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Get the full path to our executable to be debugged. + self.exe = os.path.join(os.getcwd(), "process_io") + + def put_stdin(self): + """Launch a process and use SBProcess.PutSTDIN() to write data to it.""" + + target = self.dbg.CreateTarget(self.exe) + + self.dbg.SetAsync(True) + process = target.LaunchSimple(None, None, os.getcwd()) + if self.TraceOn(): + print "process launched." + + self.assertTrue(process, PROCESS_IS_VALID) + + process.PutSTDIN("Line 1 Entered.\n") + process.PutSTDIN("Line 2 Entered.\n") + process.PutSTDIN("Line 3 Entered.\n") + + for i in range(5): + output = process.GetSTDOUT(500) + error = process.GetSTDERR(500) + if self.TraceOn(): + print "output->|%s|" % output + print "error->|%s|" % error + # We are satisfied once "input line=>1" appears in stderr. + # See also main.c. + #if "input line=>1" in error: + if "input line=>1" in output: + return + time.sleep(5) + + self.fail("Expected output form launched process did not appear?") + +if __name__ == '__main__': + import atexit + lldb.SBDebugger.Initialize() + atexit.register(lambda: lldb.SBDebugger.Terminate()) + unittest2.main() diff --git a/lldb/test/python_api/process/io/main.c b/lldb/test/python_api/process/io/main.c new file mode 100644 index 00000000000..a3d95fe12af --- /dev/null +++ b/lldb/test/python_api/process/io/main.c @@ -0,0 +1,12 @@ +#include <stdio.h> + +int main(int argc, char const *argv[]) { + printf("Hello world.\n"); + char line[100]; + int count = 1; + while (fgets(line, sizeof(line), stdin)) { // Reading from stdin... + fprintf(stderr, "input line=>%d\n", count++); + } + + printf("Exiting now\n"); +} |