summaryrefslogtreecommitdiffstats
path: root/lldb/unittests/ScriptInterpreter
Commit message (Collapse)AuthorAgeFilesLines
* [Lldb/Lua] Generate Lua BindingsJonas Devlieghere2019-12-211-0/+2
| | | | | | | | | | | This patch uses SWIG to generate the Lua bindings for the SB API. It covers most of the API, but some methods require a type map similar to Python. Discussion on the mailing list: http://lists.llvm.org/pipermail/lldb-dev/2019-December/015812.html Differential revision: https://reviews.llvm.org/D71235
* [lldb/Lua] Implement a Simple Lua Script Interpreter PrototypeJonas Devlieghere2019-12-204-0/+103
| | | | | | | | | | | | | | | This implements a very elementary Lua script interpreter. It supports running a single command as well as running interactively. It uses editline if available. It's still missing a bunch of stuff though. Some things that I intentionally ingored for now are that I/O isn't properly hooked up (so every print goes to stdout) and the non-editline support which is not handling a bunch of corner cases. The latter is a matter of reusing existing code in the Python interpreter. Discussion on the mailing list: http://lists.llvm.org/pipermail/lldb-dev/2019-December/015812.html Differential revision: https://reviews.llvm.org/D71234
* [lldb/CMake] Rename LLDB_DISABLE_PYTHON to LLDB_ENABLE_PYTHONJonas Devlieghere2019-12-131-1/+1
| | | | | | | This matches the naming scheme used by LLVM and all the other optional dependencies in LLDB. Differential revision: https://reviews.llvm.org/D71482
* [LLDB] Disable MSVC warning C4190: ↵Alexandre Ganea2019-12-031-0/+12
| | | | | | 'LLDBSwigPythonBreakpointCallbackFunction' has C-linkage specified, but returns UDT 'llvm::Expected<bool>' which is incompatible with C Differential Revision: https://reviews.llvm.org/D70830
* [LLDB][Python] remove ArgInfo::countLawrence D'Anna2019-11-041-19/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch updates the last user of ArgInfo::count and deletes it. I also delete `GetNumInitArguments()` and `GetInitArgInfo()`. Classess are callables and `GetArgInfo()` should work on them. On python 3 it already works, of course. `inspect` is good. On python 2 we have to add yet another special case. But hey if python 2 wasn't crufty we wouln't need python 3. I also delete `is_bound_method` becuase it is unused. This path is tested in `TestStepScripted.py` Reviewers: labath, mgorny, JDevlieghere Reviewed By: labath, JDevlieghere Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D69742
* [LLDB][Python] warning fix for LLDBSwigPythonBreakpointCallbackFunctionLawrence D'Anna2019-10-301-0/+5
| | | | | | | | | | | | | | | | | | This is a quick followup to this commit: https://reviews.llvm.org/rGa69bbe02a2352271e8b14542073f177e24c499c1 In that, I #pragma-squelch this warning in `ScriptInterpreterPython.cpp` but we get the same warning in `PythonTestSuite.cpp`. This patch squelches the same warning in the same way as the reviweed commit. I'm submitting it without review under the "obviously correct" rule. At least if this is incorrect the main commit was also incorrect. By the way, as far as I can tell, these functions are extern "C" because SWIG does that to everything, not because they particularly need to be.
* [LLDB][breakpoints] ArgInfo::count -> ArgInfo::max_positional_argsLawrence D'Anna2019-10-291-1/+1
| | | | | | | | | | | | | | | | | | | | Summary: Move breakpoints from the old, bad ArgInfo::count to the new, better ArgInfo::max_positional_args. Soon ArgInfo::count will be no more. It looks like this functionality is already well tested by `TestBreakpointCommandsFromPython.py`, so there's no need to write additional tests for it. Reviewers: labath, jingham, JDevlieghere Reviewed By: labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D69468
* Add the ability to pass extra args to a Python breakpoint callback.Jim Ingham2019-10-251-1/+2
| | | | | | | | | | | | | | | | | For example, it is pretty easy to write a breakpoint command that implements "stop when my caller is Foo", and it is pretty easy to write a breakpoint command that implements "stop when my caller is Bar". But there's no way to write a generic "stop when my caller is..." function, and then specify the caller when you add the command to a breakpoint. With this patch, you can pass this data in a SBStructuredData dictionary. That will get stored in the PythonCommandBaton for the breakpoint, and passed to the implementation function (if it has the right signature) when the breakpoint is hit. Then in lldb, you can say: (lldb) break com add -F caller_is -k caller_name -v Foo More generally this will allow us to write reusable Python breakpoint commands. Differential Revision: https://reviews.llvm.org/D68671
* fix PythonDataObjectsTest.TestExceptions on windowsLawrence D'Anna2019-10-221-7/+7
| | | | | | | | | Looks like on windows googlemock regexes treat newlines differently from on darwin. This patch fixes the regex in this test so it will work on both. Fixes: https://reviews.llvm.org/D69214 llvm-svn: 375477
* remove multi-argument form of PythonObject::Reset()Lawrence D'Anna2019-10-223-165/+84
| | | | | | | | | | | | | | | | | | | | 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
* eliminate nontrivial Reset(...) from TypedPythonObjectLawrence D'Anna2019-10-191-7/+3
| | | | | | | | | | | | | | | | | | | | | | | | Summary: This deletes `Reset(...)`, except for the no-argument form `Reset()` from `TypedPythonObject`, and therefore from `PythonString`, `PythonList`, etc. It updates the various callers to use assignment, `As<>`, `Take<>`, and `Retain<>`, as appropriate. followon to https://reviews.llvm.org/D69080 Reviewers: JDevlieghere, clayborg, labath, jingham Reviewed By: labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D69133 llvm-svn: 375350
* [LLDB] bugfix: command script add -f doesn't work for some callablesLawrence D'Anna2019-10-191-6/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: When users define a debugger command from python, they provide a callable object. Because the signature of the function has been extended, LLDB needs to inspect the number of parameters the callable can take. The rule it was using to decide was weird, apparently not tested, and giving wrong results for some kinds of python callables. This patch replaces the weird rule with a simple one: if the callable can take 5 arguments, it gets the 5 argument version of the signature. Otherwise it gets the old 4 argument version. It also adds tests with a bunch of different kinds of python callables with both 4 and 5 arguments. Reviewers: JDevlieghere, clayborg, labath, jingham Reviewed By: labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D69014 llvm-svn: 375333
* eliminate one form of PythonObject::Reset()Lawrence D'Anna2019-10-171-10/+10
| | | | | | | | | | | | | | | | | | | | | | Summary: I'd like to eliminate all forms of Reset() and all public constructors on these objects, so the only way to make them is with Take<> and Retain<> and the only way to copy or move them is with actual c++ copy, move, or assignment. This is a simple place to start. Reviewers: JDevlieghere, clayborg, labath, jingham Reviewed By: labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D69080 llvm-svn: 375182
* clean up the implementation of PythonCallable::GetNumArgumentsLawrence D'Anna2019-10-171-0/+114
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The current implementation of PythonCallable::GetNumArguments is not exception safe, has weird semantics, and is just plain incorrect for some kinds of functions. Python 3.3 introduces inspect.signature, which lets us easily query for function signatures in a sane and documented way. This patch leaves the old implementation in place for < 3.3, but uses inspect.signature for modern pythons. It also leaves the old weird semantics in place, but with FIXMEs grousing about it. We should update the callers and fix the semantics in a subsequent patch. It also adds some tests. Reviewers: JDevlieghere, clayborg, labath, jingham Reviewed By: labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D68995 llvm-svn: 375181
* delete SWIG typemaps for FILE*Lawrence D'Anna2019-10-171-2/+3
| | | | | | | | | | | | | | | | | | 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
* Pass an SBStructuredData to scripted ThreadPlans on use.Jim Ingham2019-10-031-0/+1
| | | | | | | | | | This will allow us to write reusable scripted ThreadPlans, since you can use key/value pairs with known keys in the plan to parametrize its behavior. Differential Revision: https://reviews.llvm.org/D68366 llvm-svn: 373675
* Give an error when StepUsingScriptedThreadPlan is passed a bad classname.Jim Ingham2019-09-281-0/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D68173 llvm-svn: 373135
* Convert FileSystem::Open() to return Expected<FileUP>Lawrence D'Anna2019-09-262-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [CMake] Only the Python scirpt interpreter should link against Python.Jonas Devlieghere2019-04-011-3/+1
| | | | | | This patch removes spurious links against Python. llvm-svn: 357431
* [ScriptInterpreterPython] Fix the unit test after refactorJonas Devlieghere2019-03-291-3/+4
| | | | llvm-svn: 357313
* [Python] Define empty SWIG wrapper for unit testin"Jonas Devlieghere2019-03-262-1/+188
| | | | | | | | | The python plugin uses wrappers generated by swig. For the symbols to be available, we'd need to link against liblldb, which is not an option because the symbols could conflict with the static library we are testing. Instead we define the symbols ourselves in the unit test. llvm-svn: 356971
* [Python] Move SWIG wrapper dependency into the pluginJonas Devlieghere2019-03-251-1/+1
| | | | | | This should fix the Windows bot (fingers crossed). llvm-svn: 356967
* [PythonTestSuite] Fix usage of InitializePrivate in PythonTestSuiteJonas Devlieghere2019-03-251-3/+8
| | | | llvm-svn: 356950
* Add PythonBoolean type to the PythonDataObjectsTatyana Krasnukha2019-02-161-0/+25
| | | | | | Differential Revision: https://reviews.llvm.org/D57817 llvm-svn: 354206
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-194-16/+12
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [FileSystem] Open File instances through the FileSystem.Jonas Devlieghere2018-11-021-2/+4
| | | | | | | | | | | This patch modifies how we open File instances in LLDB. Rather than passing a path or FileSpec to the constructor, we now go through the virtual file system. This is needed in order to make things work with the VFS in the future. Differential revision: https://reviews.llvm.org/D54020 llvm-svn: 346049
* [FileSystem] Improve assert and add Terminate in unit test.Jonas Devlieghere2018-11-011-0/+2
| | | | | | | | Speculative fix for the Xcode bots where we were seeing the assertion being triggered because we would re-initialize the FileSystem without terminating it. llvm-svn: 345849
* [FileSystem] Extend file system and have it use the VFS.Jonas Devlieghere2018-10-311-1/+3
| | | | | | | | | | | | | | | | This patch extends the FileSystem class with a bunch of functions that are currently implemented as methods of the FileSpec class. These methods will be removed in future commits and replaced by calls to the file system. The new functions are operated in terms of the virtual file system which was recently moved from clang into LLVM so it could be reused in lldb. Because the VFS is stateful, we turned the FileSystem class into a singleton. Differential revision: https://reviews.llvm.org/D53532 llvm-svn: 345783
* Added new API to SBStructuredData classAbhishek Aggarwal2017-05-291-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: - Added API to access data types -- integer, double, array, string, boolean and dictionary data types -- Earlier user had to parse through the string output to get these values - Added Test cases for API testing - Added new StructuredDataType enum in public include file -- Replaced locally-defined enum in StructuredData.h with this new one -- Modified other internal files using this locally-defined enum Signed-off-by: Abhishek Aggarwal <abhishek.a.aggarwal@intel.com> Reviewers: clayborg, lldb-commits Reviewed By: clayborg Subscribers: labath Differential Revision: https://reviews.llvm.org/D33434 llvm-svn: 304138
* [CMake] Update unit tests with accurate dependenciesChris Bieneman2017-02-011-2/+7
| | | | | | This is extending the updates from r293696 to the LLDB unit tests. llvm-svn: 293821
* Fix some unit test compilation failures.Zachary Turner2016-11-161-12/+12
| | | | llvm-svn: 287158
* Don't allow direct access to StreamString's internal buffer.Zachary Turner2016-11-161-7/+7
| | | | | | | | | | | | | | | This is a large API change that removes the two functions from StreamString that return a std::string& and a const std::string&, and instead provide one function which returns a StringRef. Direct access to the underlying buffer violates the concept of a "stream" which is intended to provide forward only access, and makes porting to llvm::raw_ostream more difficult in the future. Differential Revision: https://reviews.llvm.org/D26698 llvm-svn: 287152
* *** This commit represents a complete reformatting of the LLDB source codeKate Stone2016-09-064-625/+586
| | | | | | | | | | | | | | | | | | | | | | | *** to conform to clang-format’s LLVM style. This kind of mass change has *** two obvious implications: Firstly, merging this particular commit into a downstream fork may be a huge effort. Alternatively, it may be worth merging all changes up to this commit, performing the same reformatting operation locally, and then discarding the merge for this particular commit. The commands used to accomplish this reformatting were as follows (with current working directory as the root of the repository): find . \( -iname "*.c" -or -iname "*.cpp" -or -iname "*.h" -or -iname "*.mm" \) -exec clang-format -i {} + find . -iname "*.py" -exec autopep8 --in-place --aggressive --aggressive {} + ; The version of clang-format used was 3.9.0, and autopep8 was 1.2.4. Secondly, “blame” style tools will generally point to this commit instead of a meaningful prior commit. There are alternatives available that will attempt to look through this change and find the appropriate prior commit. YMMV. llvm-svn: 280751
* Fix unit tests on windowsPavel Labath2016-08-112-2/+2
| | | | | | Python headers need to be included before PosixApi.h llvm-svn: 278345
* Fix a problem where if a uint64_t value is placed into a python dictionary ↵Greg Clayton2016-08-101-0/+24
| | | | | | | | and sent up to LLDB and converted to StructuredData, it would not be able to parse the full 64 bit value. A number like 0xf000000000000000L could be placed into a dictionary, and sent to LLDB and it would end up being 0xffffffffffffffff since it would overflow a int64_t. We leave the old code there, but if it overflows, we treat the number like a uint64_t and get it to decode correctly. Added a gtest to cover this so we don't regress. I verified the gtest failed prior to the fix, and it succeeds after it. <rdar://problem/27409265> llvm-svn: 278304
* Fix a no newline at end of file warning.Greg Clayton2016-06-091-1/+1
| | | | llvm-svn: 272284
* Initialize the Python script interpreter lazily (i.e. not at debugger startup)Enrico Granata2016-04-121-0/+1
| | | | | | This time it should also pass the gtests llvm-svn: 266103
* Fix PythonDataObjectsTests for python 2Pavel Labath2016-02-251-2/+1
| | | | | | | | | | | | | | Summary: the python2 branch seems erroneous as it expected the object to be both a "String" and "Bytes". Fix the expectation. Reviewers: zturner Subscribers: lldb-commits Differential Revision: http://reviews.llvm.org/D17545 llvm-svn: 261901
* Fix sign conversion warnings in LLDB Python unittestsReid Kleckner2016-02-031-19/+18
| | | | llvm-svn: 259689
* Fix swig typemap for SBEvent.Zachary Turner2016-01-251-0/+14
| | | | | | | | | | | 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
* Introduce a PythonBytes class into PythonDataObjects.Zachary Turner2016-01-111-0/+21
| | | | | | | This class behaves the same as PythonString on Python2, but differently on Python3. Unittests are added as well. llvm-svn: 257397
* Fix a bug in PythonExceptionState and add unittest coverage.Zachary Turner2015-11-131-0/+53
| | | | | | | I forgot to reset the restore flag when calling member function `Acquire`. The newly added unittest should cover this case. llvm-svn: 253002
* Introduce a `PythonExceptionState` class.Zachary Turner2015-11-132-0/+122
| | | | | | | | | | | | This is a helper class which supports a number of features including exception to string formatting with backtrace handling and auto-restore of exception state upon scope exit. Additionally, unit tests are included to verify the feature set of the class. llvm-svn: 252994
* gtest - Make a `PythonTestSuite` base class for setup / teardown.Zachary Turner2015-11-134-17/+74
| | | | | | | | This allows other potential unit test suites (of which one is forthcoming in a subsequent patch) to re-use the same initialization and teardown of the GIL. llvm-svn: 252993
* Create `PythonTuple` and `PythonCallable` wrapper classes.Zachary Turner2015-11-111-11/+132
| | | | | | | | | | | | | | This adds PythonTuple and PythonCallable classes to PythonDataObjects. Additionally, unit tests are provided that exercise this functionality, including invoking manipulating and checking for validity of tuples, and invoking and checking for validity of callables using a variety of different syntaxes. The goal here is to eventually replace the code in python-wrapper.swig that directly uses the Python C API to deal with callables and name resolution with this code that can be more easily tested and debugged. llvm-svn: 252787
* Add a `PythonModule` class, and a root-level method for resolving names.Zachary Turner2015-11-111-0/+60
| | | | llvm-svn: 252765
* Convert SWIG typemap string operations to PythonObjects.Zachary Turner2015-10-161-0/+11
| | | | llvm-svn: 250530
* Introduce a `PythonFile` object, and use it everywhere.Zachary Turner2015-10-151-0/+9
| | | | | | | | | | | | | | | | | | | | | | | Python file handling got an overhaul in Python 3, and it affects the way we have to interact with files. Notably: 1) `PyFile_FromFile` no longer exists, and instead we have to use `PyFile_FromFd`. This means having a way to get an fd from a FILE*. For this we reuse the lldb_private::File class to convert between FILE*s and fds, since there are some subtleties regarding ownership rules when FILE*s and fds refer to the same file. 2) PyFile is no longer a builtin type, so there is no such thing as `PyFile_Check`. Instead, files in Python 3 are just instances of `io.IOBase`. So the logic for checking if something is a file in Python 3 is to check if it is a subclass of that module. Additionally, some unit tests are added to verify that `PythonFile` works as expected on Python 2 and Python 3, and `ScriptInterpreterPython` is updated to use `PythonFile` instead of manual calls to the various `PyFile_XXX` methods. llvm-svn: 250444
* Get Python unit tests working with Python 3.Zachary Turner2015-10-141-260/+173
| | | | | | | | | | | | | | | | | | | | | There were a couple of issues related to string handling that needed to be fixed. In particular, we cannot get away with converting `PyUnicode` objects to `PyBytes` objects and storing the `PyBytes` regardless of Python version. Instead we have to store a `PyUnicode` on Python 3 and a `PyString` on Python 2. The reason for this is that if you call `PyObject_Str` on a `PyBytes` in Python 3, it will return you a string that actually contains the string value wrappedin the characters b''. So if we create a `PythonString` with the value "test", and we call Str() on it, we will get back the string "b'test'", which breaks string equality. The only way to fix this is to store a native `PyUnicode` object under Python 3. With this CL, ScriptInterpreterPythonTests unit tests pass 100% under Python 2 and Python 3. llvm-svn: 250327
* Fix ref counting of Python objects.Zachary Turner2015-10-131-43/+94
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | PythonObjects were being incorrectly ref-counted. This problem was pervasive throughout the codebase, leading to an unknown number of memory leaks and potentially use-after-free. The issue stems from the fact that Python native methods can either return "borrowed" references or "owned" references. For the former category, you *must* incref it prior to decrefing it. And for the latter category, you should not incref it before decrefing it. This is mostly an issue when a Python C API method returns a `PyObject` to you, but it can also happen with a method accepts a `PyObject`. Notably, this happens in `PyList_SetItem`, which is documented to "steal" the reference that you give it. So if you pass something to `PyList_SetItem`, you cannot hold onto it unless you incref it first. But since this is one of only two exceptions in the entire API, it's confusing and difficult to remember. Our `PythonObject` class was indiscriminantely increfing every object it received, which means that if you passed it an owned reference, you now have a dangling reference since owned references should not be increfed. We were doing this in quite a few places. There was also a fair amount of manual increfing and decrefing prevalent throughout the codebase, which is easy to get wrong. This patch solves the problem by making any construction of a `PythonObject` from a `PyObject` take a flag which indicates whether it is an owned reference or a borrowed reference. There is no way to construct a `PythonObject` without this flag, and it does not offer a default value, forcing the user to make an explicit decision every time. All manual uses of `PyObject` have been cleaned up throughout the codebase and replaced with `PythonObject` in order to make RAII the predominant pattern when dealing with native Python objects. Differential Revision: http://reviews.llvm.org/D13617 Reviewed By: Greg Clayton llvm-svn: 250195
OpenPOWER on IntegriCloud