summaryrefslogtreecommitdiff
path: root/lldb/scripts/Python/python-typemaps.swig
AgeCommit message (Collapse)Author
2020-01-09[lldb/Bindings] Move bindings into their own subdirectoryJonas Devlieghere
All the code required to generate the language bindings for Python and Lua lives under scripts, even though the majority of this code aren't scripts at all, and surrounded by scripts that are totally unrelated. I've reorganized these files and moved everything related to the language bindings into a new top-level directory named bindings. This makes the corresponding files self contained and much more discoverable. Differential revision: https://reviews.llvm.org/D72437
2019-10-22remove multi-argument form of PythonObject::Reset()Lawrence D'Anna
Summary: With this patch, only the no-argument form of `Reset()` remains in PythonDataObjects. It also deletes PythonExceptionState in favor of PythonException, because the only call-site of PythonExceptionState was also using Reset, so I cleaned up both while I was there. Reviewers: JDevlieghere, clayborg, labath, jingham Reviewed By: labath Subscribers: mgorny, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D69214 llvm-svn: 375475
2019-10-17delete SWIG typemaps for FILE*Lawrence D'Anna
Summary: The SWIG typemaps for FILE* are no longer used, so this patch deletes them. Reviewers: JDevlieghere, jasonmolenda, labath Reviewed By: labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D68963 llvm-svn: 375073
2019-10-15SBFile::GetFile: convert SBFile back into python native files.Lawrence D'Anna
Summary: This makes SBFile::GetFile public and adds a SWIG typemap to convert the result back into a python native file. If the underlying File itself came from a python file, it is returned identically. Otherwise a new python file object is created using the file descriptor. Reviewers: JDevlieghere, jasonmolenda, labath Reviewed By: labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D68737 llvm-svn: 374911
2019-10-09SBFile: add a bunch of tests that should eventually work.Lawrence D'Anna
Summary: It's really annoying and confusing to have to keep referring back to earlier versions of this SBFile work to find the tests that need to be added for each patch, and not duplicate them with new tests. This patch just imports all my tests. A bunch of them don't work yet, so they are marked to be skipped. They'll be unmarked as I fix them. One of these tests will actually trip an assert in the SWIG code now instead of just failing, so I'm fixing that here too. Reviewers: JDevlieghere, jasonmolenda, labath Reviewed By: JDevlieghere, labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D68433 llvm-svn: 374237
2019-10-09allow arbitrary python streams to be converted to SBFileLawrence D'Anna
Summary: This patch adds SWIG typemaps that can convert arbitrary python file objects into lldb_private::File. A SBFile may be initialized from a python file using the constructor. There are also alternate, tagged constructors that allow python files to be borrowed, and for the caller to control whether or not the python I/O methods will be called even when a file descriptor is available.I Reviewers: JDevlieghere, jasonmolenda, labath Reviewed By: labath Subscribers: zturner, amccarth, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D68188 llvm-svn: 374225
2019-10-03"Fix" TestFileHandle.py on non-darwin platformsPavel Labath
This test exposed a very long standing issue that the python file objects returned by the FILE* typemap were unusable on non-darwin platforms. The reason they work on darwin is that they rely on a non-standard extension to fetch the "mode" of a FILE* object. On other platforms, this code was #ifdefed out, and so we were returning an empty mode. As there's no portable way to get this information, I just change the non-darwin path to return "r+", which should permit both reading and writing operations on the object. If the underlying file descriptor turns out to be incompatible with this mode, the operating system should return EBADF (or equivalent), instead of the "file not open for XXX" error from python. llvm-svn: 373573
2019-10-03factor out an abstract base class for FileLawrence D'Anna
Summary: This patch factors out File as an abstract base class and moves most of its actual functionality into a subclass called NativeFile. In the next patch, I'm going to be adding subclasses of File that don't necessarily have any connection to actual OS files, so they will not inherit from NativeFile. This patch was split out as a prerequisite for https://reviews.llvm.org/D68188 Reviewers: JDevlieghere, jasonmolenda, labath Reviewed By: labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D68317 llvm-svn: 373564
2019-10-03new api class: SBFileLawrence D'Anna
Summary: SBFile is a scripting API wrapper for lldb_private::File This is the first step in a project to enable arbitrary python io.IOBase file objects -- including those that override the read() and write() methods -- to be used as the main debugger IOStreams. Currently this is impossible because python file objects must first be converted into FILE* streams by SWIG in order to be passed into the debugger. full prototype: https://github.com/smoofra/llvm-project/tree/files Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath Reviewed By: labath Subscribers: labath, mgorny, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D67793 llvm-svn: 373562
2019-10-01File::Clear() -> File::TakeStreamAndClear()Lawrence D'Anna
Summary: File::Clear() is an ugly function. It's only used in one place, which is the swig typemaps for FILE*. This patch refactors and renames that function to make it clear what it's really for and why nobody else should use it. Both File::TakeStreamAndClear() and the FILE* typemaps will be removed in later patches after a suitable replacement is in place. Reviewers: JDevlieghere, jasonmolenda, labath Reviewed By: labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D68160 llvm-svn: 373285
2019-09-26Convert FileSystem::Open() to return Expected<FileUP>Lawrence D'Anna
Summary: This patch converts FileSystem::Open from this prototype: Status Open(File &File, const FileSpec &file_spec, ...); to this one: llvm::Expected<std::unique_ptr<File>> Open(const FileSpec &file_spec, ...); This is beneficial on its own, as llvm::Expected is a more modern and recommended error type than Status. It is also a necessary step towards https://reviews.llvm.org/D67891, and further developments for lldb_private::File. Reviewers: JDevlieghere, jasonmolenda, labath Reviewed By: labath Subscribers: mgorny, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D67996 llvm-svn: 373003
2019-03-28Fix the swig typemap for "uint32_t *versions, uint32_t num_versions".Jim Ingham
It was making a list of a certain size but not always filling in that many elements, which would lead to a crash iterating over the list. Differential Revision: https://reviews.llvm.org/D59913 llvm-svn: 357207
2018-09-25[Swig] Merge typemaps with same bodiesTatyana Krasnukha
Differential Revision: https://reviews.llvm.org/D52376 llvm-svn: 342959
2018-09-11Remove undefined behavior around the use of StateTypeShafik Yaghmour
rdar://problem/43530233 Patch by Shafik Yaghmour. Differential Revision: https://reviews.llvm.org/D51445 llvm-svn: 341957
2017-12-22Change SBProcess::ReadCStringFromMemory() back to returningJason Molenda
an empty Python string object when it reads a 0-length string out of memory (and a successful SBError object). <rdar://problem/26186692> llvm-svn: 321338
2016-04-08Fix #ifdef __APPLE__ code is the swig Python bindingsTodd Fiala
This code was getting evaluated unintentionally at binding generation time instead of binding file compilation time. Addresses: https://bugs.swift.org/browse/SR-1192 llvm-svn: 265829
2016-03-11Check for a NULL input filehandle before referencing it.Jim Ingham
<rdar://problem/25105824> llvm-svn: 263274
2016-03-11Fix SBDebugger.GetOutputFileHandle() on OS X.Jim Ingham
The swig typemaps had some magic for output File *'s on OS X that made: SBDebugger.GetOutputFileHandle() actually work. That was protected by a "#ifdef __MACOSX__", but the corresponding define got lost going from the Darwin shell scripts to the python scripts for running swig, so the code was elided. I need to pass the define to SWIG, but only when targetting Darwin. So I added a target-platform argument to prepare_bindings, and if that is Darwin, I pass -D__APPLE__ to swig, and that activates this code again, and GetOutputFileHandle works again. Note, I only pass that argument for the Xcode build. I'm sure it is possible to do that for cmake, but my cmake-foo is weak. I should have been able to write a test for this by creating a debugger, setting the output file handle to something file, writing to it, getting the output file handle and reading it. But SetOutputFileHandle doesn't seem to work from Python, so I'd have to write a pexpect test to test this, which I'd rather not do. llvm-svn: 263183
2016-01-25Fix some issues with bytes and strings in Python 3.Zachary Turner
SBProcess::ReadMemory and other related functions such as WriteMemory are returning Python string() objects. This means that in Python 3 that are returning Unicode objects. In reality they should be returning bytes objects which is the same as a string in Python 2, but different in Python 3. This patch updates the generated SWIG code to return Python bytes objects for all memory related functions. One quirk of this patch is that the C++ signature of ReadCStringFromMemory has it writing c-string data into a void*. This confuses our swig typemaps which expect that a void* means byte data. So I hacked up a custom typemap which maps this specific function to treat the void* as string data instead of byte data. llvm-svn: 258743
2016-01-25Fix more occurrences of string/bytes/bytearray in swig typemaps.Zachary Turner
llvm-svn: 258742
2016-01-25Fix swig typemap for SBEvent.Zachary Turner
This needs to be able to handle bytes, strings, and bytearray objects. In Python 2 this was easy because bytes and strings are the same thing, but in Python 3 the 2 cases need to be handled separately. So as not to mix raw Python C API code with PythonDataObjects code, I've also introduced a PythonByteArray class to PythonDataObjects to make the paradigm used here consistent. llvm-svn: 258741
2016-01-13Get rid of const char** typemaps.Zachary Turner
We already have char** typemaps which were near copy-pastes of the const char** versions. This way we have only one version that works for both. llvm-svn: 257670
2016-01-13Fix TestProcessLaunch for Python 3.Zachary Turner
There were a number of problems preventing this from working: 1. The SWIG typemaps for converting Python lists to and from C++ arrays were not updated for Python 3. So they were doing things like PyString_Check instead of using the PythonString from PythonDataObjects. 2. ProcessLauncherWindows was ignoring the environment completely. So any test that involved launching an inferior with any kind of environment variable would have failed. 3. The test itself was using process.GetSTDOUT(), which isn't implemented on Windows. So this was changed to save the value of the environment variable in a local variable and have the debugger look at the value of the variable. llvm-svn: 257669
2016-01-13Fix an issue where scripted commands would not actually print any of their ↵Enrico Granata
output if an immediate output file was set in the result object via a Python file object Fixes rdar://24130303 llvm-svn: 257644
2016-01-11Fix Python 3 issues related to OS plugins.Zachary Turner
* lldb::tid_t was being converted incorrectly, so this is updated to use PythonInteger instead of manual Python Native API calls. * OSPlugin_RegisterContextData was assuming that the result of get_register_data was a string, when in fact it is a bytes. So this method is updated to use PythonBytes to do the work. llvm-svn: 257398
2015-11-18Fix some issues with swig & string conversion.Zachary Turner
This patch fixes two issues: 1) Popen needs to be used with universal_newlines=True by default. This elicits automatic decoding from bytes -> string in Py3, and has no negative effects in other Py versions. 2) The swig typemaps for converting between string and (char*, int) did not work correctly when the length of the string was 0, indicating an error. In this case we would try to construct a string from uninitialized data. 3) Ironically, the bug mentioned in #2 led to a test passing on Windows that was actually broken, because the test was written such that the assertion was never even getting checked, so it passed by default. So we additionally fix this test to also fail if the method errors. By fixing this test it's now broken on Windows, so we also xfail it. llvm-svn: 253487
2015-11-16Python3 - Fix some issues related to `PythonFile` class.Zachary Turner
Python 3 has lots of new debug asserts, and some of these were firing on PythonFile. Specifically related to handling of invalid files. llvm-svn: 253261
2015-10-16Convert SWIG typemap string operations to PythonObjects.Zachary Turner
llvm-svn: 250530
2015-10-16Update SWIG typemaps to use `PythonFile`.Zachary Turner
Using the Python native C API is non-portable across Python versions, so this patch changes them to use the `PythonFile` class which hides the version specific differences behind a single interface. llvm-svn: 250525
2015-10-14Change swig interface files to use PythonDataObjects.Zachary Turner
llvm-svn: 250303
2015-09-04Convert "long" input to "long long" in typemap for lldb::tid_t.Siva Chandra
Summary: lldb::tid_t is 64 bit, but "long" need not always be 64 bit. Reviewers: chying, clayborg Subscribers: lldb-commits Differential Revision: http://reviews.llvm.org/D12650 llvm-svn: 246885
2015-09-02We want Python int or long to both be usable as-a tid_t for API purposes. ↵Enrico Granata
Introduce a typemap to this effect llvm-svn: 246709
2015-07-01[Python] Allow PyLong values in integer lists (when converting to C lists)Siva Chandra
Test Plan: dotest.py -p TestSBData Reviewers: clayborg, granata.enrico Reviewed By: clayborg, granata.enrico Subscribers: lldb-commits Differential Revision: http://reviews.llvm.org/D10821 llvm-svn: 241208
2014-10-21Add typemaps to handle the transformation of Python list of strings into a ↵Enrico Granata
'char const **'. This fixes zephyr's issue with SBTarget::Launch without splitting the API into multiple names llvm-svn: 220306
2014-01-27Merging the iohandler branch back into main. Greg Clayton
The many many benefits include: 1 - Input/Output/Error streams are now handled as real streams not a push style input 2 - auto completion in python embedded interpreter 3 - multi-line input for "script" and "expression" commands now allow you to edit previous/next lines using up and down arrow keys and this makes multi-line input actually a viable thing to use 4 - it is now possible to use curses to drive LLDB (please try the "gui" command) We will need to deal with and fix any buildbot failures and tests and arise now that input/output and error are correctly hooked up in all cases. llvm-svn: 200263
2014-01-09Patch by Ari GrantEnrico Granata
"Open LLDB and run: (lldb) script print lldb.debugger.GetInputFileHandle() This puts the debugger into a catatonic state and all interactions seem to enter a black hole. The reason is that executing this commnand actually *CLOSES* the input file handle and so all input is dropped on the floor. Oof! The fix is simple: flush a descriptor, instead of closing it, when transferring ownership." llvm-svn: 198835
2013-06-19Sort out a number of mismatched integer types in order to cut down the ↵Andy Gibbs
number of compiler warnings. llvm-svn: 184333
2013-05-02<rdar://problem/13499317>Enrico Granata
Enabling Python commands to produce Unicode output via: result.PutCString(u”whatever”) llvm-svn: 180930
2012-10-29Ensuring that the swig typemaps for SBData set the size to 0 along with the ↵Enrico Granata
pointer to NULL There should be no functional changes as SBData creation functions already checked for NULL regardless of size - but it ensures consistency llvm-svn: 166978
2012-08-28Simplify the typecheck code.Filipe Cabecinhas
llvm-svn: 162753
2012-08-25Added SBDebugger's log callbacks to Python-landFilipe Cabecinhas
- Tweaked a parameter name in SBDebugger.h so my typemap will catch it; - Added a SBDebugger.Create(bool, callback, baton) to the swig interface; - Added SBDebugger.SetLoggingCallback to the swig interface; - Added a callback utility function for log callbacks; - Guard against Py_None on both callback utility functions; - Added a FIXME to the SBDebugger API test; - Added a __del__() stub for SBDebugger. We need to be able to get both the log callback and baton from an SBDebugger if we want to protect against memory leaks (or make the user responsible for holding another reference to the callback). Additionally, it's impossible to revert from a callback-backed log mechanism to a file-backed log mechanism. llvm-svn: 162633
2012-08-22Added a typemap and wrappers for SBInputReader callbacksFilipe Cabecinhas
Now it's possible to use SBInputReader callbacks in Python. We leak the callback object, unfortunately. A __del__ method can be added to SBInputReader, but we have no way to check the callback function that is on the reader. So we can't call Py_DECREF on it when we have our PythonCallback function. One way to do it is to assume that reified SBInputReaders always have a Python callback (and always call Py_DECREF). Another one is to add methods or properties to SBInputReader (or make the m_callback_function property public). llvm-svn: 162356
2012-08-20Fix a crash (_wrap_SBDebugger_SetInputFileHandle -> PyString_AsString) ↵Johnny Chen
running the test suite. Also modify the boundary condition test case SBDebugger.DispatchInput(None) to be wrapped inside a try-except clause for now. llvm-svn: 162228
2012-08-20A baton isn't needed to dispatch input.Filipe Cabecinhas
I also added a typemap to make DispatchInput usable in Python. llvm-svn: 162204
2012-08-20Add FILE* typemaps for SBDebugger.GetInputFileHandle() and friends.Filipe Cabecinhas
llvm-svn: 162203
2012-05-11Fix SBProcess::ReadMemory's typemap to handle PyLongObjects.Filipe Cabecinhas
llvm-svn: 156638
2012-02-23typemaps to allow Python to invoke the new SBModule::GetVersion() API. ↵Enrico Granata
Memory management is taken care of automatically so that Python users can simply say my_list = my_module.GetVersion() and receive a new list with the version numbers, if any, inside. llvm-svn: 151271
2012-01-06http://llvm.org/bugs/show_bug.cgi?id=11619Johnny Chen
Allow creating SBData values from arrays or primitives in Python Patch submitted by Enrico Granata. llvm-svn: 147639
2011-12-14I have added a function to SBTarget that allowsSean Callanan
clients to disassemble a series of raw bytes as demonstrated by a new testcase. In the future, this API will also allow clients to provide a callback that adds comments for addresses in the disassembly. I also modified the SWIG harness to ensure that Python ByteArrays work as well as strings as sources of raw data. llvm-svn: 146611
2011-11-28SBProcess.PutSTDIN() needs to be properly typemapped when swigging,Johnny Chen
so that we can do Python scripting like this: target = self.dbg.CreateTarget(self.exe) self.dbg.SetAsync(True) process = target.LaunchSimple(None, None, os.getcwd()) process.PutSTDIN("Line 1 Entered.\n") process.PutSTDIN("Line 2 Entered.\n") process.PutSTDIN("Line 3 Entered.\n") Add TestProcessIO.py to exercise the process IO API: PutSTDIN()/GetSTDOUT()/GetSTDERR(). llvm-svn: 145282