summaryrefslogtreecommitdiff
path: root/lldb/examples/python
AgeCommit message (Collapse)Author
2021-12-06[lldb/plugins] Add arm64(e) support to ScriptedProcessMed Ismail Bennani
This patch adds support for arm64(e) targets to ScriptedProcess, by providing the `DynamicRegisterInfo` to the base `lldb.ScriptedThread` class. This allows create and debugging ScriptedProcess on Apple Silicon hardware as well as Apple mobile devices. It also replace the C++ asserts on `ScriptedThread::GetDynamicRegisterInfo` by some error logging, re-enables `TestScriptedProcess` for arm64 Darwin platforms and adds a new invalid Scripted Thread test. rdar://85892451 Differential Revision: https://reviews.llvm.org/D114923 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-11-10[lldb/test] Update TestScriptedProcess to use skinny corefilesMed Ismail Bennani
This patch changes the ScriptedProcess test to use a stack-only skinny corefile as a backing store. The corefile is saved as a temporary file at the beginning of the test, and a second target is created for the ScriptedProcess. To do so, we use the SBAPI from the ScriptedProcess' python script to interact with the corefile process. This patch also makes some small adjustments to the other ScriptedProcess scripts to resolve some inconsistencies and removes the raw memory dump that was previously checked in. Differential Revision: https://reviews.llvm.org/D112047 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-11-10[lldb/bindings] Change ScriptedThread initializer parametersMed Ismail Bennani
This patch changes the `ScriptedThread` initializer in couple of ways: - It replaces the `SBTarget` parameter by a `SBProcess` (pointing to the `ScriptedProcess` that "owns" the `ScriptedThread`). - It adds a reference to the `ScriptedProcessInfo` Dictionary, to pass arbitrary user-input to the `ScriptedThread`. This patch also fixes the SWIG bindings methods that call the `ScriptedProcess` and `ScriptedThread` initializers by passing all the arguments to the appropriate `PythonCallable` object. Differential Revision: https://reviews.llvm.org/D112046 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-10-08[lldb/Plugins] Add memory region support in ScriptedProcessMed Ismail Bennani
This patch adds support for memory regions in Scripted Processes. This is necessary to read the stack memory region in order to reconstruct each stackframe of the program. In order to do so, this patch makes some changes to the SBAPI, namely: - Add a new constructor for `SBMemoryRegionInfo` that takes arguments such as the memory region name, address range, permissions ... This is used when reading memory at some address to compute the offset in the binary blob provided by the user. - Add a `GetMemoryRegionContainingAddress` method to `SBMemoryRegionInfoList` to simplify the access to a specific memory region. With these changes, lldb is now able to unwind the stack and reconstruct each frame. On top of that, reloading the target module at offset 0 allows lldb to symbolicate the `ScriptedProcess` using debug info, similarly to an ordinary Process. To test this, I wrote a simple program with multiple function calls, ran it in lldb, stopped at a leaf function and read the registers values and copied the stack memory into a binary file. These are then used in the python script. Differential Revision: https://reviews.llvm.org/D108953 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-10-08[lldb/Plugins] Add support for ScriptedThread in ScriptedProcessMed Ismail Bennani
This patch introduces the `ScriptedThread` class with its python interface. When used with `ScriptedProcess`, `ScriptedThreaad` can provide various information such as the thread state, stop reason or even its register context. This can be used to reconstruct the program stack frames using lldb's unwinder. rdar://74503836 Differential Revision: https://reviews.llvm.org/D107585 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-10-07[lldb] Parse and display reporting errors from JSON crashlogsJonas Devlieghere
JSON crashlogs have an optional field named reportNotes that contains any potential errors encountered by the crash reporter when generating the crashlog. Parse and display them in LLDB. Differential revision: https://reviews.llvm.org/D111339
2021-10-07[lldb] Support missing threadState in JSON crashlogsJonas Devlieghere
Gracefully deal with JSON crashlogs that don't have thread state available and print an error saying as much: "No thread state (register information) available". rdar://83955858 Differential revision: https://reviews.llvm.org/D111341
2021-10-05[lldb] Improve meta data stripping from JSON crashlogsJonas Devlieghere
JSON crashlogs normally start with a single line of meta data that we strip unconditionally. Some producers started omitting the meta data which tripped up crashlog. Be more resilient by only removing the first line when we know it really is meta data. rdar://82641662
2021-09-20[lldb][crashlog] Avoid specifying arch for image when a UUID is presentVedant Kumar
When adding an image to a target for crashlog purposes, avoid specifying the architecture of the image. This has the effect of making SBTarget::AddModule infer the ArchSpec for the image based on the SBTarget's architecture, which LLDB puts serious effort into calculating correctly (in TargetList::CreateTargetInternal). The status quo is that LLDB randomly guesses the ArchSpec for a module if its architecture is specified, via: ``` SBTarget::AddModule -> Platform::GetAugmentedArchSpec -> Platform::IsCompatibleArchitecture -> GetSupportedArchitectureAtIndex -> {ARM,x86}GetSupportedArchitectureAtIndex ``` ... which means that the same crashlog can fail to load on an Apple Silicon Mac (due to the random guess of arm64e-apple-macosx for the module's ArchSpec not being compatible with the SBTarget's (correct) ArchSpec), while loading just fine on an Intel Mac. I'm not sure how to add a test for this (it doesn't look like there's test coverage of this path in-tree). It seems like it would be pretty complicated to regression test: the host LLDB would need to be built for arm64e, we'd need a hand-crafted arm64e iOS crashlog, and we'd need a binary with an iOS deployment target. I'm open to other / simpler options. rdar://82679400 Differential Revision: https://reviews.llvm.org/D110013
2021-09-07[lldb] Update crashlog.py to accept multiple results from mdfindJonas Devlieghere
mdfind can return multiple results, some of which are not even dSYM bundles, but Xcode archives (.xcrachive). Currently, we end up concatenating the paths, which is obviously bogus. This patch not only fixes that, but now also skips paths that don't have a Contents/Resources/DWARF subdirectory. rdar://81270312 Differential revision: https://reviews.llvm.org/D109263
2021-09-03[lldb] Adjust parse_frames for unnamed imagesJonas Devlieghere
Follow up to 2cbd3b04feaaaff7fab4c6500476839a23180886 which added support for unnamed images but missed the use case in parse_frames.
2021-07-22[lldb/Plugins] Add ScriptedProcess Process PluginMed Ismail Bennani
This patch introduces Scripted Processes to lldb. The goal, here, is to be able to attach in the debugger to fake processes that are backed by script files (in Python, Lua, Swift, etc ...) and inspect them statically. Scripted Processes can be used in cooperative multithreading environments like the XNU Kernel or other real-time operating systems, but it can also help us improve the debugger testing infrastructure by writting synthetic tests that simulates hard-to-reproduce process/thread states. Although ScriptedProcess is not feature-complete at the moment, it has basic execution capabilities and will improve in the following patches. rdar://65508855 Differential Revision: https://reviews.llvm.org/D100384 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-07-02[lldb] Update shebang in heap.py and crashlog.pyJonas Devlieghere
2021-05-31[lldb] Fix typos. NFC.Bruce Mitchener
Differential Revision: https://reviews.llvm.org/D103381
2021-04-24[lldb] [gdb-remote server] Introduce new stop reasons for fork and vforkMichał Górny
Introduce three new stop reasons for fork, vfork and vforkdone events. This includes server support for serializing fork/vfork events into gdb-remote protocol. The stop infos for the two base events take a pair of PID and TID for the newly forked process. Differential Revision: https://reviews.llvm.org/D100196
2021-04-22[lldb] Update register state parsing for JSON crashlogsJonas Devlieghere
- The register encoding state in the JSON crashlog format changes. Update the parser accordingly. - Print the register state when printing the symbolicated thread.
2021-04-22[lldb] Include thread name in crashlog.py outputJonas Devlieghere
Update the JSON parser to include the thread name in the Thread object. rdar://76677320
2021-04-19[lldb] Support "absolute memory address" images in crashlog.pyJonas Devlieghere
The binary image list contains the following entry when a frame is not found in any know binary image: { "size" : 0, "source" : "A", "base" : 0, "uuid" : "00000000-0000-0000-0000-000000000000" } Note that this object is missing the name and path keys. This patch makes the JSON parser resilient against their absence.
2021-04-15[lldb] Raise a CrashLogParseException when failing to parse JSON crashlogJonas Devlieghere
Throw an exception with an actually helpful message when we fail to parse a JSON crashlog.
2021-03-23[lldb/bindings] Add Python ScriptedProcess base class to lldb moduleMed Ismail Bennani
In order to facilitate the writting of Scripted Processes, this patch introduces a `ScriptedProcess` python base class in the lldb module. The base class holds the python interface with all the - abstract - methods that need to be implemented by the inherited class but also some methods that can be overwritten. This patch also provides an example of a Scripted Process with the `MyScriptedProcess` class. rdar://65508855 Differential Revision: https://reviews.llvm.org/D95712 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-03-09[lldb] Update crashlog script for JSON changesJonas Devlieghere
Update the crashlog script for changes to the JSON schema. rdar://75122914 Differential revision: https://reviews.llvm.org/D98219
2021-03-01[lldb] Revert ScriptedProcess patchesMed Ismail Bennani
This patch reverts the following commits: - 5a9c34918bb1526b7e8c29aa5e4fb8d8e27e27b4 - 46796762afe76496ec4dd900f64d0cf4cdc30e99 - 2cff3dec1171188ce04ab1a4373cc1885ab97be1 - 182f0d1a34419445bb19d67581d6ac1afc98b7fa - d62a53aaf1d38a55d1affbd3a30d564a4e9d3171 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-03-01[lldb/bindings] Add Python ScriptedProcess base class to lldb moduleMed Ismail Bennani
In order to facilitate the writting of Scripted Processes, this patch introduces a `ScriptedProcess` python base class in the lldb module. The base class holds the python interface with all the - abstract - methods that need to be implemented by the inherited class but also some methods that can be overwritten. This patch also provides an example of a Scripted Process with the `MyScriptedProcess` class. rdar://65508855 Differential Revision: https://reviews.llvm.org/D95712 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-12-03[lldb] Refactor the Symbolicator initializerJonas Devlieghere
We found out that we have clients relying on the old signature of the Symbolicator initializer. Make the signature compatible again and provide a factory method to initialize the class correctly based on whether you have a target or want the symbolicator to create one for you. Differential revision: D92601
2020-11-16[crashlog] Implement parser for JSON encoded crashlogsJonas Devlieghere
Add a parser for JSON crashlogs. The CrashLogParser now defers to either the JSONCrashLogParser or the TextCrashLogParser. It first tries to interpret the input as JSON, and if that fails falling back to the textual parser. Differential revision: https://reviews.llvm.org/D91130
2020-11-04[crashlog] Pass the debugger around instead of relying on lldb.debuggerJonas Devlieghere
The lldb.debugger et al convenience variables are only available from the interactive script interpreter. In all other scenarios, they are None (since fc1fd6bf9fcfac412b10b4193805ec5de0e8df57) before that they were default initialized. The crashlog script was hacking around that by setting the lldb.debugger to a newly created debugger instance when running outside of the script interpreter, which works fine until lldb creates a script interpreter instance under the hood and clears the variables. This was resulting in an AttributeError when invoking the script directly (from outside of lldb): AttributeError: 'NoneType' object has no attribute 'GetSourceManager' This patch fixes that by passing around the debugger instance. rdar://64775776 Differential revision: https://reviews.llvm.org/D90706
2020-11-03[crashlog] Print the actual exception in the CommandReturnObjectJonas Devlieghere
Before: error: python exception <class 'AttributeError'> After: error: python exception: 'DarwinImage' object has no attribute 'debugger'
2020-11-03[crashlog] Modularize parserJonas Devlieghere
Instead of parsing the crashlog in one big loop, use methods that correspond to the different parsing modes. Differential revision: https://reviews.llvm.org/D90665
2020-11-03[crashlog] Move crash log parsing into its own classJonas Devlieghere
Move crash log parsing out of the CrashLog class and into its own class and add more tests. Differential revision: https://reviews.llvm.org/D90664
2020-11-02[crashlog] Remove commented out code (NFC)Jonas Devlieghere
Remove commented out code and print statements.
2020-11-02[crashlog] Turn crash log parsing modes into a Python 'enum' (NFC)Jonas Devlieghere
Python doesn't support enums before PEP 435, but using a class with constants is how it's commonly emulated. It can be converted into a real Enum (in Python 3.4 and later) by extending the Enum class: class CrashLogParseMode(Enum): NORMAL = 0 THREAD = 1 IMAGES = 2 THREGS = 3 SYSTEM = 4 INSTRS = 5
2020-11-02[crashlog] Fix and simplify the way we import lldbJonas Devlieghere
Don't try to guess the location of LLDB.framework but use xcrun to ask the command line driver for the location of the lldb module.
2020-10-30[lldb] Ignore binary data in crashlogJonas Devlieghere
Skip the instruction stream section in the crashlog section. Differential revision: https://reviews.llvm.org/D90414
2020-07-16Harmonize Python shebangserge-sans-paille
Differential Revision: https://reviews.llvm.org/D83857
2020-05-28Fix the crashlog.py script's use of the load_address property.Jim Ingham
This property is explicitly for use only in the interactive editor, and NOT in commands. It's use worked until we got more careful about not leaving lldb.target lying around in the script interpreter. I also added a quick sniff test for the save_crashlog command. <rdar://problem/60350620> Differential Revision: https://reviews.llvm.org/D80680
2020-04-07[lldb] NFC: Fix trivial typo in comments, documents, and messagesKazuaki Ishizaki
Differential Revision: https://reviews.llvm.org/D77460
2020-02-13[lldb] Make gdbremote.py utility py2and3 compatiblePavel Labath
2019-11-22[Examples] Move structured-data unpacking out of the loop. (NFC)Jonas Devlieghere
There's no need to repeat this work in the loop.
2019-11-22[Examples] Add in_call_stack breakpoint function.Jonas Devlieghere
The in_call_stack Python script makes it possible to modify the last breakpoint to only stop if a given function is present in the call stack. It will check both the symbol name and the function name (coming from the debug info, in case the binary is stripped). To use this, you have to: 1. Import the script into lldb. (lldb) command script import in_call_stack.py 2. Set a breakpoint and use the in_call_stack alias. (lldb) b foo (lldb) in_call_stack bar Note that this alias operates on the last set breakpoint. You can re-run the in_call_stack command to modify the condition.
2019-11-07crashlog.py: Improve regular expressionsAdrian Prantl
This is yet another change to the regular expressions in crashlog.py that fix a few edge cases, and attempt to improve the readability quite a bit in the process. My last change to support spaces in filenames introduced a bug that caused the version/archspec field to be parsed as part of the image name. For example, in "0x1111111 - 0x22222 +MyApp Pro arm64 <01234>", the name of the image was recognized as "MyApp Pro arm64" instead of "MyApp Pro" with a "version" of arm64. The bugfix makes the space following an optional field mandatory *inside* the optional group. rdar://problem/56883435 Differential Revision: https://reviews.llvm.org/D69871
2019-07-29[Symbolication] Remove some dead code. Nothing exciting.Davide Italiano
llvm-svn: 367262
2019-07-29[Symbolication] Remove a duplicate assignment.Davide Italiano
llvm-svn: 367261
2019-07-29[Symbolication] Fix unicode compatibility between 2 and 3.Davide Italiano
Triples are always ASCII for now, but we were handed out a unicode object. <rdar://problem/53592772> llvm-svn: 367260
2019-07-09[crashlog] Fix a mismatch between bytes and strings.Davide Italiano
The functions in read_plist() want bytes as input, not strings. <rdar://problem/52600712> llvm-svn: 365416
2019-06-26Use the // integer divide operator in these Jason Molenda
target definition files, like Davide's change to x86_64_target_definition.py. llvm-svn: 364481
2019-06-26[x86-64] Use `//` for integer division in the target definition.Davide Italiano
This forces integer division and works with python 2 and python 3. <rdar://problem/52073911> llvm-svn: 364465
2019-06-14Python 3: decode string as utf-8 to avoid type mismatch.Adrian Prantl
rdar://problem/51464644 Differential Revision: https://reviews.llvm.org/D63311 llvm-svn: 363413
2019-06-14Make crashlog.py less noisyAdrian Prantl
For end-users there is no point in printing dSYM load errors for system frameworks, since they will all fail and there's nothing they can do about it. This patch hides them by default and shows them when --verbose is present. Differential Revision: https://reviews.llvm.org/D63310 llvm-svn: 363412
2019-06-12[lldb] Ignore null frames in lldb.macosx crashlogStefan Granitz
llvm-svn: 363172
2019-05-30[crashlog] Add a missing call to decode.Davide Italiano
<rdar://problem/51139357> llvm-svn: 362044