157 Commits

Author SHA1 Message Date
GeorgeHuyubo
77f8335a07
Add symbol locator time for each module in statistics (#137379)
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-25 11:48:31 -07:00
Kazu Hirata
bc716a755a Revert "Add symbol locator time for each module in statistics (#134563)"
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-25 11:01:19 -07:00
GeorgeHuyubo
070a4ae2f9
Add symbol locator time for each module in statistics (#134563)
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 10:43:17 -07:00
Michael Buch
d555b9f9a0 [lldb][CPlusPlus] Add plugin.cplusplus.display.function-name-format setting (#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-25 10:04:27 +01:00
David Peixotto
2026873fb8
Add enable/disable api for SystemRuntime plugins (#133794)
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-04-02 13:15:31 -07:00
David Peixotto
f0b3bdd6df
[lldb] Remove raw access to PluginInstances vector (#132884)
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.
2025-03-31 09:53:46 -07:00
Miro Bucko
86f7f089ee
Fix return value of 'PluginManager::RegisterPlugin()'. (#114120) 2024-11-26 11:29:24 -05:00
Adrian Prantl
a0dd90eb7d
[lldb] Make conversions from llvm::Error explicit with Status::FromEr… (#107163)
…ror() [NFC]
2024-09-05 12:19:31 -07:00
Adrian Prantl
0642cd768b
[lldb] Turn lldb_private::Status into a value type. (#106163)
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-27 10:59:31 -07:00
Jacob Lalonde
572943e790
[LLDB] Reapply #100443 SBSaveCore Thread list (#104497)
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-15 16:29:59 -07:00
Jacob Lalonde
accf5c9bb3
Revert "[LLDB][SBSaveCore] Implement a selectable threadlist for Core… (#102018)
… Options.  (#100443)"

This reverts commit 3e4af616334eae532f308605b89ff158dd195180.

@adrian-prantl FYI

Reverts #100443
2024-08-05 10:17:25 -07:00
Haojian Wu
86f7374078 Revert "[LLDB][SBSaveCore] Fix bug where default values are not propagated. (#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-05 09:37:36 +02:00
Jacob Lalonde
34766d0d48
[LLDB][SBSaveCore] Fix bug where default values are not propagated. (#101770)
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 18:38:05 -07:00
Jacob Lalonde
3e4af61633
[LLDB][SBSaveCore] Implement a selectable threadlist for Core Options. (#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-08-02 13:35:05 -07:00
Med Ismail Bennani
bccff3baef [lldb/Commands] Add scripting template list command with auto discovery
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-27 13:36:30 -07:00
Med Ismail Bennani
e8504cb0c9
[lldb] Revert scripting template list patches (#100673)
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 17:11:36 -07:00
Med Ismail Bennani
2914a4b888 [lldb/Commands] Add scripting template list command with auto discovery
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 00:12:06 -07:00
Med Ismail Bennani
39c23a31d2
Revert "[lldb/Commands] Add scripting template list command with auto 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 16:04:48 -07:00
Med Ismail Bennani
43ca63149d
[lldb/Commands] Add scripting template list command with auto discovery (#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-23 10:19:52 -07:00
Jacob Lalonde
4120570dc4
[LLDB][SaveCore] Add SBSaveCoreOptions Object, and SBProcess::SaveCore() 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.
2024-07-18 17:10:15 -07:00
Kazu Hirata
744f38913f [lldb] Use StringRef::{starts,ends}_with (NFC)
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-16 14:39:37 -08:00
Kevin Frei
c43c86c285
DEBUGINFOD based DWP acquisition for LLDB (#70996)
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-12-04 11:45:40 -08:00
Jonas Devlieghere
e7c61479ce
[lldb] Move DownloadObjectAndSymbolFile to SymbolLocator plugin (#71267)
This builds on top of the work started in c3a302d to convert
LocateSymbolFile to a SymbolLocator plugin. This commit moves
DownloadObjectAndSymbolFile.
2023-11-04 17:58:35 -07:00
Jonas Devlieghere
19df9aa3f4
[lldb] Move LocateExecutableSymbolFile to SymbolLocator plugin (#71266)
This builds on top of the work started in c3a302d to convert
LocateSymbolFile to a SymbolLocator plugin. This commit moves
LocateExecutableSymbolFile.
2023-11-03 19:48:36 -07:00
Jonas Devlieghere
9b2246d9fa
[lldb] Move FindSymbolFileInBundle to SymbolLocator plugin (#71247)
This builds on top of the work started in c3a302d to convert
LocateSymbolFile to a SymbolLocator plugin. This commit moves
FindSymbolFileInBundle.
2023-11-03 18:07:57 -07:00
Jonas Devlieghere
c3a302d399
[lldb] Convert LocateSymbolFile into a plugin (#71151)
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-11-03 15:42:23 -07:00
Alex Langford
7ec083107f [lldb][NFCI] Remove use of ConstString from PluginManager
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-27 10:43:35 -07:00
Alex Langford
2014572d9a [lldb][NFCI] Remove unneeded ConstString constructions for 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-06-26 11:06:29 -07:00
Alex Langford
96a800c07f [lldb] Change setting descriptions to use StringRef instead of ConstString
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-19 14:45:02 -07:00
David Spickett
e07a421dd5 [lldb] Show register fields using bitfield struct types
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
2023-04-13 13:04:34 +00:00
Walter Erquinigo
c49d14aca5 [trace][intel pt] Simple detection of infinite decoding loops
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-10-25 10:20:49 -07:00
Jonas Devlieghere
48506fbbbf
[lldb] Teach LLDB about Mach-O filesets
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-08-25 15:24:51 -07:00
Walter Erquinigo
b8dcd0ba26 [NFC][lldb][trace] Rename trace session to trace bundle
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-24 08:41:33 -07:00
Alvin Wong
25c8a061c5 [lldb] Set COFF module ABI from default triple and make it an option
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
2022-06-09 22:43:33 +03:00
Jonas Devlieghere
100863ccd8 [lldb] Check if language is supported before creating a REPL instance
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-12-14 12:05:35 -08:00
Pavel Labath
30f922741a [lldb] Remove ConstString from plugin names in PluginManager innards
This completes de-constification of plugin names.
2021-11-03 13:14:21 +01:00
Pavel Labath
adf5e9c9b6 [lldb] Remove ConstString from TypeSystem and REPL plugin names 2021-11-02 16:13:52 +01:00
Pavel Labath
a394231819 [lldb] Remove ConstString from SymbolVendor, Trace, TraceExporter, UnwindAssembly, MemoryHistory and InstrumentationRuntime plugin names 2021-10-29 12:08:57 +02:00
Pavel Labath
5f4980f004 [lldb] Remove ConstString from Process, ScriptInterpreter and StructuredData plugin names 2021-10-28 10:15:03 +02:00
Pavel Labath
49481b5380 Remove ConstString from Language, LanguageRuntime, SystemRuntime and SymbolFile plugin names 2021-10-27 08:25:44 +02:00
Pavel Labath
a458ef4f73 [lldb] Remove ConstString from Platform plugin names 2021-10-26 10:04:35 +02:00
Pavel Labath
6fa1b4ff4b Remove ConstString from DynamicLoader, JITLoader and Instruction plugin names 2021-10-25 10:32:35 +02:00
Pavel Labath
b5e9f83ea4 [lldb] Remove ConstString from ABI, Architecture and Disassembler plugin names 2021-10-22 10:29:19 +02:00
Pavel Labath
6c88086ba8 [lldb] Fix a thinko in 2ace1e57
An empty plugin name means we should try everything.

Picked up by the windows bot.
2021-10-21 14:05:49 +02:00
Pavel Labath
2ace1e5753 [lldb] Remove ConstString from GetPluginNameStatic of some plugins
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
2021-10-21 12:58:45 +02:00
Pavel Labath
93c1b3caf0 [lldb] Remove some anonymous namespaces
.. and reduce the scope of others. They don't follow llvm coding
standards (which say they should be used only when the same effect
cannot be achieved with the static keyword), and they set a bad example.
2021-10-05 08:35:18 +02:00
Benjamin Kramer
4a0ba4180b [lldb] Fix pessimizing move warning
lldb/source/Core/PluginManager.cpp:695:21: warning: moving a temporary object prevents copy elision [-Wpessimizing-move]
      return Status(std::move(ret.takeError()));
                    ^
lldb/source/Core/PluginManager.cpp:695:21: note: remove std::move call here
      return Status(std::move(ret.takeError()));
                    ^~~~~~~~~~               ~
2021-09-06 21:17:29 +02:00
Michał Górny
25fbbc5936 [lldb] Support SaveCore() from gdb-remote client
Extend PluginManager::SaveCore() to support saving core dumps
via Process plugins.  Implement the client-side part of qSaveCore
request in the gdb-remote plugin, that creates the core dump
on the remote host and then uses vFile packets to transfer it.

Differential Revision: https://reviews.llvm.org/D101329
2021-09-06 18:33:02 +02:00
Andrej Korman
eee687a66d [lldb] Add minidump save-core functionality to ELF object files
This change adds save-core functionality into the ObjectFileELF that enables
saving minidump of a stopped process. This change is mainly targeting Linux
running on x86_64 machines. Minidump should contain basic information needed
to examine state of threads, local variables and stack traces. Full support
for other platforms is not so far implemented. API tests are using LLDB's
MinidumpParser.

This relands commit aafa05e, reverted in 1f986f6.
Failed tests were fixed.

Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D108233
2021-09-01 15:14:29 +02:00
Andy Yankovsky
1f986f6057 Revert "[lldb] Add minidump save-core functionality to ELF object files"
This reverts commit aafa05e03d629cc6605718c54575256d9d683659.

Broke builder on aarch64 --
https://lab.llvm.org/buildbot/#/builders/96/builds/10926
2021-08-31 13:36:53 +02:00