summaryrefslogtreecommitdiff
path: root/lldb/source/Core/PluginManager.cpp
AgeCommit message (Collapse)Author
2025-06-23[lldb] add plugin names to process save-core error output. (#143126)Ebuka Ezike
continuation of [#142684](https://github.com/llvm/llvm-project/pull/142684) to show plugin names. From issue [#14258](https://github.com/llvm/llvm-project/issues/142581)
2025-06-20[lldb] Add Model Context Protocol (MCP) support to LLDB (#143628)Jonas Devlieghere
This PR adds an MCP (Model Context Protocol ) server to LLDB. For motivation and background, please refer to the corresponding RFC: https://discourse.llvm.org/t/rfc-adding-mcp-support-to-lldb/86798 I implemented this as a new kind of plugin. The idea is that we could support multiple protocol servers (e.g. if we want to support DAP from within LLDB). This also introduces a corresponding top-level command (`protocol-server`) with two subcommands to `start` and `stop` the server. ``` (lldb) protocol-server start MCP tcp://localhost:1234 MCP server started with connection listeners: connection://[::1]:1234, connection://[127.0.0.1]:1234 ``` The MCP sever supports one tool (`lldb_command`) which executes a command, but can easily be extended with more commands.
2025-06-17[lldb] Add support to list/enable/disable remaining plugin types. (#143970)David Peixotto
In #134418 we added support to list/enable/disable `SystemRuntime` and `InstrumentationRuntime` plugins. We limited it to those two plugin types to flesh out the idea with a smaller change. This PR adds support for the remaining plugin types. We now support all the plugins that can be registered directly with the plugin manager. Plugins that are added by loading shared objects are still not supported.
2025-06-09Add commands to list/enable/disable plugins (#134418)David Peixotto
This commit adds three new commands for managing plugins. The `list` command will show which plugins are currently registered and their enabled state. The `enable` and `disable` commands can be used to enable or disable plugins. A disabled plugin will not show up to the PluginManager when it iterates over available plugins of a particular type. The purpose of these commands is to provide more visibility into registered plugins and allow users to disable plugins for experimental perf reasons. There are a few limitations to the current implementation 1. Only SystemRuntime and InstrumentationRuntime plugins are currently supported. We can easily extend the existing implementation to support more types. The scope was limited to these plugins to keep the PR size manageable. 2. Only "statically" know plugin types are supported (i.e. those managed by the PluginManager and not from `plugin load`). It is possibly we could support dynamic plugins as well, but I have not looked into it yet.
2025-05-25[lldb] Use llvm::find_if (NFC) (#141385)Kazu Hirata
2025-04-25Add symbol locator time for each module in statistics (#137379)GeorgeHuyubo
Identical PR to: https://github.com/llvm/llvm-project/pull/134563 Previous PR was approved and landed but broke the build due to bad merge. Manually resolve the merge conflict and try to land again. Co-authored-by: George Hu <georgehuyubo@gmail.com>
2025-04-25Revert "Add symbol locator time for each module in statistics (#134563)"Kazu Hirata
This reverts commit 070a4ae2f9bcf6967a7147ed2972f409eaa7d3a6. Multiple buildbot failures have been reported: https://github.com/llvm/llvm-project/pull/134563 The build fails with: lldb/source/Target/Statistics.cpp:75:39: error: use of undeclared identifier 'num_symbols_loaded'
2025-04-25Add symbol locator time for each module in statistics (#134563)GeorgeHuyubo
In statistics, add locate time for each module in statistics, we time the PluginManager::LocateExecutableSymbolFile and PluginManager::LocateExecutableObjectFile call, save the duration for the succeeded symbol locator plugin in the Module class as a map. New key being added: Module level: "_symbolLocatorTime_" Summary level: "_totalSymbolLocatorTime_" which would be a map of symbol_locator_plugin_name to time. Sample statistic dump output after this change: ``` Command: statistics dump ===============Output=============== { "commands": { "command container add": 1, "command script add": 51, "command script import": 59, "statistics dump": 1, "target create": 1, "type summary add": 36, "type synthetic add": 21 }, "memory": { "strings": { "bytesTotal": 2801664, "bytesUnused": 1704256, "bytesUsed": 1097408 } }, "modules": [ { "debugInfoByteSize": 244927, "debugInfoEnabled": true, "debugInfoHadIncompleteTypes": false, "debugInfoHadVariableErrors": false, "debugInfoIndexLoadedFromCache": false, "debugInfoIndexSavedToCache": false, "debugInfoIndexTime": 0.61934599999999995, "debugInfoParseTime": 0.00033100000000000002, "identifier": 94868115726768, "path": "/home/hyubo/.cache/llvm-debuginfod/client/llvmcache-720c9a0f5ba8b460a1524a25597226f0fa551f71-c4crasher", "symbolLocatorTime": { "debuginfod": 1.4547020000000002 }, "symbolTableIndexTime": 0.0035370000000000002, "symbolTableLoadedFromCache": false, "symbolTableParseTime": 0.0055040000000000002, "symbolTableSavedToCache": false, "symbolTableStripped": false, "triple": "x86_64--linux", "uuid": "720C9A0F-5BA8-B460-A152-4A25597226F0-FA551F71" }, { "debugInfoByteSize": 0, "debugInfoEnabled": false, "debugInfoHadIncompleteTypes": false, "debugInfoHadVariableErrors": false, "debugInfoIndexLoadedFromCache": false, "debugInfoIndexSavedToCache": false, "debugInfoIndexTime": 0, "debugInfoParseTime": 0, "identifier": 94868111142256, "path": "[vdso](0x00007ffd41c59000)", "symbolLocatorTime": { "debuginfod": 0.80597700000000005 }, "symbolTableIndexTime": 2.8e-05, "symbolTableLoadedFromCache": false, "symbolTableParseTime": 0.00037300000000000001, "symbolTableSavedToCache": false, "symbolTableStripped": false, "triple": "x86_64--linux", "uuid": "4D1F38BD-BD34-DFB3-C9A5-B49A2A912219-AC713763" }, { "debugInfoByteSize": 0, "debugInfoEnabled": false, "debugInfoHadIncompleteTypes": false, "debugInfoHadVariableErrors": false, "debugInfoIndexLoadedFromCache": false, "debugInfoIndexSavedToCache": false, "debugInfoIndexTime": 0, "debugInfoParseTime": 0, "identifier": 94868116162096, "path": "/usr/local/fbcode/platform010/lib/libc.so.6", "symbolLocatorTime": { "debuginfod": 0.286356 }, "symbolTableIndexTime": 0.0091780000000000004, "symbolTableLoadedFromCache": false, "symbolTableParseTime": 0.081841999999999998, "symbolTableSavedToCache": false, "symbolTableStripped": false, "triple": "x86_64--linux", "uuid": "ACE9DF01-8872-3A35-6D14-3C92527EF739-4BE32C75" }, { "debugInfoByteSize": 0, "debugInfoEnabled": false, "debugInfoHadIncompleteTypes": false, "debugInfoHadVariableErrors": false, "debugInfoIndexLoadedFromCache": false, "debugInfoIndexSavedToCache": false, "debugInfoIndexTime": 0, "debugInfoParseTime": 0, "identifier": 94868111990032, "path": "/usr/local/fbcode/platform010/lib/libm.so.6", "symbolLocatorTime": { "debuginfod": 0.63356699999999999 }, "symbolTableIndexTime": 0.0023960000000000001, "symbolTableLoadedFromCache": false, "symbolTableParseTime": 0.021706, "symbolTableSavedToCache": false, "symbolTableStripped": false, "triple": "x86_64--linux", "uuid": "85932B54-0DE7-4FC1-23B0-FB09AD1A5A61-8E1098B7" }, { "debugInfoByteSize": 0, "debugInfoEnabled": false, "debugInfoHadIncompleteTypes": false, "debugInfoHadVariableErrors": false, "debugInfoIndexLoadedFromCache": false, "debugInfoIndexSavedToCache": false, "debugInfoIndexTime": 0, "debugInfoParseTime": 0, "identifier": 94868116399488, "path": "/usr/local/fbcode/platform010/lib/libmvec.so.1", "symbolLocatorTime": { "debuginfod": 0.66705099999999995 }, "symbolTableIndexTime": 0.00053700000000000004, "symbolTableLoadedFromCache": false, "symbolTableParseTime": 0.0034429999999999999, "symbolTableSavedToCache": false, "symbolTableStripped": false, "triple": "x86_64--linux", "uuid": "4537CA22-8E6E-495B-7A03-FC2CEDCAD71C-8A7B2067" }, { "debugInfoByteSize": 0, "debugInfoEnabled": false, "debugInfoHadIncompleteTypes": false, "debugInfoHadVariableErrors": false, "debugInfoIndexLoadedFromCache": false, "debugInfoIndexSavedToCache": false, "debugInfoIndexTime": 0, "debugInfoParseTime": 0, "identifier": 94868111778368, "path": "/usr/local/fbcode/platform010/lib/libatomic.so.1", "symbolLocatorTime": { "debuginfod": 0.83268299999999995 }, "symbolTableIndexTime": 0.000243, "symbolTableLoadedFromCache": false, "symbolTableParseTime": 0.0026640000000000001, "symbolTableSavedToCache": false, "symbolTableStripped": false, "triple": "x86_64--", "uuid": "F90F9111-BBD1-C2A9-972A-34EB75ABE62E-3BDED9CF" }, { "debugInfoByteSize": 0, "debugInfoEnabled": false, "debugInfoHadIncompleteTypes": false, "debugInfoHadVariableErrors": false, "debugInfoIndexLoadedFromCache": false, "debugInfoIndexSavedToCache": false, "debugInfoIndexTime": 0, "debugInfoParseTime": 0, "identifier": 94868116403264, "path": "/usr/local/fbcode/platform010/lib/libgcc_s.so.1", "symbolLocatorTime": { "debuginfod": 0.58871499999999999 }, "symbolTableIndexTime": 0.000292, "symbolTableLoadedFromCache": false, "symbolTableParseTime": 0.0033, "symbolTableSavedToCache": false, "symbolTableStripped": false, "triple": "x86_64--", "uuid": "1C715A92-40BE-BE95-E148-1B401749BAB8-15D09F9D" }, { "debugInfoByteSize": 0, "debugInfoEnabled": false, "debugInfoHadIncompleteTypes": false, "debugInfoHadVariableErrors": false, "debugInfoIndexLoadedFromCache": false, "debugInfoIndexSavedToCache": false, "debugInfoIndexTime": 0, "debugInfoParseTime": 0, "identifier": 94868113225328, "path": "/usr/local/fbcode/platform010/lib/libstdc++.so.6", "symbolLocatorTime": { "debuginfod": 0.76993400000000001 }, "symbolTableIndexTime": 0.042455, "symbolTableLoadedFromCache": false, "symbolTableParseTime": 0.081374000000000002, "symbolTableSavedToCache": false, "symbolTableStripped": false, "triple": "x86_64--", "uuid": "C9DAEE53-F607-981B-6BED-F2042833BFC7-71A1E66C" }, { "debugInfoByteSize": 0, "debugInfoEnabled": false, "debugInfoHadIncompleteTypes": false, "debugInfoHadVariableErrors": false, "debugInfoIndexLoadedFromCache": false, "debugInfoIndexSavedToCache": false, "debugInfoIndexTime": 0, "debugInfoParseTime": 0, "identifier": 94868113600960, "path": "/usr/local/fbcode/platform010/lib/ld.so", "symbolLocatorTime": { "debuginfod": 0.48382199999999997 }, "symbolTableIndexTime": 0.00054799999999999998, "symbolTableLoadedFromCache": false, "symbolTableParseTime": 0.0057219999999999997, "symbolTableSavedToCache": false, "symbolTableStripped": false, "triple": "x86_64--linux", "uuid": "CCA86CF4-E4FF-42C8-7056-2F7D8B83AEE0-530B4095" } ], "targets": [ { "breakpoints": [], "dyldPluginName": "dump-modulelist-dyld", "expressionEvaluation": { "failures": 0, "successes": 0 }, "frameVariable": { "failures": 0, "successes": 0 }, "mismatchCoredumpModuleCount": 0, "moduleIdentifiers": [ 94868115726768, 94868111142256, 94868116162096, 94868111990032, 94868116399488, 94868111778368, 94868116403264, 94868113225328, 94868113600960 ], "signals": [ { "SIGABRT": 1 } ], "sourceMapDeduceCount": 0, "sourceRealpathAttemptCount": 0, "sourceRealpathCompatibleCount": 0, "stopCount": 1, "summaryProviderStatistics": [], "targetCreateTime": 4.1999999999999998e-05, "totalBreakpointResolveTime": 0, "totalSharedLibraryEventHitCount": 0 } ], "totalDebugInfoByteSize": 244927, "totalDebugInfoEnabled": 1, "totalDebugInfoIndexLoadedFromCache": 0, "totalDebugInfoIndexSavedToCache": 0, "totalDebugInfoIndexTime": 0.61934599999999995, "totalDebugInfoParseTime": 0.00033100000000000002, "totalModuleCount": 9, "totalModuleCountHasDebugInfo": 1, "totalModuleCountWithIncompleteTypes": 0, "totalModuleCountWithVariableErrors": 0, "totalSymbolLocatorTime": { "debuginfod": 6.5228070000000002 }, "totalSymbolTableIndexTime": 0.059214000000000003, "totalSymbolTableParseTime": 0.205928, "totalSymbolTableStripped": 0, "totalSymbolTablesLoadedFromCache": 0, "totalSymbolTablesSavedToCache": 0, "transcript": [ { "command": "symsrv", "commandArguments": "", "commandName": "symsrv", "durationInSeconds": 0.00069099999999999999, "error": "", "output": "", "timestampInEpochSeconds": 1744934015 }, { "command": "settings set symbols.enable-external-lookup true", "commandArguments": "symbols.enable-external-lookup true", "commandName": "settings set", "durationInSeconds": 4.1999999999999998e-05, "error": "", "output": "", "timestampInEpochSeconds": 1744934015 }, { "command": "settings insert-before plugin.symbol-locator.debuginfod.server-urls 0 https://our.intern.facebook.com/intern/debuginfod", "commandArguments": "plugin.symbol-locator.debuginfod.server-urls 0 https://our.intern.facebook.com/intern/debuginfod", "commandName": "settings insert-before", "durationInSeconds": 5.5999999999999999e-05, "error": "", "output": "", "timestampInEpochSeconds": 1744934015 }, { "command": "target create --core \"/var/tmp/cores/c4crasher.crasher.1576894\"", "commandArguments": "--core \"/var/tmp/cores/c4crasher.crasher.1576894\"", "commandName": "target create", "durationInSeconds": 6.7297630000000002, "error": "", "output": "Core file '/var/tmp/cores/c4crasher.crasher.1576894' (x86_64) was loaded.\n", "timestampInEpochSeconds": 1744934017 }, { "command": "fbpaste statistics dump", "commandArguments": "statistics dump", "commandName": "fbpaste", "timestampInEpochSeconds": 1744934055 }, { "command": "statistics dump", "commandArguments": "", "commandName": "statistics dump", "timestampInEpochSeconds": 1744934055 } ] } ``` Co-authored-by: George Hu <georgehuyubo@gmail.com>
2025-04-25[lldb][CPlusPlus] Add plugin.cplusplus.display.function-name-format setting ↵Michael Buch
(#131836) Adds the new `plugin.cplusplus.display.function-name-format` setting and makes the `${function.name-with-args}` query it for formatting the function name. One caveat is that the setting can't itself be set to `${function.name-with-args}` because that would cause infinite recursion and blow the stack. I added an XFAILed test-case for it and will address it in a follow-up patch. https://github.com/llvm/llvm-project/pull/131836
2025-04-02Add enable/disable api for SystemRuntime plugins (#133794)David Peixotto
This commit adds support for enabling and disabling plugins by name. The changes are made generically in the `PluginInstances` class, but currently we only expose the ability to SystemRuntime plugins. Other plugins types can be added easily. We had a few design goals for how disabled plugins should work 1. Plugins that are disabled should still be visible to the system. This allows us to dynamically enable and disable plugins and report their state to the user. 2. Plugin order should be stable across disable and enable changes. We want avoid changing the order of plugin lookup. When a plugin is re-enabled it should return to its original slot in the creation order. 3. Disabled plugins should not appear in PluginManager operations. Clients should be able to assume that only enabled plugins will be returned from the PluginManager. For the implementation we modify the plugin instance to maintain a bool of its enabled state. Existing clients external to the Instances class expect to iterate over only enabled instance so we skip over disabed instances in the query and snapshot apis. This way the client does not have to manually check which instances are enabled.
2025-03-31[lldb] Remove raw access to PluginInstances vector (#132884)David Peixotto
Remove raw access to PluginInstances vector This commit modifies the PluginInstances class to remove direct access to the m_instances vector. Instead, we expose a new `GetSnapshot` method that returns a copy of the current state of the instances vector. All external iteration over the instances is updated to use the new method. The motivation for the change is to allow modifying the way we store instances without having to change all the clients. This is a preliminary change to allow enabling/disabling of plugins in which case we want to iterate over only enabled plugins. We also considered using a custom iterator that wraps the vector iterator and can skip over disabled instances. That works, but the iterator code is a bit messy with all template and typedefs to make a compliant iterator.
2024-11-26Fix return value of 'PluginManager::RegisterPlugin()'. (#114120)Miro Bucko
2024-09-05[lldb] Make conversions from llvm::Error explicit with Status::FromEr… ↵Adrian Prantl
(#107163) …ror() [NFC]
2024-08-27[lldb] Turn lldb_private::Status into a value type. (#106163)Adrian Prantl
This patch removes all of the Set.* methods from Status. This cleanup is part of a series of patches that make it harder use the anti-pattern of keeping a long-lives Status object around and updating it while dropping any errors it contains on the floor. This patch is largely NFC, the more interesting next steps this enables is to: 1. remove Status.Clear() 2. assert that Status::operator=() never overwrites an error 3. remove Status::operator=() Note that step (2) will bring 90% of the benefits for users, and step (3) will dramatically clean up the error handling code in various places. In the end my goal is to convert all APIs that are of the form ` ResultTy DoFoo(Status& error) ` to ` llvm::Expected<ResultTy> DoFoo() ` How to read this patch? The interesting changes are in Status.h and Status.cpp, all other changes are mostly ` perl -pi -e 's/\.SetErrorString/ = Status::FromErrorString/g' $(git grep -l SetErrorString lldb/source) ` plus the occasional manual cleanup.
2024-08-15[LLDB] Reapply #100443 SBSaveCore Thread list (#104497)Jacob Lalonde
Reapply #100443 and #101770. These were originally reverted due to a test failure and an MSAN failure. I changed the test attribute to restrict to x86 (following the other existing tests). I could not reproduce the test or the MSAN failure and no repo steps were provided.
2024-08-05Revert "[LLDB][SBSaveCore] Implement a selectable threadlist for Core… ↵Jacob Lalonde
(#102018) … Options. (#100443)" This reverts commit 3e4af616334eae532f308605b89ff158dd195180. @adrian-prantl FYI Reverts #100443
2024-08-05Revert "[LLDB][SBSaveCore] Fix bug where default values are not propagated. ↵Haojian Wu
(#101770)" This reverts commit 34766d0d488ba2fbefa80dcd0cc8720a0e753448 which caused a msan failure, see comment https://github.com/llvm/llvm-project/pull/101770#issuecomment-2268373325 for details.
2024-08-02[LLDB][SBSaveCore] Fix bug where default values are not propagated. (#101770)Jacob Lalonde
In #100443, Mach-o and Minidump now only call process API's that take a `SaveCoreOption` as the container for the style and information if a thread should be included in the core or not. This introduced a bug where in subsequent method calls we were not honoring the defaults of both implementations. ~~To solve this I have made a copy of each SaveCoreOptions that is mutable by the respective plugin. Originally I wanted to leave the SaveCoreOptions as non const so these default value mutations could be shown back to the user. Changing that behavior is outside of the scope of this bugfix, but is context for why we are making a copy.~~ Removed const on the savecoreoptions so defaults can be inspected by the user CC: @Michael137
2024-08-02[LLDB][SBSaveCore] Implement a selectable threadlist for Core Options. ↵Jacob Lalonde
(#100443) In #98403 I enabled the SBSaveCoreOptions object, which allows users via the scripting API to define what they want saved into their core file. As the first option I've added a threadlist, so users can scan and identify which threads and corresponding stacks they want to save. In order to support this, I had to add a new method to `Process.h` on how we identify which threads are to be saved, and I had to change the book keeping in minidump to ensure we don't double save the stacks. Important to @jasonmolenda I also changed the MachO coredump to accept these new APIs.
2024-07-27[lldb/Commands] Add `scripting template list` command with auto discoveryMed Ismail Bennani
This patch introduces a new `template` multiword sub-command to the `scripting` top-level command. As the name suggests, this sub-command operates on scripting templates, and currently has the ability to automatically discover the various scripting extensions that lldb supports. This was previously reviewed in #97273. Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2024-07-25[lldb] Revert scripting template list patches (#100673)Med Ismail Bennani
Reverts https://github.com/llvm/llvm-project/pull/97273 since it broke the windows bot: https://lab.llvm.org/buildbot/#/builders/141/builds/1025/steps/4/logs/stdio
2024-07-25[lldb/Commands] Add `scripting template list` command with auto discoveryMed Ismail Bennani
This patch introduces a new `template` multiword sub-command to the `scripting` top-level command. As the name suggests, this sub-command operates on scripting templates, and currently has the ability to automatically discover the various scripting extensions that lldb supports. This was previously reviewed in #97273. Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2024-07-23Revert "[lldb/Commands] Add `scripting template list` command with auto ↵Med Ismail Bennani
discovery" (#100273) Reverts llvm/llvm-project#97273 since it broke the windows bot: https://lab.llvm.org/buildbot/#/builders/141/builds/1025/steps/4/logs/stdio
2024-07-23[lldb/Commands] Add `scripting template list` command with auto discovery ↵Med Ismail Bennani
(#97273) This patch introduces a new `template` multiword sub-command to the `scripting` top-level command. As the name suggests, this sub-command operates on scripting templates, and currently has the ability to automatically discover the various scripting extensions that lldb supports. Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2024-07-18[LLDB][SaveCore] Add SBSaveCoreOptions Object, and SBProcess::SaveCore() ↵Jacob Lalonde
overload (#98403) This PR adds `SBSaveCoreOptions`, which is a container class for options when LLDB is taking coredumps. For this first iteration this container just keeps parity with the extant API of `file, style, plugin`. In the future this options object can be extended to allow users to take a subset of their core dumps.
2023-12-16[lldb] Use StringRef::{starts,ends}_with (NFC)Kazu Hirata
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2023-12-04DEBUGINFOD based DWP acquisition for LLDB (#70996)Kevin Frei
I've plumbed the LLVM DebugInfoD client into LLDB, and added automatic downloading of DWP files to the SymbolFileDWARF.cpp plugin. If you have DEBUGINFOD_URLS set to a space delimited set of web servers, LLDB will try to use them as a last resort when searching for DWP files. If you do *not* have that environment variable set, nothing should be changed. There's also a setting, per @clayborg 's suggestion, that will override the environment variable, or can be used instead of the environment variable. The setting is why I also needed to add an API to the llvm-debuginfod library ### Test Plan: Suggestions are welcome here. I should probably have some positive and negative tests, but I wanted to get the diff up for people who have a clue what they're doing to rip it to pieces before spending too much time validating the initial implementation. --------- Co-authored-by: Kevin Frei <freik@meta.com> Co-authored-by: Alex Langford <nirvashtzero@gmail.com>
2023-11-04[lldb] Move DownloadObjectAndSymbolFile to SymbolLocator plugin (#71267)Jonas Devlieghere
This builds on top of the work started in c3a302d to convert LocateSymbolFile to a SymbolLocator plugin. This commit moves DownloadObjectAndSymbolFile.
2023-11-03[lldb] Move LocateExecutableSymbolFile to SymbolLocator plugin (#71266)Jonas Devlieghere
This builds on top of the work started in c3a302d to convert LocateSymbolFile to a SymbolLocator plugin. This commit moves LocateExecutableSymbolFile.
2023-11-03[lldb] Move FindSymbolFileInBundle to SymbolLocator plugin (#71247)Jonas Devlieghere
This builds on top of the work started in c3a302d to convert LocateSymbolFile to a SymbolLocator plugin. This commit moves FindSymbolFileInBundle.
2023-11-03[lldb] Convert LocateSymbolFile into a plugin (#71151)Jonas Devlieghere
This commit contains the initial scaffolding to convert the functionality currently implemented in LocateSymbolFile to a plugin architecture. The plugin approach allows us to easily add new ways to find symbols and fixes some issues with the current implementation. For instance, currently we (ab)use the host OS to include support for querying the DebugSymbols framework on macOS. The plugin approach retains all the benefits (including the ability to compile this out on other platforms) while maintaining a higher level of separation with the platform independent code. To limit the scope of this patch, I've only converted a single function: LocateExecutableObjectFile. Future commits will convert the remaining LocateSymbolFile functions and eventually remove LocateSymbolFile. To make reviewing easier, that will done as follow-ups.
2023-06-27[lldb][NFCI] Remove use of ConstString from PluginManagerAlex Langford
The underlying structures no longer use ConstString so we can remove it wholesale from PluginManager now. Differential Revision: https://reviews.llvm.org/D153818
2023-06-26[lldb][NFCI] Remove unneeded ConstString constructions for ↵Alex Langford
OptionValueProperties::AppendProperty I removed ConstString from OptionValueProperties in 643ba926c1f6, but there are a few call sites that still create a ConstString as an argument. I did not catch these initially because ConstString has an implicit conversion method to StringRef. Differential Revision: https://reviews.llvm.org/D153673
2023-04-19[lldb] Change setting descriptions to use StringRef instead of ConstStringAlex Langford
These probably do not need to be in the ConstString StringPool as they don't really need any of the advantages that ConstStrings offer. Lifetime for these things is always static and we never need to perform comparisons for setting descriptions. Differential Revision: https://reviews.llvm.org/D148679
2023-04-13[lldb] Show register fields using bitfield struct typesDavid Spickett
This change uses the information from target.xml sent by the GDB stub to produce C types that we can use to print register fields. lldb-server *does not* produce this information yet. This will only work with GDB stubs that do. gdbserver or qemu are 2 I know of. Testing is added that uses a mocked lldb-server. ``` (lldb) register read cpsr x0 fpcr fpsr x1 cpsr = 0x60001000 = (N = 0, Z = 1, C = 1, V = 0, TCO = 0, DIT = 0, UAO = 0, PAN = 0, SS = 0, IL = 0, SSBS = 1, BTYPE = 0, D = 0, A = 0, I = 0, F = 0, nRW = 0, EL = 0, SP = 0) ``` Only "register read" will display fields, and only when we are not printing a register block. For example, cpsr is a 32 bit register. Using the target's scratch type system we construct a type: ``` struct __attribute__((__packed__)) cpsr { uint32_t N : 1; uint32_t Z : 1; ... uint32_t EL : 2; uint32_t SP : 1; }; ``` If this register had unallocated bits in it, those would have been filled in by RegisterFlags as anonymous fields. A new option "SetChildPrintingDecider" is added so we can disable printing those. Important things about this type: * It is packed so that sizeof(struct cpsr) == sizeof(the real register). (this will hold for all flags types we create) * Each field has the same storage type, which is the same as the type of the raw register value. This prevents fields being spilt over into more storage units, as is allowed by most ABIs. * Each bitfield size matches that of its register field. * The most significant field is first. The last point is required because the most significant bit (MSB) being on the left/top of a print out matches what you'd expect to see in an architecture manual. In addition, having lldb print a different field order on big/little endian hosts is not acceptable. As a consequence, if the target is little endian we have to reverse the order of the fields in the value. The value of each field remains the same. For example 0b01 doesn't become 0b10, it just shifts up or down. This is needed because clang's type system assumes that for a struct like the one above, the least significant bit (LSB) will be first for a little endian target. We need the MSB to be first. Finally, if lldb's host is a different endian to the target we have to byte swap the host endian value to match the endian of the target's typesystem. | Host Endian | Target Endian | Field Order Swap | Byte Order Swap | |-------------|---------------|------------------|-----------------| | Little | Little | Yes | No | | Big | Little | Yes | Yes | | Little | Big | No | Yes | | Big | Big | No | No | Testing was done as follows: * Little -> Little * LE AArch64 native debug. * Big -> Little * s390x lldb running under QEMU, connected to LE AArch64 target. * Little -> Big * LE AArch64 lldb connected to QEMU's GDB stub, which is running an s390x program. * Big -> Big * s390x lldb running under QEMU, connected to another QEMU's GDB stub, which is running an s390x program. As we are not allowed to link core code to plugins directly, I have added a new plugin RegisterTypeBuilder. There is one implementation of this, RegisterTypeBuilderClang, which uses TypeSystemClang to build the CompilerType from the register fields. Reviewed By: jasonmolenda Differential Revision: https://reviews.llvm.org/D145580
2022-10-25[trace][intel pt] Simple detection of infinite decoding loopsWalter Erquinigo
The low-level decoder might fall into an infinite decoding loop for various reasons, the simplest being an infinite direct loop reached due to wrong handling of self-modified code in the kernel, e.g. it might reach ``` 0x0A: pause 0x0C: jump to 0x0A ``` In this case, all the code is sequential and requires no packets to be decoded. The low-level decoder would produce an output like the following ``` 0x0A: pause 0x0C: jump to 0x0A 0x0A: pause 0x0C: jump to 0x0A 0x0A: pause 0x0C: jump to 0x0A ... infinite amount of times ``` These cases require stopping the decoder to avoid infinite work and signal this at least as a trace error. - Add a check that breaks decoding of a single PSB once 500k instructions have been decoded since the last packet was processed. - Add a check that looks for infinite loops after certain amount of instructions have been decoded since the last packet was processed. - Add some `settings` properties for tweaking the thresholds of the checks above. This is also nice because it does the basic work needed for future settings. - Add an AnomalyDetector class that inspects the DecodedThread and the libipt decoder in search for anomalies. These anomalies are then signaled as fatal errors in the trace. - Add an ErrorStats class that keeps track of all the errors in a DecodedThread, with a special counter for fatal errors. - Add an entry for decoded thread errors in the `dump info` command. Some notes are added in the code and in the documention of the settings, so please read them. Besides that, I haven't been unable to create a test case in LLVM style, but I've found an anomaly in the thread #12 of the trace 72533820-3eb8-4465-b8e4-4e6bf0ccca99 at Meta. We have to figure out how to artificially create traces with this kind of anomalies in LLVM style. With this change, that anomalous thread now shows: ``` (lldb)thread trace dump instructions 12 -e -i 23101 thread #12: tid = 8 ...missing instructions 23101: (error) anomalous trace: possible infinite loop detected of size 2 vmlinux-5.12.0-0_fbk8_clang_6656_gc85768aa64da`panic_smp_self_stop + 5 [inlined] rep_nop at processor.h:13:2 23100: 0xffffffff81342785 pause vmlinux-5.12.0-0_fbk8_clang_6656_gc85768aa64da`panic_smp_self_stop + 7 at panic.c:87:2 23099: 0xffffffff81342787 jmp 0xffffffff81342785 ; <+5> [inlined] rep_nop at processor.h:13:2 vmlinux-5.12.0-0_fbk8_clang_6656_gc85768aa64da`panic_smp_self_stop + 5 [inlined] rep_nop at processor.h:13:2 23098: 0xffffffff81342785 pause vmlinux-5.12.0-0_fbk8_clang_6656_gc85768aa64da`panic_smp_self_stop + 7 at panic.c:87:2 23097: 0xffffffff81342787 jmp 0xffffffff81342785 ; <+5> [inlined] rep_nop at processor.h:13:2 vmlinux-5.12.0-0_fbk8_clang_6656_gc85768aa64da`panic_smp_self_stop + 5 [inlined] rep_nop at processor.h:13:2 23096: 0xffffffff81342785 pause vmlinux-5.12.0-0_fbk8_clang_6656_gc85768aa64da`panic_smp_self_stop + 7 at panic.c:87:2 23095: 0xffffffff81342787 jmp 0xffffffff81342785 ; <+5> [inlined] rep_nop at processor.h:13:2 ``` It used to be in an infinite loop where the decoder never stopped. Besides that, the dump info command shows ``` (lldb) thread trace dump info 12 Errors: Number of individual errors: 32 Number of fatal errors: 1 Number of other errors: 31 ``` and in json format ``` (lldb) thread trace dump info 12 -j "errors": { "totalCount": 32, "libiptErrors": {}, "fatalErrors": 1, "otherErrors": 31 } ``` Differential Revision: https://reviews.llvm.org/D136557
2022-08-25[lldb] Teach LLDB about Mach-O filesetsJonas Devlieghere
This patch teaches LLDB about Mach-O filesets. Filsets are Mach-O files that contain a bunch of other Mach-O files. Unlike universal binaries, which have a different header, Filesets use load commands to describe the different entries it contains. Differential revision: https://reviews.llvm.org/D132433
2022-06-24[NFC][lldb][trace] Rename trace session to trace bundleWalter Erquinigo
As previously discussed with @jj10306, we didn't really have a name for the post-mortem (or offline) trace session representation, which is in fact a folder with a bunch of files. We decided to call this folder "trace bundle", and the main JSON file in it "trace bundle description file". This naming is pretty decent, so I'm refactoring all the existing code to account for that. Differential Revision: https://reviews.llvm.org/D128484
2022-06-09[lldb] Set COFF module ABI from default triple and make it an optionAlvin Wong
PE/COFF can use either MSVC or GNU (MinGW) ABI for C++ code, however LLDB had defaulted to MSVC implicitly with no way to override it. This causes issues when debugging modules built with the GNU ABI, sometimes even crashes. This changes the PE/COFF plugin to set the module triple according to the default target triple used to build LLDB. If the default target triple is Windows and a valid environment is specified, then this environment will be used for the module spec. This not only works for MSVC and GNU, but also other environments. A new setting, `plugin.object-file.pe-coff.abi`, has been added to allow overriding this default ABI. * Fixes https://github.com/llvm/llvm-project/issues/50775 * Fixes https://github.com/mstorsjo/llvm-mingw/issues/226 * Fixes https://github.com/mstorsjo/llvm-mingw/issues/282 Reviewed By: omjavaid Differential Revision: https://reviews.llvm.org/D127048
2021-12-14[lldb] Check if language is supported before creating a REPL instanceJonas Devlieghere
Currently, we'll try to instantiate a ClangREPL for every known language. The plugin manager already knows what languages it supports, so rely on that to only instantiate a REPL when we know the requested language is supported. rdar://86439474 Differential revision: https://reviews.llvm.org/D115698
2021-11-03[lldb] Remove ConstString from plugin names in PluginManager innardsPavel Labath
This completes de-constification of plugin names.
2021-11-02[lldb] Remove ConstString from TypeSystem and REPL plugin namesPavel Labath
2021-10-29[lldb] Remove ConstString from SymbolVendor, Trace, TraceExporter, ↵Pavel Labath
UnwindAssembly, MemoryHistory and InstrumentationRuntime plugin names
2021-10-28[lldb] Remove ConstString from Process, ScriptInterpreter and StructuredData ↵Pavel Labath
plugin names
2021-10-27Remove ConstString from Language, LanguageRuntime, SystemRuntime and ↵Pavel Labath
SymbolFile plugin names
2021-10-26[lldb] Remove ConstString from Platform plugin namesPavel Labath
2021-10-25Remove ConstString from DynamicLoader, JITLoader and Instruction plugin namesPavel Labath
2021-10-22[lldb] Remove ConstString from ABI, Architecture and Disassembler plugin namesPavel Labath
2021-10-21[lldb] Fix a thinko in 2ace1e57Pavel Labath
An empty plugin name means we should try everything. Picked up by the windows bot.
2021-10-21[lldb] Remove ConstString from GetPluginNameStatic of some pluginsPavel Labath
This patch deals with ObjectFile, ObjectContainer and OperatingSystem plugins. I'll convert the other types in separate patches. In order to enable piecemeal conversion, I am leaving some ConstStrings in the lowest PluginManager layers. I'll convert those as the last step. Differential Revision: https://reviews.llvm.org/D112061