Commit Graph

31803 Commits

Author SHA1 Message Date
Felipe de Azevedo Piovezan
2cae14fdc6 Revert "[lldb] Change synthetic symbol names to have file address (#137512)"
This reverts commit b69957fa64.
2025-05-01 18:27:34 -07:00
jimingham
471fe9c689 Fix TestEvents.py after: 4fdb8cb (#138211)
I changed the option name from at-first-stop (-F) to at-initial-stop
(-I) but missed one place in the testsuite.
2025-05-01 16:01:50 -07:00
Ely Ronnen
b69957fa64 [lldb] Change synthetic symbol names to have file address (#137512)
Changes the default synthetic symbol names to contain their file address
2025-05-01 15:32:34 -07:00
jimingham
4fdb8cb42f Make stop-hooks fire when lldb first gains control of a process. (#137410)
stop-hooks are supposed to trigger every time the process stops, but as
initially implemented they would only fire when control was returned to
the user. So for instance when a process was launched the stop hook
would only trigger when the process hit a breakpoint or crashed.

However, it would be really useful to be able to trigger a stop hook
when lldb first gains control over the process. One way to do that would
be to implement general "target lifecycle events" and then send process
created events that users could bind actions to.

OTOH, extending the stop hooks to fire when lldb first gains control
over the process is a pretty natural extension to the notion of a stop
hook. So this patch takes the shorter route to that ability by making
stop-hooks fire when lldb first gains control over the process.

I also added the ability to specify whether to trigger the stop hook "on
gaining control". I'm on the fence about whether to set the default to
be "trigger on gaining control" or "don't trigger on gaining control".
Since I think it's a generally useful feature, I've set the default to
"trigger on gaining control".
2025-05-01 13:46:19 -07:00
Kazu Hirata
2bff80f25d [lldb] Fix a warning
This patch fixes:

  lldb/source/Target/Memory.cpp:438:3: error: 'lock_guard' may not
  intend to support class template argument deduction
  [-Werror,-Wctad-maybe-unsupported]
2025-05-01 12:27:08 -07:00
Mikhail Zakharov
6aa963f780 [lldb] Do not bump memory modificator ID when "internal" debugger memory is updated (#129092)
This change adds a setting `target.process.track-memory-cache-changes`.
Disabling this setting prevents invalidating and updating values in
`ValueObject::UpdateValueIfNeeded` when only "internal" debugger memory
is updated. Writing to "internal" debugger memory happens when, for
instance, expressions are evaluated by visualizers (pretty printers).
One of the examples when cache invalidation has a particularly heavy
impact is visualizations of some collections: in some collections
getting collection size is an expensive operation (it requires traversal
of the collection).
At the same time evaluating user expression with side effects (visible
to target, not only to debugger) will still bump memory ID because:

- If expression is evaluated via interpreter: it will cause write to
"non-internal" memory
- If expression is JIT-compiled: then to call the function LLDB will
write to "non-internal" stack memory

The downside of disabled `target.process.track-memory-cache-changes`
setting is that convenience variables won't reevaluate synthetic
children automatically.

---------

Co-authored-by: Mikhail Zakharov <mikhail.zakharov@jetbrains.com>
2025-05-01 11:10:41 -07:00
David Spickett
09488bcfba [lldb] Disable statusline on Windows (#138111)
Something to do with control code handling in Windows terminals breaks
the statusline in various ways. It makes LLDB unusable and even if you
set the setting to disable statusline, it's too late, and the terminal
session is now in a weird state.

See https://github.com/llvm/llvm-project/issues/134846 for more details.

Until we figure this out, don't allow it to be used on Windows.
2025-05-01 16:40:47 +01:00
Jan Svoboda
b69dcb8734 [clang][frontend] Require invocation to construct CompilerInstance (#137668)
This PR makes it so that `CompilerInvocation` needs to be provided to
`CompilerInstance` on construction. There are a couple of benefits in my
view:
* Making it impossible to mis-use some `CompilerInstance` APIs. For
example there are cases, where `createDiagnostics()` was called before
`setInvocation()`, causing the `DiagnosticEngine` to use the
default-constructed `DiagnosticOptions` instead of the intended ones.
* This shrinks `CompilerInstance`'s state space.
* This makes it possible to access **the** invocation in
`CompilerInstance`'s constructor (to be used in a follow-up).
2025-05-01 07:31:30 -07:00
David Spickett
2dbab4ca8d [lldb][test] Disable a bunch of flakey lldb-dap tests
These, or parts of these, are all failing every so often on Linaro's
build bots with:
    raise ValueError(desc)
ValueError: no response for "disconnect"

Sorry to use a global disable here but this is happening too often
and spamming unrelated PRs.

I think it's the same issue as https://github.com/llvm/llvm-project/issues/137660.
2025-05-01 10:01:14 +00:00
David Spickett
47424df2d5 [lldb][test] Skip part of TestLldbGdbServer.py on Windows
See https://github.com/llvm/llvm-project/issues/138085.
2025-05-01 09:30:33 +00:00
Jonas Devlieghere
1495d132db [lldb-dap] Add an RAII helper for synchronous mode (NFC) (#137900)
While debugging the flakiness of the launch and attach tests, I noticed
that we have some places in lldb-dap where we put the debugger in
synchronous mode and have an early exit, that would leave the debugger
in this state. This PR introduces an RAII helper to avoid such mistakes.
2025-04-30 15:18:32 -07:00
Ivan Tadeu Ferreira Antunes Filho
b85f37a132 [lldb][test] Free buffer to fix memory leak on test (#137979) 2025-04-30 16:02:33 -04:00
Chelsea Cassanova
ff8fc5bc45 [lldb][cmake] Add clang resource dir to LLDB shell tests config (#136761)
We want to be able to access the Clang resources directory in LLDB shell
tests, this commit adds the ability to do this by populating the
`CLANG_RESOURCE_DIR` variable in LLDBConfig.cmake.
2025-04-30 10:10:05 -07:00
Charles Zablit
b3d130279f [lldb] Upgrade GetIndexOfChildWithName to use llvm::Expected (#136693)
This patch replaces the use of `UINT32_MAX` as the error return value of
`GetIndexOfChildWithName` with `llvm::Expected`.


# Tasks to do in another PR

1. Replace `CalculateNumChildrenIgnoringErrors` with
`CalculateNumChildren`. See [this
comment](https://github.com/llvm/llvm-project/pull/136693#discussion_r2056319358).
2. Update `lldb_private::formatters::ExtractIndexFromString` to use
`llvm::Expected`. See [this
comment](https://github.com/llvm/llvm-project/pull/136693#discussion_r2054217536).
3. Create a new class which carries both user and internal errors. See
[this
comment](https://github.com/llvm/llvm-project/pull/136693#discussion_r2056439608).
2025-04-30 11:44:19 +01:00
Ebuka Ezike
6951d5d6cf [NFC][lldb][test] Fix typo in test setup commands. (#137944) 2025-04-30 10:42:43 +01:00
Jonas Devlieghere
f73db3df80 [lldb-dap[test] Don't pass --listen to debugserver
Fixes "debugserver: unrecognized option `--listen'"
2025-04-29 14:59:36 -07:00
Felipe de Azevedo Piovezan
f784fa7275 [lldb] Disable TestExitDuringExpression on asan
This test is trying to exercise code running constructors with
interrupts. While we should fix this, this is creating noise on the
bots.
2025-04-29 12:38:51 -07:00
Ilia Kuklin
d637038429 [LLDB] Add unary operators Dereference and AddressOf to DIL (#134428) 2025-04-29 21:29:52 +05:00
Jonas Devlieghere
3081ec1249 [lldb] Provide an unconditional @skip annotation for API tests (#137712)
The correct way of doing this today is to use `@skipIf` with no
arguments, which reads like it expects a condition.

Fixes #137710
2025-04-29 08:28:43 -07:00
Pavel Labath
cf7301aeb8 [lldb] Disable the process architecture test on macOS as well
Fails on the x86_64 bot.
2025-04-29 16:59:23 +02:00
Felipe de Azevedo Piovezan
55b4e5e515 [lldb] Disable TestDAP_attach
This is also flaky. See https://github.com/llvm/llvm-project/issues/137660
2025-04-29 07:18:22 -07:00
David Spickett
65b0d21eb4 [lldb] Remove "error:" prefix from reverse execute error messages
Errors will get "error:" prefixes automatically so this is not needed.
2025-04-29 14:01:01 +00:00
Michael Buch
4560ff8740 [lldb][test] Skip TestFrameFormatFunctionSuffix.test on Windows
We skip/xfail the other FrameFormat tests on Windows already. The number
of different buildbot configurations out there targetting Windows makes
it hard to make this test portable. If we want to test this on Windows
we should probably just make a dedicated test for it.
2025-04-29 14:25:31 +01:00
Michael Buch
ebeae6402d Reland "[lldb][Format] Make function name frame-format variables work without debug-info" (#137757)
This reverts commit da7099290c.

Same as the original PR. The failing test-case was resolved in https://github.com/llvm/llvm-project/pull/137763
2025-04-29 11:49:21 +01:00
Michael Buch
252b095b32 [lldb][test] Add more test-cases to MangledTest 2025-04-29 10:07:04 +01:00
Michael Buch
64b5bc876a [lldb][Format] Add function.suffix frame-format variable (#137763)
This patch adds another frame-format variable (currently only
implemented in the CPlusPlus language plugin) that represents the
"suffix" of a function. The name is derived from the `DotSuffix` node of
LLVM's Itanium demangler.

For a function name such as `int foo() (.cold)`, the suffix would be
`(.cold)`.
2025-04-29 10:02:44 +01:00
Pavel Labath
a9ece2dc68 [lldb] Skip some Host::GetProcessInfo tests for macos
Some of the tests moved in #134354 do not currently pass on a mac. Disable
them.

The test for testing process priority also does not build on a mac.  I'm not
moving it (back) to the linux, since it's "almost" fine -- we'd just need to
implement the RLIMIT_NICE logic differently. I'm not doing that now since
(apart from linux) there are no systems which are able to retrieve the process
priority.
2025-04-29 09:28:43 +02:00
Pavel Labath
15cd71afd2 [lldb] Make ValueObject::Dereference less aggressive (#137311)
The function was always trying to dereference both the synthetic and
non-synthetic view of the object. This is wrong as the caller should be
able to determine which view of the object it wants to access, as is
done e.g. for child member access.

This patch removes the nonsynthetic->synthetic fallback, which is the
more surprising path, and fixes the callers to try both versions of the
object (when appropriate). I also snuck in simplification of the member
access code path because it was possible to use the same helper function
for that, and I wanted to be sure I understand the logic correctly.

I've left the synthetic->nonsynthetic fallback in place. I think we may
want to keep that one as we often have synthetic child providers for
pointer types. They usually don't provide an explicit dereference
operation but I think users would expect that a dereference operation on
those objects would work. What we may want to do is to try the
*synthetic* operation first in this case, so that the nonsynthetic case
is really a fallback.

---------

Co-authored-by: Ilia Kuklin <kuklin.iy@mail.ru>
2025-04-29 08:27:18 +02:00
Pavel Labath
679cc0a1ed [lldb] Remove Function null checks in Block.cpp (#137611)
As of #117683, Blocks are always enclosed in a function, so these checks
never fail. We can't change the signature of
`CalculateSymbolContextFunction` as it's an abstract function (and some
of its implementations can return nullptr), but we can create a
different function that we can call when we know we're dealing with a
block.
2025-04-29 08:20:08 +02:00
Pavel Labath
ebaeecc429 [lldb] Use early returns in TypeSystemClang::IsPossibleDynamicType (#137630)
Remove a couple of levels of indentation before I need to add another
one to fix a bug.
2025-04-29 08:17:53 +02:00
Michael Buch
da7099290c Revert "[lldb][Format] Make function name frame-format variables work without debug-info" (#137757)
Reverts llvm/llvm-project#137408

This change broke `lldb/test/Shell/Unwind/split-machine-functions.test`.

The test binary has a symbol named `_Z3foov.cold` and the test expects
the backtrace to print the name of the cold part of the function like
this:

```
# SPLIT: frame #1: {{.*}}`foo() (.cold) +
```
but now it gets

```
frame #1: 0x000055555555514f split-machine-functions.test.tmp`foo() + 12
```
2025-04-29 07:13:04 +01:00
Hemang Gadhavi
d1bb8d6a5c [lldb][AIX] get host info for AIX (#134354)
This PR is in reference to porting LLDB on AIX.

Link to discussions on llvm discourse and github:

1. https://discourse.llvm.org/t/port-lldb-to-ibm-aix/80640
2. https://github.com/llvm/llvm-project/issues/101657
The complete changes for porting are present in this draft PR:
https://github.com/llvm/llvm-project/pull/102601

- Added changes to make the common host support functions under
`Host/posix` for unix-like system.
Also, created the `unittests/Host/posix/` to test the hostInfo & support
functions for unix-like system.
- Added changes to get the host information for AIX. (GetProcessInfo()) 
(Information like : executable path, arch, process status etc.)
2025-04-29 11:23:03 +05:30
Jonas Devlieghere
a37e475efc [lldb] Rely on operator== for std::vector (NFC)
Rely on operator== for std::vector instead of comparing the elements in
the vector element by element,
2025-04-28 20:10:56 -07:00
Jonas Devlieghere
82ab35961f [lldb-dap] Fix machine-overridable scope (#137723)
My previous commit was a bit sloppy, I didn't spot that
`lldb-dap.executable-path` already had a scope and I didn't consider
that `lldb-dap.log-path` should have the same scope.

This PR addresses both:

 - Fix duplicate scope for `lldb-dap.executable-path`.
 - Change scope of `lldb-dap.log-path` to `machine-overridable` too.
2025-04-28 17:01:03 -07:00
Wanyi
47de54e9a2 [lldb-dap] Fix TestDap_attach.py flakiness (#137278)
# Summary
This patch makes the `request_attach` wait for events `process` and
`initialized` just like `request_launch`. This ensure the DAP session
can move forward somewhat correctly.

Recently `TestDap_attach.test_terminate_commands` became flaky.
It's hitting:
```
lldbsuite/test/tools/lldb-dap/dap_server.py", line 350, in send_recv
    raise ValueError(desc)
ValueError: no response for "disconnect"
```
I took a look at the DAP msg from that test case and noticed:
- It's not using the regular attaching, instead it's using the
`attachCommands` to launch debug the binary and it will stop at entry.
- The `initialized` event returned after the `disconnect` request. Which
means lldb-dap didn't really get ready yet.

### NOTE
The `dap_server.py` is doing things to mimic the VSCode (or other dap
clients) but it had some assumptions. For example, it's still missing
the `configurationDone` request and response because it relies on a
continue action to trigger the `configurationDone` request.

# Test Plan
```
./bin/llvm-lit -va /Users/wanyi/llvm-upstream/llvm-project/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py
./bin/llvm-lit -va /Users/wanyi/llvm-upstream/llvm-project/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py
```

To test the `wait_for_events` timeout case
```
events = self.wait_for_events(["process", "initialized", "fake", "event"], 1)
if events:
    raise ValueError(f'no events {",".join(events)} found for within timeout 1')
```
Observed
<img width="696" alt="image"
src="https://github.com/user-attachments/assets/bc97c0ef-d91f-4561-8272-4d36f5f5d4e6"
/>

### Also
Looks like some test cases should be re-enabled in
0b8dfb5762
But only comments was removed. The skip statements survived the change.
2025-04-28 18:32:51 -04:00
Jonas Devlieghere
7d4e6ff216 [lldb-dap] Bump the version to 0.2.13 2025-04-28 14:11:01 -07:00
Felipe de Azevedo Piovezan
b73169ad3e [lldb] Disable TestDAP_attachByPortNum
This test is flaky and creating a lot of noise in CI.
See https://github.com/llvm/llvm-project/issues/137660
2025-04-28 14:08:14 -07:00
John Harrison
4fa0f1d166 [lldb-dap] Adding an icon to the lldb-dap package. (#137695)
This shows up in the extension UI and in the VSCode extension
marketplace.

I used the llvm/llvm-www/blob/main/img/LLVMWyvernSmall.png for the
image.

Here is what this looks like locally: 
<img width="1020" alt="Screenshot 2025-04-28 at 12 30 33 PM"
src="https://github.com/user-attachments/assets/cd615161-06db-4a37-8f8a-df65ca620a67"
/>
2025-04-28 14:02:36 -07:00
Jonas Devlieghere
9d77a3fa1a [debugserver] Remove PThreadMutex (NFC) (#137555)
Now that all uses of PThreadMutex have been migrated to their C++
equivalent, this PR removes PThreadMutex itself.
2025-04-28 11:28:45 -07:00
Jonas Devlieghere
64737ceb9a [lldb-dap] Bump the version to 0.2.12 2025-04-28 10:33:22 -07:00
Jonas Devlieghere
46fd2b94af [debugserver] Migrate PThreadEvent away from PThreadMutex (NFC) (#137554)
The debugserver code predates modern C++, but with C++11 and later
there's no need to have something like PThreadMutex. This migrates
PThreadEvent away from PThreadMutex in preparation for removing it.
2025-04-28 10:31:59 -07:00
Med Ismail Bennani
4e4c6d7e27 [lldb/Format] Make progress count show thousands separators (NFC) (#137446)
This patch changes the progress count formatting show thousands
separator making it easier to read big numbers.

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2025-04-28 10:26:40 -07:00
Jonas Devlieghere
9f2bcc7a66 [debugserver] Migrate DNBTimer away from PThreadMutex (NFC) (#137540)
The debugserver code predates modern C++, but with C++11 and later
there's no need to have something like PThreadMutex. This migrates
DNBTimer away from that class in preparation for removing PThreadMutex.
2025-04-28 09:44:14 -07:00
Jonas Devlieghere
41ab76bf0a Revert "[debugserver] Migrate DNBTimer away from PThreadMutex (NFC) (#137540)"
This reverts commit ae71055e66.
2025-04-28 08:44:30 -07:00
Jan Svoboda
985410f87f [clang] Hide the TargetOptions pointer from CompilerInvocation (#106271)
This PR hides the reference-counted pointer that holds `TargetOptions`
from the public API of `CompilerInvocation`. This gives
`CompilerInvocation` an exclusive control over the lifetime of this
member, which will eventually be leveraged to implement a copy-on-write
behavior.

There are two clients that currently share ownership of that pointer:

* `TargetInfo` - This was refactored to hold a non-owning reference to
`TargetOptions`. The options object is typically owned by the
`CompilerInvocation` or by the new `CompilerInstance::AuxTargetOpts` for
the auxiliary target. This needed a bit of care in `ASTUnit::Parse()` to
keep the `CompilerInvocation` alive.
* `clangd::PreambleData` - This was refactored to exclusively own the
`TargetOptions` that get moved out of the `CompilerInvocation`.
2025-04-28 07:43:26 -07:00
Michael Buch
cebf86eb1d [lldb][Format] Make function name frame-format variables work without debug-info (#137408)
This patch makes the frame-format variables introduced in
https://github.com/llvm/llvm-project/pull/131836 also work when no
debug-info is available. Previously, we assumed `sc.function` was
available, but without debug-info we might only have `sc.symbol`. We
don't really need the `sc.function` apart from when formatting
arguments.

For the function arguments case I added a fallback that will just print
the arguments we get from the demangler (which is what LLDB does for
stacktraces with no debug-info anyway). Ideally we'd have a separate
`FormatEntity::Entry::Type::FunctionArguments` that will just print the
arguments from the demangler and have something like the following in
the `plugin.cplusplus.display.function-name-format`:
```
{ ${function.formatted-arguments} || ${function.arguments} }
```
I.e., when we can't format the arguments, print the ones from the
demangler. But we currently don't have the `||` operator in the
frame-format language yet.
2025-04-28 10:46:00 +01:00
David Spickett
5afe9c72e4 [lldb][lldb-dap] Disable launch tests that rely on get_stdout()
This appears not to work on Windows.

See https://github.com/llvm/llvm-project/issues/137599.
2025-04-28 09:10:12 +00:00
Michael Buch
ec6b619430 [lldb][DNB] Add missing include
On the buildbots:
```
user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/tools/debugserver/source/DNBLog.cpp
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/tools/debugserver/source/DNBLog.cpp:66:15: error: no type named 'recursive_mutex' in namespace 'std'
  static std::recursive_mutex g_LogThreadedMutex;
         ~~~~~^
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/tools/debugserver/source/DNBLog.cpp:67:8: error: no member named 'lock_guard' in namespace 'std'
  std::lock_guard<std::recursive_mutex> guard(g_LogThreadedMutex);
  ~~~~~^
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/tools/debugserver/source/DNBLog.cpp:67:24: error: no member named 'recursive_mutex' in namespace 'std'
  std::lock_guard<std::recursive_mutex> guard(g_LogThreadedMutex);
                  ~~~~~^
```
2025-04-28 09:39:45 +01:00
Michael Buch
e665d95426 [lldb] Highlight basenames in backtraces (#137301)
Also changes the PC value color so it doesn't visually clash with the
function names

Before:
<img width="1510" alt="Screenshot 2025-04-25 at 10 38 58 AM"
src="https://github.com/user-attachments/assets/1ec35ba3-a3d9-4e5b-bac9-fc738bfe6d25"
/>

After:
![Screenshot 2025-04-25 at 4 34
27 PM](https://github.com/user-attachments/assets/3de6e778-ff97-4f47-b361-360e4bbfaede)
2025-04-28 08:29:31 +01:00
Michael Buch
fcb1a481ce [lldb][docs] Document new frame-format variables (#137522)
Documents https://github.com/llvm/llvm-project/pull/131836
2025-04-28 08:28:54 +01:00