summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/ScriptInterpreter
Commit message (Collapse)AuthorAgeFilesLines
* [lldb/CommandInterpreter] Remove flag that's always true (NFC)Jonas Devlieghere2020-01-141-2/+2
| | | | | | | The 'asynchronously' argument to both GetLLDBCommandsFromIOHandler and GetPythonCommandsFromIOHandler is true for all call sites. This commit simplifies the API by dropping it and giving the baton a default argument.
* [lldb/Lua] Support loading Lua modulesJonas Devlieghere2020-01-104-0/+49
| | | | | | Implements the command script import command for Lua. Differential revision: https://reviews.llvm.org/D71825
* [lldb/Lua] Make lldb.debugger et al available to LuaJonas Devlieghere2020-01-094-3/+40
| | | | | | | | The Python script interpreter makes the current debugger, target, process, thread and frame available to interactive scripting sessions through convenience variables. This patch does the same for Lua. Differential revision: https://reviews.llvm.org/D71801
* [lldb/CMake] Fix variable naming in FindLibEditJonas Devlieghere2020-01-021-2/+2
| | | | | | | | | | | | The current FOUND_VAR for FindLibEdit is libedit_FOUND but wasn't set by find_package_handle_standard_args. However this isn't valid for the package name. The argument for FOUND_VAR is "libedit_FOUND", but only "LibEdit_FOUND" and "LIBEDIT_FOUND" are valid names. This fixes all the variables set by FindLibEdit to match the desired naming scheme.
* [lldb/CMake] Use PYTHON_LIBRARIES instead of PYTHON_LIBRARYJonas Devlieghere2020-01-021-1/+1
| | | | | | PYTHON_LIBRARIES is the canonical variable set by FindPythonLibs while PYTHON_LIBRARY is an implementation detail. This replaces the uses of the latter with the former.
* [lldb/ScriptInterpreter] Remove can_reload which is always true (NFC)Jonas Devlieghere2019-12-222-10/+4
| | | | | | The `-r` option for `command script import` is there for legacy compatibility, however the can_reload flag is always set to true. This patch removes the flag and any code that relies on it being false.
* [Lldb/Lua] Persist Lua state across script interpreter calls.Jonas Devlieghere2019-12-214-9/+21
| | | | | | Don't create a new lua state on every operation. Share a single state across the lifetime of the script interpreter. Add simple locking to prevent two threads from modifying the state concurrently.
* [Lldb/Lua] Generate Lua BindingsJonas Devlieghere2019-12-212-0/+7
| | | | | | | | | | | 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] Fix -Wstringop-truncation in PythonReadline.cppPavel Labath2019-12-211-1/+1
| | | | | The size is known and the truncation is deliberate -- use memcpy instead of strncpy.
* [lldb/Lua] Implement a Simple Lua Script Interpreter PrototypeJonas Devlieghere2019-12-204-12/+120
| | | | | | | | | | | | | | | 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/Lua] Add Boilerplate for a Lua Script InterpreterJonas Devlieghere2019-12-194-0/+129
| | | | | | | | | | | This adds the boilerplate necessary to support the Lua script interpreter. The interpreter is not functional yet and just reports that it's not implemented. Discussion on the mailing list: http://lists.llvm.org/pipermail/lldb-dev/2019-December/015812.html Differential revision: https://reviews.llvm.org/D71232
* [lldb/CMake] Rename LLDB_DISABLE_PYTHON to LLDB_ENABLE_PYTHONJonas Devlieghere2019-12-137-16/+10
| | | | | | | This matches the naming scheme used by LLVM and all the other optional dependencies in LLDB. Differential revision: https://reviews.llvm.org/D71482
* [lldb/Core] Add missing include (2/2)Jonas Devlieghere2019-12-121-0/+2
| | | | This got flagged by the debian buildbot.
* [lldb/CMake] Rename LLDB_DISABLE_LIBEDIT to LLDB_ENABLE_LIBEDITJonas Devlieghere2019-12-122-3/+3
| | | | | | This matches the naming scheme used by LLVM. Differential revision: https://reviews.llvm.org/D71380
* [lldb/Host] Use Host/Config.h entries instead of a global define.Jonas Devlieghere2019-12-106-12/+12
| | | | | | | | | | | As suggested by Pavel in a code review: > Can we replace this (and maybe python too, while at it) with a > Host/Config.h entry? A global definition means that one has to > recompile everything when these change in any way, whereas in > practice only a handful of files need this.. Differential revision: https://reviews.llvm.org/D71280
* [lldb][CMake] Fix build for the case of custom libedit installationTatyana Krasnukha2019-12-091-0/+11
|
* [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] Fix some warnings in the python pluginPavel Labath2019-11-122-2/+3
|
* Silence warning, PyMODINIT_FUNC already contains extern "C"Benjamin Kramer2019-11-061-1/+1
| | | | PythonReadline.h:22:12: warning: duplicate 'extern' declaration specifier [-Wduplicate-decl-specifier]
* [lldb] [Python] Build readline override module only on LinuxMichał Górny2019-11-051-1/+1
| | | | | | | | | Restrict building the readline override to Linux only. It both does not build on *BSD systems, and is largely irrelevant since they default to using libedit over readline anyway. This restores the behavior of the old readline override that also was built only on Linux. Differential Revision: https://reviews.llvm.org/D69846
* [lldb] Fix readline/libedit compat patch for py2serge-sans-paille2019-11-051-1/+9
| | | | This is a follow-up to https://reviews.llvm.org/D69793
* Revert and patch "[Python] Remove readline module"serge-sans-paille2019-11-054-0/+124
| | | | | | | | | | | | | | | | | | | | Fix https://bugs.llvm.org/show_bug.cgi?id=43830 while avoiding polluting the global Python namespace. This both reverts r357277 to rebundle a version of Python's readline module based on libedit. However, this patch also provides two improvements over the previous implementation: 1. use PyMem_RawMalloc instead of PyMem_Malloc, as expected by PyOS_Readline (prevents to segfault upon exit of interactive session) 2. patch the readline module upon embedded interpreter loading, instead of patching it globally, which should prevent any side effect on other modules/packages 3. only activate the patched module if libedit is actually linked in lldb Differential Revision: https://reviews.llvm.org/D69793
* [LLDB][Python] remove ArgInfo::countLawrence D'Anna2019-11-043-65/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | 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][PythonFile] fix dangerous borrow semantics on python2Lawrence D'Anna2019-10-301-13/+15
| | | | | | | | | | | | | | | | | | | | Summary: It is inherently unsafe to allow a python program to manipulate borrowed memory from a python object's destructor. It would be nice to flush a borrowed file when python is finished with it, but it's not safe to do on python 2. Python 3 does not suffer from this issue. Reviewers: labath, mgorny Reviewed By: labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D69532
* [LLDB][breakpoints] ArgInfo::count -> ArgInfo::max_positional_argsLawrence D'Anna2019-10-292-41/+56
| | | | | | | | | | | | | | | | | | | | 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
* [LLDB][Python] fix another fflush issue on NetBSDLawrence D'Anna2019-10-292-15/+20
| | | | | | | | | | | | | | | | Summary: Here's another instance where we were calling fflush on an input stream, which is illegal on NetBSD. Reviewers: labath, mgorny Reviewed By: mgorny Subscribers: krytarowski, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D69488
* Correct size_t format specifierShu-Chun Weng2019-10-261-1/+1
| | | | Differential Revision: https://reviews.llvm.org/D69455
* Add the ability to pass extra args to a Python breakpoint callback.Jim Ingham2019-10-253-19/+116
| | | | | | | | | | | | | | | | | 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
* [lldb] [Python] Do not attempt to flush() a read-only fdMichal Gorny2019-10-241-5/+7
| | | | | | | | | | | | | | | Summary: When creating a FileSP object, do not flush() the underlying file unless it is open for writing. Attempting to flush() a read-only fd results in EBADF on NetBSD. Reviewers: lawrence_danna, labath, krytarowski Reviewed By: lawrence_danna, labath Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D69320
* remove multi-argument form of PythonObject::Reset()Lawrence D'Anna2019-10-227-479/+316
| | | | | | | | | | | | | | | | | | | | 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-193-39/+75
| | | | | | | | | | | | | | | | | | | | | | | | 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-192-8/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-172-27/+5
| | | | | | | | | | | | | | | | | | | | | | 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-172-35/+215
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-173-35/+7
| | | | | | | | | | | | | | | | | | 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
* update ScriptInterpreterPython to use File, not FILE*Lawrence D'Anna2019-10-162-55/+52
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: ScriptInterpreterPython needs to save and restore sys.stdout and friends when LLDB runs a python script. It currently does this using FILE*, which is not optimal. If whatever was in sys.stdout can not be represented as a FILE*, then it will not be restored correctly when the script is finished. It also means that if the debugger's own output stream is not representable as a file, ScriptInterpreterPython will not be able to redirect python's output correctly. This patch updates ScriptInterpreterPython to represent files with lldb_private::File, and to represent whatever the user had in sys.stdout as simply a PythonObject. This will make lldb interoperate better with other scripts or programs that need to manipulate sys.stdout. Reviewers: JDevlieghere, jasonmolenda, labath Reviewed By: labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D68962 llvm-svn: 374964
* eliminate virtual methods from PythonDataObjectsLawrence D'Anna2019-10-152-380/+121
| | | | | | | | | | | | | | | | | | | | | Summary: This patch eliminates a bunch of boilerplate from PythonDataObjects, as well as the use of virtual methods. In my opinion it also makes the Reset logic a lot more clear and easy to follow. The price is yet another template. I think it's worth it. Reviewers: JDevlieghere, jasonmolenda, labath, zturner Reviewed By: JDevlieghere, labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D68918 llvm-svn: 374916
* SBFile::GetFile: convert SBFile back into python native files.Lawrence D'Anna2019-10-152-24/+80
| | | | | | | | | | | | | | | | | | | | | | 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
* uint32_t options -> File::OpenOptions optionsLawrence D'Anna2019-10-141-7/+12
| | | | | | | | | | | | | | | | | | | | | | | Summary: This patch re-types everywhere that passes a File::OpenOptions as a uint32_t so it actually uses File::OpenOptions. It also converts some OpenOptions related functions that fail by returning 0 or NULL into llvm::Expected split off from https://reviews.llvm.org/D68737 Reviewers: JDevlieghere, jasonmolenda, labath Reviewed By: labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D68853 llvm-svn: 374817
* SBFile support in SBCommandReturnObjectLawrence D'Anna2019-10-091-2/+3
| | | | | | | | | | | | | | | | | | Summary: This patch add SBFile interfaces to SBCommandReturnObject, and removes the internal callers of its FILE* interfaces. Reviewers: JDevlieghere, jasonmolenda, labath Reviewed By: JDevlieghere Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D68434 llvm-svn: 374238
* allow arbitrary python streams to be converted to SBFileLawrence D'Anna2019-10-091-14/+401
| | | | | | | | | | | | | | | | | | | | | | | | 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
* exception handling in PythonDataObjects.Lawrence D'Anna2019-10-082-36/+392
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Python APIs nearly all can return an exception. They do this by returning NULL, or -1, or some such value and setting the exception state with PyErr_Set*(). Exceptions must be handled before further python API functions are called. Failure to do so will result in asserts on debug builds of python. It will also sometimes, but not usually result in crashes of release builds. Nearly everything in PythonDataObjects.h needs to be updated to account for this. This patch doesn't fix everything, but it does introduce some new methods using Expected<> return types that are safe to use. split off from https://reviews.llvm.org/D68188 Reviewers: JDevlieghere, jasonmolenda, labath, zturner Reviewed By: labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D68547 llvm-svn: 374094
* [lldb] Reverts part of 61f471aHaibo Huang2019-10-081-1/+6
| | | | | | | | | | | Seems I wrongly merged an old patch. Reverts the change related to python dir for windows. FileSpec should always contain normalized path. I.e. using '/' even in windows. llvm-svn: 373998
* [lldb] Unifying lldb python pathHaibo Huang2019-10-073-40/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Based on mgorny@'s D67890 There are 3 places where python site-package path is calculated independently: 1. finishSwigPythonLLDB.py where files are written to site-packages. 2. lldb/scripts/CMakeLists.txt where site-packages are installed. 3. ScriptInterpreterPython.cpp where site-packages are added to PYTHONPATH. This change creates the path once and use it everywhere. So that they will not go out of sync. Also it provides a chance for cross compiling users to specify the right path for site-packages. Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D68442 llvm-svn: 373991
* [Python] Remove unused variableJonas Devlieghere2019-10-041-1/+0
| | | | | | warning: unused variable 'py_func_obj' [-Wunused-variable] PyObject *py_func_obj = m_py_obj; llvm-svn: 373686
* Python3 doesn't seem to allow you to tell whether an object is a classJim Ingham2019-10-031-2/+0
| | | | | | | | | PyClass_Check and everything it relied on seems gone from Python3.7. So I won't check whether it is a class first... Also cleaned up a couple of warnings. llvm-svn: 373679
* Pass an SBStructuredData to scripted ThreadPlans on use.Jim Ingham2019-10-034-2/+26
| | | | | | | | | | 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
* factor out an abstract base class for FileLawrence D'Anna2019-10-032-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | 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
* SBDebugger::SetInputFile, SetOutputFile, etc.Lawrence D'Anna2019-10-031-0/+2
| | | | | | | | | | | | | | | | | | | | | Summary: Add new methods to SBDebugger to set IO files as SBFiles instead of as FILE* streams. In future commits, the FILE* methods will be deprecated and these will become the primary way to set the debugger I/O streams. Reviewers: JDevlieghere, jasonmolenda, labath Reviewed By: labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D68181 llvm-svn: 373563
* new api class: SBFileLawrence D'Anna2019-10-032-20/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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
OpenPOWER on IntegriCloud