29577 Commits

Author SHA1 Message Date
Jonas Devlieghere
2f343fc157
[lldb] Print a message when background tasks take a while to complete (#82799)
When terminating the debugger, we wait for all background tasks to
complete. Given that there's no way to interrupt those treads, this can
take a while. When that happens, the debugger appears to hang at exit.

The above situation is unfortunately not uncommon when background
downloading of dSYMs is enabled (`symbols.auto-download background`).
Even when calling dsymForUUID with a reasonable timeout, it can take a
while to complete.

This patch improves the user experience by printing a message from the
driver when it takes more than one (1) second to terminate the debugger.
2024-03-05 12:04:32 -08:00
Jonas Devlieghere
1b812f9cd6
[lldb] Log to system log instead of stderr from Host::SystemLog (#83366)
Currently, calls to Host::SystemLog print to stderr on all host
platforms except Darwin. This severely limits its value on the command
line, where we don't want to overload the user with log messages. Switch
to using the syslog function on POSIX systems to send messages to the
system logger instead of stdout.

On Darwin systems this sends the log message to os_log, which matches
what we do today. Nevertheless I kept the current implementation that
uses os_log directly as it gives us more freedom.

I'm not sure if there's an equivalent on Windows, so I kept the existing
behavior of logging to stderr.
2024-03-05 10:56:01 -08:00
Felipe de Azevedo Piovezan
488ac3d5ef
[lldb] Enable a test that was never enabled (#83925)
According to the git log (d9442afba1bd6), this test has never been
enabled/disabled, it was checked in without being called anywhere. But
it passes and it is useful, so this commit enables it.
2024-03-04 15:45:43 -08:00
Med Ismail Bennani
5000e4c252
[lldb/crashlog] Fix breaking changes in textual report format (#83861)
This patch should address some register parsing issue in the legacy
report format.

rdar://107210149

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2024-03-04 15:44:44 -08:00
Alexander M
79e8f29ab0
[lldb/lua] Fix Lua building on Windows (#83871)
Add `liblldb` dependency and use correct extension for compiled Lua
module.

Replace 'Python' with 'Lua' in install path name.

Fixes #55075.
2024-03-04 11:54:24 -08:00
Med Ismail Bennani
f32c6b28b8
[lldb/Test] Fix oversight in ProcessEventDataTest::SetUp (NFC) (#83895)
This patch addresses an oversight in `ProcessEventDataTest::SetUp`
unittest to ensure the Debugger is initialized properly.

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2024-03-04 11:42:04 -08:00
Jordan Rupprecht
503075e4d4 [lldb][test][NFC] Narrow scope of import pexpect
We do not run `pexpect` based tests on Windows, but there are still cases where those tests run `import pexpect` outside of the scope where the test is skipped. By moving the import statement to a different scope, those tests can run even when `pexpect` truly isn't installed.

Tangentially related: TestSTTYBeforeAndAfter.py is using a manual `@expectedFailureAll` for windows instead of the common `@skipIfWindows`. If `pexepect` is generally expected to not be available, we should not bother running the test at all.
2024-03-04 11:21:47 -08:00
Jonas Devlieghere
1da5db97cb
[lldb] Use sort-ordering for indexes when sorting by size (#83889)
Use sort-ordering for indexes when sorting by size. This addresses
Jason's post commit review feedback.
2024-03-04 10:44:17 -08:00
Michael Buch
252f3c98db
[lldb][test] Add test for chained PCH debugging (#83582)
Adds a test-case for debugging a program with a
pch chain, that is, the main executable depends
on a pch that itself included another pch.

Currently clang doesn't emit the sekeleton CUs
required for LLDB to track all types on the pch chain. Thus this test is
XFAILed for now.
2024-03-04 17:17:13 +00:00
Mehdi Amini
e52650cfc3 Fix LLDB build after renaming the base class for ThreadPool to ThreadPoolInterface
The header was updated but not the implementation.
2024-03-02 19:30:33 -08:00
Mehdi Amini
6594f428de
Split the llvm::ThreadPool into an abstract base class and an implementation (#82094)
This decouples the public API used to enqueue tasks and wait for
completion from the actual implementation, and opens up the possibility
for clients to set their own thread pool implementation for the pool.

https://discourse.llvm.org/t/construct-threadpool-from-vector-of-existing-threads/76883
2024-03-02 19:10:50 -08:00
Daniil Kovalev
b14220e075
[lldb][X86] Fix setting target features in ClangExpressionParser (#82364)
Currently, for x86 and x86_64 triples, "+sse" and "+sse2" are appended
to `Features` vector of `TargetOptions` unconditionally. This vector is
later reset in `TargetInfo::CreateTargetInfo` and filled using info from
`FeaturesAsWritten` vector, so previous modifications of the `Features`
vector have no effect. For x86_64 triple, we append "sse2"
unconditionally in `X86TargetInfo::initFeatureMap`, so despite the
`Features` vector reset, we still have the desired sse features enabled.
The corresponding code in `X86TargetInfo::initFeatureMap` is marked as
FIXME, so we should not probably rely on it and should set desired
features properly in `ClangExpressionParser`.

This patch changes the vector the features are appended to from
`Features` to `FeaturesAsWritten`. It's not reset later and is used to
compute resulting `Features` vector.
2024-03-02 13:09:47 +03:00
Fangrui Song
ebaf26dabe [lldb] Fix -Wformat after #83602 2024-03-01 12:09:32 -08:00
Jonas Devlieghere
af009451ec
[lldb] Fix thread backtrace --count (#83602)
The help output for `thread backtrace` specifies that you can pass -1 to
`--count` to display all the frames.

```
-c <count> ( --count <count> )
            How many frames to display (-1 for all)
```

However, that doesn't work:

```
(lldb) thread backtrace --count -1
error: invalid integer value for option 'c'
```

The problem is that we store the option value as an unsigned and the
code to parse the string correctly rejects it. There's two ways to fix
this:

1. Make `m_count` a signed value so that it accepts negative values and
appease the parser. The function that prints the frames takes an
unsigned so a negative value will just become a really large positive
value, which is what the current implementation relies on.
2. Keep `m_count` unsigned and instead use 0 the magic value to show all
frames. I don't really see a point in not showing any frames at all,
plus that's already broken (`error: error displaying backtrace for
thread: "0x0001"`).

This patch implements (2) and at the same time improve the error
reporting so that we print the invalid value when we cannot parse it.

rdar://123881767
2024-03-01 11:06:58 -08:00
Chelsea Cassanova
137ed17016
[lldb][progress] Hook up new broadcast bit and progress manager (#83069)
This commit adds the functionality to broadcast events using the
`Debugger::eBroadcastProgressCategory`
bit (https://github.com/llvm/llvm-project/pull/81169) by keeping track
of these reports with the `ProgressManager`
class (https://github.com/llvm/llvm-project/pull/81319). The new bit is
used in such a way that it will only broadcast the initial and final
progress reports for specific progress categories that are managed by
the progress manager.

This commit also adds a new test to the progress report unit test that
checks that only the initial/final reports are broadcasted when using
the new bit.
2024-03-01 10:56:45 -08:00
Jonas Devlieghere
8fa33013de
[lldb] Add support for sorting by size to target module dump symtab (#83527)
This patch adds support to sort the symbol table by size. The command
already supports sorting and it already reports sizes. Sorting by size
helps diagnosing size issues.

rdar://123788375
2024-03-01 08:34:36 -08:00
David Spickett
ec8df55570 [lldb][test][Windows] Don't check for pexpect with LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS
See https://github.com/llvm/llvm-project/issues/22648 for why we don't use it on
Windows. Any pexpect tests are skipped there.
2024-03-01 09:47:17 +00:00
Jason Molenda
4551f53523
[lldb] [debugserver] fix qLaunchSuccess error, add QErrorStringInPacketSupported (#82593)
Pavel added an extension to lldb's gdb remote serial protocol that
allows the debug stub to append an error message (ascii hex encoded)
after an error response packet Exx. This was added in 2017 in
https://reviews.llvm.org/D34945 . lldb sends the
QErrorStringInPacketSupported packet and then the remote stub may add
these error strings.

debugserver has two bugs in its use of extended error messages: the
vAttach family would send the extended error string without checking if
the mode had been enabled. And qLaunchSuccess would not properly format
its error response packet (missing the hex digits, did not asciihex
encode the string).

There is also a bug in the HandlePacket_D (detach) packet where the
error packets did not include hex digits, but this one does not append
an error string.

I'm adding a new RNBRemote::SendErrorPacket() and routing all error
packet returns though this one method. It takes an optional second
string which is the longer error message; it now handles appending it to
the Exx response or not, depending on the QErrorStringInPacketSupported
state. I updated all packets to send their errors via this method.
2024-02-29 20:22:12 -08:00
Chelsea Cassanova
8171f6d12e
[lldb][progress][NFC] Fix Doxygen information (#83502) 2024-02-29 19:22:23 -08:00
Alexander M
5b6e58c565
Revert "XFAIL TestLocalVariables.py on Windows" (#83454)
This reverts commit 3434472ed74141848634b5eb3cd625d651e22562.

Closes #43097.
2024-02-29 18:23:12 -08:00
Jason Molenda
e8ce864a36 Revert "[lldb] Add SBProcess methods for get/set/use address masks (#83095)"
This reverts commit 9a12b0a60084b2b92f728e1bddec884a47458459.

TestAddressMasks fails its first test on lldb-x86_64-debian,
lldb-arm-ubuntu, lldb-aarch64-ubuntu bots.  Reverting while
investigating.
2024-02-29 17:29:24 -08:00
Jason Molenda
9a12b0a600
[lldb] Add SBProcess methods for get/set/use address masks (#83095)
I'm reviving a patch from phabracator, https://reviews.llvm.org/D155905
which was approved but I wasn't thrilled with all the API I was adding
to SBProcess for all of the address mask types / memory regions. In this
update, I added enums to control type address mask type (code, data,
any) and address space specifiers (low, high, all) with defaulted
arguments for the most common case.

This patch is also fixing a bug in the "addressable bits to address
mask" calculation I added in AddressableBits::SetProcessMasks. If lldb
were told that 64 bits are valid for addressing, this method would
overflow the calculation and set an invalid mask. Added tests to check
this specific bug while I was adding these APIs.

rdar://123530562
2024-02-29 17:02:42 -08:00
Michael Buch
07ffb7e294
[lldb][ClangASTImporter] Import record layouts from origin if available (#83295)
Layout information for a record gets stored in the `ClangASTImporter`
associated with the `DWARFASTParserClang` that originally parsed the
record. LLDB sometimes moves clang types from one AST to another (in the
reproducer the origin AST was a precompiled-header and the destination
was the AST backing the executable). When clang then asks LLDB to
`layoutRecordType`, it will do so with the help of the
`ClangASTImporter` the type is associated with. If the type's origin is
actually in a different LLDB module (and thus a different
`DWARFASTParserClang` was used to set its layout info), we won't find
the layout info in our local `ClangASTImporter`.

In the reproducer this meant we would drop the alignment info of the
origin type and misread a variable's contents with `frame var` and
`expr`.

There is logic in `ClangASTSource::layoutRecordType` to import an
origin's layout info. This patch re-uses that infrastructure to import
an origin's layout from one `ClangASTImporter` instance to another.

rdar://123274144
2024-02-29 21:40:02 +00:00
Michael Buch
8c10032665
[lldb][NFC] Move helpers to import record layout into ClangASTImporter (#83291)
This patch moves the logic for copying the layout info of a
`RecordDecl`s origin into a target AST.

A follow-up patch re-uses the logic from within the `ClangASTImporter`,
so the natural choice was to move it there.
2024-02-29 21:32:28 +00:00
Shubham Sandeep Rastogi
82c1bfc44e
Increase timeout to reduce test failure rate. (#83312)
The timeout for this test was set to 1.0s which is very low, it should
be a default of 10s and be increased by a factor of 10 if ASAN is
enabled. This will help reduce the falkiness of the test, especially in
ASAN builds.
2024-02-29 13:12:03 -08:00
Jonas Devlieghere
a6d9b7ba27
[lldb] Don't cache lldb_find_python_module result
Don't cache lldb_find_python_module result as that requires you to do a
clean build after installing the dependency.
2024-02-29 09:12:20 -08:00
Jonas Devlieghere
5a0bd2a365
[lldb] Add pexpect to LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS
This executed Alex' idea [1] of adding pexpect to the list of "strict
test requirements" as we're planning to stop vendoring it. This will
ensure all the bots have the package before we toggle the default.

[1] https://github.com/llvm/llvm-project/pull/83191
2024-02-29 08:08:30 -08:00
David Spickett
99824cf796 [lldb][test] Use pexpect spawn instead of spawnu
This is marked deprecated from at least 4.6 onward:
Deprecated: pass encoding to spawn() instead.
2024-02-29 14:59:51 +00:00
David Spickett
ec95379df3 [lldb][test] Clear pexpect found var before checking again
If you run cmake without pexpect installed it errors as expected.
However, if you just `pip install pexpect` and cmake again it still
doesn't find it because it cached the result of the search.

Unset the result before looking for pexpect. So that this works
as expected:
cmake ...
pip3 install pexpect
cmake ...
2024-02-29 14:22:23 +00:00
Sudharsan Veeravalli
ee297a73b5
[LLDB] Fix test failure introduced by #83234 (#83406)
Missed adding a . in the test check
2024-02-29 11:02:22 +00:00
Sudharsan Veeravalli
de5518836e
[LLDB] Fix crash when using tab completion on class variables (#83234)
We weren't checking to see if the partial_path was empty before adding
completions and this led to crashes when the class object and a variable
both start with the same substring.

Fixes [#81536](https://github.com/llvm/llvm-project/issues/81536)

---------

Co-authored-by: Michael Buch <michaelbuch12@gmail.com>
2024-02-29 09:40:27 +00:00
Jonas Devlieghere
81d94cad6d
Revert "[lldb] Add pexpect to LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS"
This reverts commit 793300988b7c723bacadce67879ea8bf71c87e70 as pexpect
is not available on any of the GreenDragon bots.
2024-02-28 21:23:19 -08:00
Jonas Devlieghere
793300988b
[lldb] Add pexpect to LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS
This executed Alex' idea [1] of adding pexpect to the list of "strict
test requirements" as we're planning to stop vendoring it. This will
ensure all the bots have the package before we toggle the default.

[1] https://github.com/llvm/llvm-project/pull/83191
2024-02-28 21:20:40 -08:00
jimingham
5784bf85bc
Fix interactive use of "command script add". (#83350)
There was a think-o in a previous commit that made us only able to
define 1 line commands when using command script add interactively.

There was also no test for this feature, so I fixed the think-o and
added a test.
2024-02-28 17:26:29 -08:00
Alex Langford
f7a544dd5f
[lldb] Ignore swig warnings about shadowed overloads (#83317)
This specifically addresses the warnings:
$LLVM/lldb/include/lldb/API/SBCommandReturnObject.h:119: Warning 509:
Overloaded method lldb::SBCommandReturnObject::PutCString(char const *)
effectively ignored,
$LLVM/lldb/include/lldb/API/SBCommandReturnObject.h:119: Warning 509: as
it is shadowed by lldb::SBCommandReturnObject::PutCString(char const
*,int).

There is exactly one declaration of SBCommandReturnObject::PutCString.
The second parameter (of type `int`) has default value `-1`. Without
investigating why SWIG believes there are 2 method declarations, I
believe it is safe to ignore this warning. It does not appear to
actually impact functionality in any way.

rdar://117744660
2024-02-28 16:54:32 -08:00
jimingham
97281708ac
Change image list -r so that it actually shows the ref count and whether the image is in the shared cache. (#83341)
The help for the `-r` option to `image list` says:

       -r[<width>] ( --ref-count=[<width>] )
Display the reference count if the module is still in the shared module
cache.

but that's not what it actually does. It unconditionally shows the
use_count for all Module shared pointers, regardless of whether they are
still in the shared module cache or whether they are just in the
ModuleCollection and other entities are keeping them alive. That seems
like a more useful behavior, but then it is also useful to know what's
in the shared cache, so I changed this to:

       -r[<width>] ( --ref-count=[<width>] )
Display whether the module is still in the the shared module cache
(Y/N), and its shared pointer use_count.

So instead of just `{5}` you will see `{Y 5}` if it is in the shared
cache and `{N 5}` if not.

I didn't add tests for this because I'm not sure how much we want to fix
shared cache behavior in the testsuite.
2024-02-28 16:14:19 -08:00
Jonas Devlieghere
d3173f4ab6
[lldb] Remove -d(ebug) mode from the lldb driver (#83330)
The -d(ebug) option broke 5 years ago when I migrated the driver to
libOption. Since then, we were never check if the option is set. We were
incorrectly toggling the internal variable (m_debug_mode) based on
OPT_no_use_colors instead.

Given that the functionality doesn't seem particularly useful and nobody
noticed it has been broken for 5 years, I'm just removing the flag.
2024-02-28 15:23:55 -08:00
Jordan Rupprecht
249cf356ef
[lldb][test][NFC] Add option to exclude third_party packages (#83191)
The goal here is to remove the third_party/Python/module tree, which
LLDB tests only use to `import pexpect`. This package is available on
`pip`, and I believe should not be hard to obtain.

However, in case it isn't easily available, deleting the tree right now
could cause disruption. This introduces a
`LLDB_TEST_USE_VENDOR_PACKAGES` cmake param that can be enabled, and the
tests will continue loading that tree. By default, it is enabled,
meaning there's really no change here. A followup change will disable it
by default once all known build bots are updated to include this
package. When disabled, an eager cmake check runs that makes sure
`pexpect` is available before waiting for the test to fail in an obscure
way.

Later, this option will go away, and when it does, we can delete the
tree too. Ideally this is not disruptive, and we can remove it in a week
or two.
2024-02-28 15:00:41 -06:00
Zequan Wu
2cacc7a610
[lldb-dap] Deduplicate watchpoints starting at the same address on SetDataBreakpointsRequest. (#83192)
If a SetDataBreakpointsRequest contains a list data breakpoints which
have duplicate starting addresses, the current behaviour is returning
`{verified: true}` to both watchpoints with duplicated starting
addresses. This confuses the client and what actually happens in lldb is
the second one overwrite the first one.

This fixes it by letting the last watchpoint at given address have
`{verified: true}` and all previous watchpoints at the same address
should have `{verfied: false}` at response.
2024-02-28 14:56:55 -05:00
Walter Erquinigo
cd344a4c20
[LLDB] Fix completion of space-only lines in the REPL on Linux (#83203)
https://github.com/modularml/mojo/issues/1796 discovered that if you try
to complete a space-only line in the REPL on Linux, LLDB crashes. I
suspect that editline doesn't behave the same way on linux and on
darwin, because I can't replicate this on darwin.

Adding a boundary check in the completion code prevents the crash from
happening.
2024-02-28 11:43:36 -05:00
Jordan Rupprecht
e427e934f6
[lldb][dap] Avoid concurrent HandleCommand calls (#83162)
The `EventThreadFunction` can end up calling `HandleCommand`
concurrently with the main request processing thread. The underlying API
does not appear to be thread safe, so add a narrowly scoped mutex lock
to prevent calling it in this place from more than one thread.

Fixes #81686. Prior to this, TestDAP_launch.py is 4% flaky. After, it
passes in 1000 runs.
2024-02-27 12:43:05 -06:00
jimingham
2d704f4bf2
Start to clean up the process of defining command arguments. (#83097)
Partly, there's just a lot of unnecessary boiler plate. It's also
possible to define combinations of arguments that make no sense (e.g.
eArgRepeatPlus followed by eArgRepeatPlain...) but these are never
checked since we just push_back directly into the argument definitions.

This commit is step 1 of this cleanup - do the obvious stuff. In it, all
the simple homogenous argument lists and the breakpoint/watchpoint
ID/Range types, are set with common functions. This is an NFC change, it
just centralizes boiler plate. There's no checking yet because you can't
get a single argument wrong.

The end goal is that all argument definition goes through functions and
m_arguments is hidden so that you can't define inconsistent argument
sets.
2024-02-27 10:34:01 -08:00
Alex Langford
0ef66fcc85
[lldb] Use CreateOptionParsingError in CommandObjectBreakpoint (#83086)
This updates the remaining SetOptionValue methods in
CommandObjectBreakpoint to use CreateOptionParsingError.

I found a few minor bugs that were fixed during this refactor (e.g.
using the wrong flag in an error message). That is one of the benefits
of centralizing error message creation.

I also found some option parsing code that is written incorrectly. I do
not make an attempt to update those here because this PR is primarily
about changing existing error handling code, not adding new error
handling code.
2024-02-27 10:25:56 -08:00
Adrian Prantl
8a87f763a6
Aim debugserver workaround more precisely. (#83099) 2024-02-27 08:14:46 -08:00
David Spickett
a1bbba06ea [lldb][test][Windows] Fix NonStop tests on case insensitive file systems
On a case insensitive file sytem, the build dir for `test_multiple_c` and
`test_multiple_C` are the same and therefore the log files are in the same
place. This means one tries to clear the log file for the other.

To fix this, make the names unique by adding the meaning of each
protocol packet.

https://sourceware.org/gdb/current/onlinedocs/gdb.html/Packets.html#Packets
2024-02-27 09:34:42 +00:00
nikitalita
dc5dfc102f
[lldb] python-bindings: fix SBTarget.get_target_watchpoints() (#82295)
Fixes erroneous usage of `bkpts` instead of `watchpoints` (probably
introduced from copying and pasting `get_target_bkpts()`).
2024-02-26 15:05:02 -08:00
Jonas Devlieghere
38515580c4
[lldb] Remove LLDB_DEBUGSERVER_CODESIGN_IDENTITY (NFC)
This property was previously used by the test suite.
2024-02-26 11:11:30 -08:00
Adrian Prantl
01450dd1c6 Change debugserver to report the cpu(sub)type of process, not the host.
This way debugserver can correctly report qProcessInfo for arm64
processes on arm64e-capable hosts.

Patch implemented with help from Jason Molenda!
2024-02-26 09:57:07 -08:00
Adrian Prantl
f9f331652d Replace ArchSpec::PiecewiseCompare() with Triple::operator==()
Looking ast the definition of both functions this is *almost* an NFC
change, except that Triple also looks at the SubArch (important) and
ObjectFormat (less so).

This fixes a bug that only manifests with how Xcode uses the SBAPI to
attach to a process by name: it guesses the architecture based on the
system. If the system is arm64 and the Process is arm64e Target fails
to update the triple because it deemed the two to be equivalent.

rdar://123338218
2024-02-26 09:57:07 -08:00
Jordan Rupprecht
252f1cdebf
[lldb][test] Remove vendored packages unittest2 and progress (#82670)
The `unittest2` package is unused since
5b386158aacac4b41126983a5379d36ed413d0ea.

The `progress` package was only used internally by `unittest2`, so it
can be deleted as well.
2024-02-26 09:45:09 -06:00