aboutsummaryrefslogtreecommitdiff
path: root/lldb/unittests/ScriptInterpreter/Python
AgeCommit message (Collapse)AuthorFilesLines
4 daysSwitch the ScriptedBreakpointResolver over to the ScriptedInterface form ↵jimingham1-14/+5
(#150720) This is NFC, I'm modernizing the interface before I add to it in a subsequent commit.
2025-06-04[lldb/cmake] Implicitly pass arguments to llvm_add_library (#142583)Pavel Labath1-2/+2
If we're not touching them, we don't need to do anything special to pass them along -- with one important caveat: due to how cmake arguments work, the implicitly passed arguments need to be specified before arguments that we handle. This isn't particularly nice, but the alternative is enumerating all arguments that can be used by llvm_add_library and the macros it calls (it also relies on implicit passing of some arguments to llvm_process_sources).
2025-04-01Add a new affordance that the Python module in a dSYM (#133290)jimingham1-0/+6
So the dSYM can be told what target it has been loaded into. When lldb is loading modules, while creating a target, it will run "command script import" on any Python modules in Resources/Python in the dSYM. However, this happens WHILE the target is being created, so it is not yet in the target list. That means that these scripts can't act on the target that they a part of when they get loaded. This patch adds a new python API that lldb will call: __lldb_module_added_to_target if it is defined in the module, passing in the Target the module was being added to, so that code in these dSYM's don't have to guess.
2025-01-29[lldb] Make Python >= 3.8 required for LLDB 21 (#124735)David Spickett1-6/+0
As decided on https://discourse.llvm.org/t/rfc-lets-document-and-enforce-a-minimum-python-version-for-lldb/82731. LLDB 20 recommended `>= 3.8` but did not remove support for anything earlier. Now we are in what will become LLDB 21, so I'm removing that support and making `>= 3.8` required. See https://docs.python.org/3/c-api/apiabiversion.html#c.PY_VERSION_HEX for the format of PY_VERSION_HEX.
2024-10-31[lldb] Use PY_VERSION_HEX to simplify conditional compilation (NFC) (#114346)Jonas Devlieghere1-1/+1
Use PY_VERSION_HEX to simplify conditional compilation depending on the Python version. This also adds a static_assert to lldb-python to error out with a meaningful diagnostic when you try building LLDB with an older Python version in preparation for [1]. [1] https://discourse.llvm.org/t/rfc-lets-document-and-enforce-a-minimum-python-version-for-lldb/82731/15
2024-09-24Add the ability to define custom completers to the parsed_cmd template. ↵jimingham1-0/+13
(#109062) If your arguments or option values are of a type that naturally uses one of our common completion mechanisms, you will get completion for free. But if you have your own custom values or if you want to do fancy things like have `break set -s foo.dylib -n ba<TAB>` only complete on symbols in foo.dylib, you can use this new mechanism to achieve that.
2024-09-20[lldb/Interpreter] Introduce ScriptedStopHook{,Python}Interface & make use ↵Med Ismail Bennani1-15/+6
of it (#109498) This patch re-lands #105449 and fixes the various test failures. --------- Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2024-09-20Revert "[lldb] Fix SWIG wrapper compilation error"David Spickett1-5/+14
...and "[lldb/Interpreter] Introduce `ScriptedStopHook{,Python}Interface` & make use of it (#105449)" This reverts commit 76b827bb4d5b4cc4d3229c4c6de2529e8b156810, and commit 1e131ddfa8f1d7b18c85c6e4079458be8b419421 because the first commit caused the test command-stop-hook-output.test to fail.
2024-09-20[lldb] Fix SWIG wrapper compilation errorDavid Spickett1-1/+1
Introduced by 1e131ddfa8f1d7b18c85c6e4079458be8b419421. https://lab.llvm.org/buildbot/#/builders/59/builds/5272
2024-09-19[lldb/Interpreter] Introduce `ScriptedStopHook{,Python}Interface` & make use ↵Med Ismail Bennani1-15/+6
of it (#105449) This patch introduces new `ScriptedStopHook{,Python}Interface` classes that make use of the Scripted Interface infrastructure and makes use of it in `StopHookScripted`. It also relax the requirement on the number of argument for initializing scripting extension if the size of the interface parameter pack contains 1 less element than the extension maximum number of positional arguments for this initializer. This addresses the cases where the embedded interpreter session dictionary is passed to the extension initializer which is not used most of the time. --------- Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2024-09-05[lldb] Make deep copies of Status explicit (NFC) (#107170)Adrian Prantl1-1/+1
2024-07-03Add the ability for Script based commands to specify their "repeat command" ↵jimingham1-0/+6
(#94823) Among other things, returning an empty string as the repeat command disables auto-repeat, which can be useful for state-changing commands. There's one remaining refinement to this setup, which is that for parsed script commands, it should be possible to change an option value, or add a new option value that wasn't originally specified, then ask lldb "make this back into a command string". That would make doing fancy things with repeat commands easier. That capability isn't present in the lldb_private side either, however. So that's for a next iteration. I haven't added this to the docs on adding commands yet. I wanted to make sure this was an acceptable approach before I spend the time to do that.
2024-06-27[lldb] Make use of Scripted{Python,}Interface for ScriptedThreadPlan ↵Med Ismail Bennani1-20/+30
(#70392) (#96868) This patch makes ScriptedThreadPlan conforming to the ScriptedInterface & ScriptedPythonInterface facilities by introducing 2 ScriptedThreadPlanInterface & ScriptedThreadPlanPythonInterface classes. This allows us to get rid of every ScriptedThreadPlan-specific SWIG method and re-use the same affordances as other scripting offordances, like Scripted{Process,Thread,Platform} & OperatingSystem. To do so, this adds new transformer methods for `ThreadPlan`, `Stream` & `Event`, to allow the bijection between C++ objects and their python counterparts. This just re-lands #70392 after fixing test failures. Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2024-05-23Revert "[lldb] Make use of Scripted{Python,}Interface for ScriptedThreadPlan ↵Med Ismail Bennani1-30/+20
(Reland #70392)" (#93153) Reverts llvm/llvm-project#93149 since it breaks https://lab.llvm.org/buildbot/#/builders/68/builds/74799
2024-05-23[lldb] Make use of Scripted{Python,}Interface for ScriptedThreadPlan (Reland ↵Med Ismail Bennani1-20/+30
#70392) (#93149) This patch makes ScriptedThreadPlan conforming to the ScriptedInterface & ScriptedPythonInterface facilities by introducing 2 ScriptedThreadPlanInterface & ScriptedThreadPlanPythonInterface classes. This allows us to get rid of every ScriptedThreadPlan-specific SWIG method and re-use the same affordances as other scripting offordances, like Scripted{Process,Thread,Platform} & OperatingSystem. To do so, this adds new transformer methods for `ThreadPlan`, `Stream` & `Event`, to allow the bijection between C++ objects and their python counterparts. This just re-lands #70392 after fixing test failures. Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2024-02-21[lldb][test] Fix PythonDataObjectsTestJordan Rupprecht1-3/+7
This is using `FileSystem::Instance()` w/o calling `FileSystem::Initialize()`. Use `SubsystemRAII` to do that.
2024-02-17[lldb] Don't rely on ScriptInterpreterPythonImpl::Initialize in the unit ↵Jonas Devlieghere1-21/+5
tests (#82096) The unit tests only test the Python objects and don't actually use anything from the LLDB module. That means that all the additional complexity in ScriptInterpreterPythonImpl::Initialize is overkill. By doing the initialization by hand, we avoid the annoying ModuleNotFoundError. Traceback (most recent call last): File "<string>", line 1, in <module> ModuleNotFoundError: No module named 'lldb' The error is the result of us stubbing out the SWIG (specifically `PyInit__lldb`) because we cannot link against libLLDB from the unit tests. The downside of doing the initialization manually is that we do lose a bit of test coverage. For example, issue #70453 also manifested itself in the unit tests.
2024-02-17[lldb] Use PyBytes and PyByteArray in Python Data Objects unittest (#82098)Jonas Devlieghere1-12/+18
Use a Python Bytes and ByteArray object instead of Integers for TestOwnedReferences and TestBorrowedReferences. These two tests were failing when building against Python 3.12 because these Integer objects had a refcount of 4294967296 (-1). I didn't dig into it, but I suspect the Python runtime has adopted an optimization to decrease refcounting traffic for these simple objects.
2024-02-13Add the ability to define a Python based command that uses ↵jimingham1-0/+8
CommandObjectParsed (#70734) This allows you to specify options and arguments and their definitions and then have lldb handle the completions, help, etc. in the same way that lldb does for its parsed commands internally. This feature has some design considerations as well as the code, so I've also set up an RFC, but I did this one first and will put the RFC address in here once I've pushed it... Note, the lldb "ParsedCommand interface" doesn't actually do all the work that it should. For instance, saying the type of an option that has a completer doesn't automatically hook up the completer, and ditto for argument values. We also do almost no work to verify that the arguments match their definition, or do auto-completion for them. This patch allows you to make a command that's bug-for-bug compatible with built-in ones, but I didn't want to stall it on getting the auto-command checking to work all the way correctly. As an overall design note, my primary goal here was to make an interface that worked well in the script language. For that I needed, for instance, to have a property-based way to get all the option values that were specified. It was much more convenient to do that by making a fairly bare-bones C interface to define the options and arguments of a command, and set their values, and then wrap that in a Python class (installed along with the other bits of the lldb python module) which you can then derive from to make your new command. This approach will also make it easier to experiment. See the file test_commands.py in the test case for examples of how this works.
2024-01-29Revert "[lldb] Make use of Scripted{Python,}Interface for ScriptedThreadPlan ↵Jason Molenda1-30/+20
(#70392)" Temporarily revert to unblock the CI bots, this is breaking the -DLLVM_ENABLE_MODULES=On modules style build. I've notified Ismail. This reverts commit 888501bc631c4f6d373b4081ff6c504a1ce4a682.
2024-01-29[lldb] Make use of Scripted{Python,}Interface for ScriptedThreadPlan (#70392)Med Ismail Bennani1-20/+30
This patch makes ScriptedThreadPlan conforming to the ScriptedInterface & ScriptedPythonInterface facilities by introducing 2 ScriptedThreadPlanInterface & ScriptedThreadPlanPythonInterface classes. This allows us to get rid of every ScriptedThreadPlan-specific SWIG method and re-use the same affordances as other scripting offordances, like Scripted{Process,Thread,Platform} & OperatingSystem. To do so, this adds new transformer methods for `ThreadPlan`, `Stream` & `Event`, to allow the bijection between C++ objects and their python counterparts. Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-11-07[lldb] Check for abstract methods implementation in Scripted Plugin Objects ↵Med Ismail Bennani1-0/+3
(#71260) This patch enforces that every scripted object implements all the necessary abstract methods. Every scripted affordance language interface can implement a list of abstract methods name that checked when the object is instanciated. Since some scripting affordances implementations can be derived from template base classes, we can't check the object dictionary since it will contain the definition of the base class, so instead, this checks the scripting class dictionary. Previously, for the various python interfaces, we used `ABC.abstractmethod` decorators but this is too language specific and doesn't work for scripting affordances that are not derived from template base classes (i.e OperatingSystem, ScriptedThreadPlan, ...), so this patch provides generic/language-agnostic checks for every scripted affordance. Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-11-07Revert "[lldb] Check for abstract methods implementation in Scripted Plugin ↵Med Ismail Bennani1-3/+0
Objects (#71260)" This reverts commit cc9ad72713405ef8f2468c7a714a137b4a3343ba since it breaks some tests upstream: https://lab.llvm.org/buildbot/#/builders/68/builds/63112 ******************** Failed Tests (4): lldb-api :: functionalities/gdb_remote_client/TestThreadSelectionBug.py lldb-api :: functionalities/plugins/python_os_plugin/TestPythonOSPlugin.py lldb-api :: functionalities/plugins/python_os_plugin/stepping_plugin_threads/TestOSPluginStepping.py lldb-api :: functionalities/postmortem/mach-core/TestMachCore.py
2023-11-07[lldb] Check for abstract methods implementation in Scripted Plugin Objects ↵Med Ismail Bennani1-0/+3
(#71260) This patch enforces that every scripted object implements all the necessary abstract methods. Every scripted affordance language interface can implement a list of abstract methods name that checked when the object is instanciated. Since some scripting affordances implementations can be derived from template base classes, we can't check the object dictionary since it will contain the definition of the base class, so instead, this checks the scripting class dictionary. Previously, for the various python interfaces, we used `ABC.abstractmethod` decorators but this is too language specific and doesn't work for scripting affordances that are not derived from template base classes (i.e OperatingSystem, ScriptedThreadPlan, ...), so this patch provides generic/language-agnostic checks for every scripted affordance. Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-10-30Revert "[lldb] Make use of Scripted{Python,}Interface for ScriptedThreadPlan ↵Med Ismail Bennani1-25/+20
(#70392)" This reverts commit 4b3cd379cce3f455bf3c8677ca7a5be6e708a4ce since it introduces some test failures: https://lab.llvm.org/buildbot/#/builders/68/builds/62556
2023-10-30[lldb] Make use of Scripted{Python,}Interface for ScriptedThreadPlan (#70392)Med Ismail Bennani1-20/+25
This patch makes ScriptedThreadPlan conforming to the ScriptedInterface & ScriptedPythonInterface facilities by introducing 2 ScriptedThreadPlanInterface & ScriptedThreadPlanPythonInterface classes. This allows us to get rid of every ScriptedThreadPlan-specific SWIG method and re-use the same affordances as other scripting offordances, like Scripted{Process,Thread,Platform} & OperatingSystem. To do so, this adds new transformer methods for `ThreadPlan`, `Stream` & `Event`, to allow the bijection between C++ objects and their python counterparts. Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-10-26[lldb] Introduce OperatingSystem{,Python}Interface and make use itMed Ismail Bennani1-1/+6
This patch aims to consolidate the OperatingSystem scripting affordance by introducing a stable interface that conforms to the Scripted{,Python}Interface. This unify the way we call into python methods from lldb while also improving its capabilities by allowing us to pass lldb_private objects are arguments. Differential Revision: https://reviews.llvm.org/D159314 Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-10-25[lldb/Interpreter] Make ScriptedInterface Object creation more generic (#68052)Med Ismail Bennani1-8/+10
This patch changes the way plugin objects used with Scripted Interfaces are created. Instead of implementing a different SWIG method to create the object for every scripted interface, this patch makes the creation more generic by re-using some of the ScriptedPythonInterface templated Dispatch code. This patch also improves error handling of the object creation by returning an `llvm::Expected`. Signed-off-by: Med Ismail Bennani <ismail@bennani.ma> Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-10-22[lldb] Remove an unused using decl (NFC)Kazu Hirata1-1/+0
2023-05-22[lldb] Add support for negative integer to {SB,}StructuredDataMed Ismail Bennani1-5/+20
This patch refactors the `StructuredData::Integer` class to make it templated, makes it private and adds 2 public specialization for both `int64_t` & `uint64_t` with a public type aliases, respectively `SignedInteger` & `UnsignedInteger`. It adds new getter for signed and unsigned interger values to the `StructuredData::Object` base class and changes the implementation of `StructuredData::Array::GetItemAtIndexAsInteger` and `StructuredData::Dictionary::GetValueForKeyAsInteger` to support signed and unsigned integers. This patch also adds 2 new `Get{Signed,Unsigned}IntegerValue` to the `SBStructuredData` class and marks `GetIntegerValue` as deprecated. Finally, this patch audits all the caller of `StructuredData::Integer` or `StructuredData::GetIntegerValue` to use the proper type as well the various tests that uses `SBStructuredData.GetIntegerValue`. rdar://105575764 Differential Revision: https://reviews.llvm.org/D150485 Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-05-19Work around a modularization issue in the Python headers.Adrian Prantl1-0/+6
2023-05-10[lldb] Mark most SBAPI methods involving private types as protected or privateAlex Langford1-61/+79
Many SB classes have public constructors or methods involving types that are private. Some are more obvious (e.g. containing lldb_private in the name) than others (lldb::FooSP is usually std::shared_pointer<lldb_private::Foo>). This commit explicitly does not address FileSP, so I'm leaving that one alone for now. Some of these were for other SB classes to use and should have been made protected/private with a friend class entry added. Some of these were public for some of the swig python helpers to use. I put all of those functions into a class and made them static methods. The relevant SB classes mark that class as a friend so they can access those private/protected members. I've also removed an outdated SBStructuredData test (can you guess which constructor it was using?) and updated the other relevant tests. Differential Revision: https://reviews.llvm.org/D150157
2023-05-03Allow scripted thread plans to modify the thread stop description whenJim Ingham1-0/+8
they are completed.
2023-04-25[lldb] Improve breakpoint management for interactive scripted processMed Ismail Bennani1-0/+4
This patch improves breakpoint management when doing interactive scripted process debugging. In other to know which process set a breakpoint, we need to do some book keeping on the multiplexer scripted process. When initializing the multiplexer, we will first copy breakpoints that are already set on the driving target. Everytime we launch or resume, we should copy breakpoints from the multiplexer to the driving process. When creating a breakpoint from a child process, it needs to be set both on the multiplexer and on the driving process. We also tag the created breakpoint with the name and pid of the originator process. This patch also implements all the requirement to achieve proper breakpoint management. That involves: - Adding python interator for breakpoints and watchpoints in SBTarget - Add a new `ScriptedProcess.create_breakpoint` python method Differential Revision: https://reviews.llvm.org/D148548 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2023-03-15[lldb] Update PythonDataObjectsTests for new exception formattingJonas Devlieghere1-4/+7
PythonDataObjectsTest.TestExceptions started failing because the output of the python traceback printers is now consistent between python and cpython [1]. Work around the issue by supporting both variants. Thanks to Ismail for identifying the root cause. [1] https://github.com/python/cpython/issues/85203
2023-03-03[lldb/Plugins] Add memory writing capabilities to Scripted ProcessMed Ismail Bennani1-0/+5
This patch adds memory writing capabilities to the Scripted Process plugin. This allows to user to get a target address and a memory buffer on the python scripted process implementation that the user can make processing on before performing the actual write. This will also be used to write trap instruction to a real process memory to set a breakpoint. Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2023-03-03[lldb/Plugins] Add Attach capabilities to ScriptedProcessMed Ismail Bennani1-0/+18
This patch adds process attach capabilities to the ScriptedProcess plugin. This doesn't really expects a PID or process name, since the process state is already script, however, this allows to create a scripted process without requiring to have an executuble in the target. In order to do so, this patch also turns the scripted process related getters and setters from the `ProcessLaunchInfo` and `ProcessAttachInfo` classes to a `ScriptedMetadata` instance and moves it in the `ProcessInfo` class, so it can be accessed interchangeably. This also adds the necessary SWIG wrappers to convert the internal `Process{Attach,Launch}InfoSP` into a `SB{Attach,Launch}Info` to pass it as argument the scripted process python implementation and convert it back to the internal representation. rdar://104577406 Differential Revision: https://reviews.llvm.org/D143104 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2023-01-12[lldb] Add ScriptedPlatform python implementationMed Ismail Bennani1-9/+2
This patch introduces both the Scripted Platform python base implementation and an example for it. The base implementation is embedded in lldb python module under `lldb.plugins.scripted_platform`. This patch also refactor the various SWIG methods to create scripted objects into a single method, that is now shared between the Scripted Platform, Process and Thread. It also replaces the target argument by a execution context object. Differential Revision: https://reviews.llvm.org/D139250 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2023-01-07[lldb] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata1-2/+2
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to clean up the "using" declarations, #include "llvm/ADT/Optional.h", etc. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-07[lldb] Add #include <optional> (NFC)Kazu Hirata1-0/+1
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-03[LLDB] Skip python exception unit test on AArch64/WindowsMuhammad Omair Javaid1-0/+4
This patch marks python exception test as skipped for AArch64/Windows platform. This is temporary to make LLDB WoA buildbot happy until a proper fix is found.
2022-12-04[lldb/unittests] Use std::nullopt instead of None (NFC)Kazu Hirata1-2/+2
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-18[lldb/Plugins] Improve error reporting with reading memory in Scripted ProcessMed Ismail Bennani1-0/+4
This patch improves the ScriptedPythonInterface::Dispatch method to support passing lldb_private types to the python implementation. This will allow, for instance, the Scripted Process python implementation to report errors when reading memory back to lldb. To do so, the Dispatch method will transform the private types in the parameter pack into `PythonObject`s to be able to pass them down to the python methods. Then, if the call succeeded, the transformed arguments will be converted back to their original type and re-assigned in the parameter pack, to ensure pointers and references behaviours are preserved. This patch also updates various scripted process python class and tests to reflect this change. rdar://100030995 Differential Revision: https://reviews.llvm.org/D134033 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-10-19[lldb] Add matching based on Python callbacks for data formatters.Jorge Gorbe Moya1-0/+6
This patch adds a new matching method for data formatters, in addition to the existing exact typename and regex-based matching. The new method allows users to specify the name of a Python callback function that takes a `SBType` object and decides whether the type is a match or not. Here is an overview of the changes performed: - Add a new `eFormatterMatchCallback` matching type, and logic to handle it in `TypeMatcher` and `SBTypeNameSpecifier`. - Extend `FormattersMatchCandidate` instances with a pointer to the current `ScriptInterpreter` and the `TypeImpl` corresponding to the candidate type, so we can run registered callbacks and pass the type to them. All matcher search functions now receive a `FormattersMatchCandidate` instead of a type name. - Add some glue code to ScriptInterpreterPython and the SWIG bindings to allow calling a formatter matching callback. Most of this code is modeled after the equivalent code for watchpoint callback functions. - Add an API test for the new callback-based matching feature. For more context, please check the RFC thread where this feature was originally discussed: https://discourse.llvm.org/t/rfc-python-callback-for-data-formatters-type-matching/64204/11 Differential Revision: https://reviews.llvm.org/D135648
2022-04-27Remove Python 2 support from the ScriptInterpreter pluginJonas Devlieghere2-32/+0
We dropped downstream support for Python 2 in the previous release. Now that we have branched for the next release the window where this kind of change could introduce conflicts is closing too. Start by getting rid of Python 2 support in the Script Interpreter plugin. Differential revision: https://reviews.llvm.org/D124429
2022-01-19[lldb] Initialize Python exactly onceJonas Devlieghere1-2/+0
We got a few crash reports that showed LLDB initializing Python on two separate threads. Make sure Python is initialized exactly once. rdar://87287005 Differential revision: https://reviews.llvm.org/D117601
2022-01-18[lldb/python] Use PythonObject in LLDBSwigPython functionsPavel Labath1-18/+19
Return our PythonObject wrappers instead of raw PyObjects (obfuscated as void *). This ensures that ownership (reference counts) of python objects is automatically tracked. Differential Revision: https://reviews.llvm.org/D117462
2021-12-20[lldb/python] Fix (some) dangling pointers in our glue codePavel Labath1-10/+10
This starts to fix the other half of the lifetime problems in this code -- dangling references. SB objects created on the stack will go away when the function returns, which is a problem if the python code they were meant for stashes a reference to them somewhere. Most of the time this goes by unnoticed, as the code rarely has a reason to store these, but in case it does, we shouldn't respond by crashing. This patch fixes the management for a couple of SB objects (Debugger, Frame, Thread). The SB objects are now created on the heap, and their ownership is immediately passed on to SWIG, which will ensure they are destroyed when the last python reference goes away. I will handle the other objects in separate patches. I include one test which demonstrates the lifetime issue for SBDebugger. Strictly speaking, one should create a test case for each of these objects and each of the contexts they are being used. That would require figuring out how to persist (and later access) each of these objects. Some of those may involve a lot of hoop-jumping (we can run python code from within a frame-format string). I don't think that is necessary/worth it since the new wrapper functions make it very hard to get this wrong. Differential Revision: https://reviews.llvm.org/D115925
2021-12-13[lldb] Clarify StructuredDataImpl ownershipPavel Labath1-7/+7
StructuredDataImpl ownership semantics is unclear at best. Various structures were holding a non-owning pointer to it, with a comment that the object is owned somewhere else. From what I was able to gather that "somewhere else" was the SBStructuredData object, but I am not sure that all created object eventually made its way there. (It wouldn't matter even if they did, as we are leaking most of our SBStructuredData objects.) Since StructuredDataImpl is just a collection of two (shared) pointers, there's really no point in elaborate lifetime management, so this patch replaces all StructuredDataImpl pointers with actual objects or unique_ptrs to it. This makes it much easier to resolve SBStructuredData leaks in a follow-up patch. Differential Revision: https://reviews.llvm.org/D114791
2021-11-30[lldb] Remove 'extern "C"' from the lldb-swig-python interfacePavel Labath1-100/+74
The LLDBSWIGPython functions had (at least) two problems: - There wasn't a single source of truth (a header file) for the prototypes of these functions. This meant that subtle differences in copies of function declarations could go by undetected. And not-so-subtle differences would result in strange runtime failures. - All of the declarations had to have an extern "C" interface, because the function definitions were being placed inside and extert "C" block generated by swig. This patch fixes both problems by moving the function definitions to the %header block of the swig files. This block is not surrounded by extern "C", and seems more appropriate anyway, as swig docs say it is meant for "user-defined support code" (whereas the previous %wrapper code was for automatically-generated wrappers). It also puts the declarations into the SWIGPythonBridge header file (which seems to have been created for this purpose), and ensures it is included by all code wishing to define or use these functions. This means that any differences in the declaration become a compiler error instead of a runtime failure. Differential Revision: https://reviews.llvm.org/D114369