Commit Graph

27106 Commits

Author SHA1 Message Date
Jordan Rupprecht 2c38201b09 [test] Fix typo in setting the wrong Context test field
This manifests as an msan error because we check the value of `es`, but it's actually uninitialized because we mistakenly set `ss` twice.
2022-09-06 18:59:03 -07:00
Jim Ingham 9690308f78 Fix another place were we suggest lldb.target in a Frame Recognizer. 2022-09-06 13:24:21 -07:00
Jim Ingham edea4a349d You can't use lldb.target in a frame recognizer. 2022-09-06 13:20:48 -07:00
Dave Lee 940704cc58 [lldb] Fix CommunicationKDP following D133251
Add `m_bytes` and `m_bytes_mutex` to `CommunicationKDP`, following refactoring
in D133251.

Differential Revision: https://reviews.llvm.org/D133365
2022-09-06 10:48:12 -07:00
Stella Stamenova bd323e42c8 Revert "[lldb][bindings] Fix module_access handling of regex"
This reverts commit 75f05fccbb.

This commit broke the windows lldb bot: https://lab.llvm.org/buildbot/#/builders/83/builds/23284
2022-09-06 08:57:28 -07:00
Pavel Labath 65596cede8 [lldb] Go back to process-directed signals in MainLoopTest.cpp
Thread-directed signals are not caught by kqueue (used on Mac). This
reverts half of D133181.
2022-09-06 14:00:53 +02:00
Michał Górny 9823d42557 [lldb] [Core] Split read thread support into ThreadedCommunication
Split the read thread support from Communication into a dedicated
ThreadedCommunication subclass.  The read thread support is used only
by a subset of Communication consumers, and it adds a lot of complexity
to the base class.  Furthermore, having a dedicated subclass makes it
clear whether a particular consumer needs to account for the possibility
of read thread being running or not.

The modules currently calling `StartReadThread()` are updated to use
`ThreadedCommunication`.  The remaining modules use the simplified
`Communication` class.

`SBCommunication` is changed to use `ThreadedCommunication` in order
to avoid changing the public API.

`CommunicationKDP` is updated in order to (hopefully) compile with
the new code.  However, I do not have a Darwin box to test it, so I've
limited the changes to the bare minimum.

`GDBRemoteCommunication` is updated to become a `Broadcaster` directly.
Since it does not inherit from `ThreadedCommunication`, its event
support no longer collides with the one used for read thread and can
be implemented cleanly.  The support for
`eBroadcastBitReadThreadDidExit` is removed from the code -- since
the read thread was not used, this event was never reported.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D133251
2022-09-06 13:09:42 +02:00
Pavel Labath 6a8bbd26ab [lldb] Enable the insertion of "pending callbacks" to MainLoops from other threads
This will be used as a replacement for selecting over a pipe fd, which
does not work on windows. The posix implementation still uses a pipe
under the hood, while the windows version uses windows event handles.

The idea is that, instead of writing to a pipe, one just inserts a
callback, which does whatever you wanted to do after the bytes come out
the read end of the pipe.

Differential Revision: https://reviews.llvm.org/D131160
2022-09-06 10:56:10 +02:00
Kazu Hirata ff2fe7b829 Use llvm::upper_bound (NFC) 2022-09-03 11:17:39 -07:00
Kazu Hirata 89f1433225 Use llvm::lower_bound (NFC) 2022-09-03 11:17:37 -07:00
Dave Lee 75f05fccbb [lldb][bindings] Fix module_access handling of regex
Fixes broken support for: `target.module[re.compile("libFoo")]`

There were two issues:
1. The type check was expecting `re.SRE_Pattern`
2. The expression to search the module path had a typo

In the first case, `re.SRE_Pattern` does not exist in Python 3, and is replaced
with `re.Pattern`.

While editing this code, I changed the type checks to us `isinstance`, which is
the conventional way of type checking.

From the docs on `type()`:

> The `isinstance()` built-in function is recommended for testing the type of an object, because it takes subclasses into account.

Differential Revision: https://reviews.llvm.org/D133130
2022-09-03 10:33:26 -07:00
Adrian Prantl 603d5a8d63 Fix out-of-bounds memory access in test 2022-09-02 18:14:23 -07:00
Jorge Gorbe Moya f021cb57ce [NFC] Remove duplicate code in SBTypeCategory
TypeCategoryImpl has its own implementation of these, so it makes no
sense to have the same logic inlined in SBTypeCategory.

There are other methods in SBTypeCategory that are directly implemented
there, instead of delegating to TypeCategoryImpl (which IMO kinda
defeats the point of having an "opaque" member pointer in the SB type),
but they don't have equivalent implementations in TypeCategoryImpl, so
this patch only picks the low-hanging fruit for now.
2022-09-02 16:04:04 -07:00
Jordan Rupprecht 945bdb167f [test] Remove problematic thread from MainLoopTest to fix flakiness
This test, specifically `TwoSignalCallbacks`, can be a little bit flaky, failing in around 5/2000 runs.

POSIX says:

> If the value of pid causes sig to be generated for the sending process, and if sig is not blocked for the calling thread and if no other thread has sig unblocked or is waiting in a sigwait() function for sig, either sig or at least one pending unblocked signal shall be delivered to the sending thread before kill() returns.

The problem is that in test setup, we create a new thread with `std::async` and that is occasionally not cleaned up. This leaves that thread available to eat the signal we're polling for.

The need for this to be async does not apply anymore, so we can just make it synchronous.

This makes the test passes in 10000 runs.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D133181
2022-09-02 10:30:56 -07:00
Dave Lee a2ec18ee04 [lldb] From unordered_map synthetic provider, return std::pair children
Change the behavior of the libc++ `unordered_map` synthetic provider to present
children as `std::pair` values, just like `std::map` does.

The synthetic provider for libc++ `std::unordered_map` has returned children
that expose a level of internal structure (over top of the key/value pair). For
example, given an unordered map initialized with `{{1,2}, {3, 4}}`, the output
is:

```
(std::unordered_map<int, int, std::hash<int>, std::equal_to<int>, std::allocator<std::pair<const int, int> > >) map = size=2 {
  [0] = {
    __cc = (first = 3, second = 4)
  }
  [1] = {
    __cc = (first = 1, second = 2)
  }
}
```

It's not ideal/necessary to have the numbered children embdedded in the `__cc`
field.

Note: the numbered children have type
`std::__hash_node<std::__hash_value_type<Key, T>, void *>::__node_value_type`,
and the `__cc` fields have type `std::__hash_value_type<Key, T>::value_type`.

Compare this output to `std::map`:

```
(std::map<int, int, std::less<int>, std::allocator<std::pair<const int, int> > >) map = size=2 {
  [0] = (first = 1, second = 2)
  [1] = (first = 3, second = 4)
```

Where the numbered children have type `std::pair<const Key, T>`.

This changes the behavior of the synthetic provider for `unordered_map` to also
present children as `pairs`, just like `std::map`.

It appears the synthetic provider implementation for `unordered_map` was meant
to provide this behavior, but was maybe incomplete (see
d22a94377f). It has both an `m_node_type` and an
`m_element_type`, but uses only the former. The latter is exactly the type
needed for the children pairs. With this existing code, it's not much of a
change to make this work.

Differential Revision: https://reviews.llvm.org/D117383
2022-09-02 08:53:46 -07:00
Kazu Hirata 4535dbd559 [lldb] Fix a warning
This patch fixes:

  lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.h:51:5:
  error: default label in switch which covers all enumeration values
  [-Werror,-Wcovered-switch-default]
2022-09-01 22:14:25 -07:00
Emmmer ff7b876aa7 [LLDB][RISCV] Add more instruction decode and execute for EmulateInstructionRISCV
Add:
- most of instructions from RVI base instructions set.
- some instruction decode tests from objdump.

Further work:
- implement riscv imac extension.

Reviewed By: DavidSpickett

Differential Revision: https://reviews.llvm.org/D132789
2022-09-02 10:17:09 +08:00
Adrian Prantl ced4e0006f Fix inconsistent target arch when attaching to arm64 binaries on
arm64e platforms.

On arm64e-capable Apple platforms, the system libraries are always
arm64e, but applications often are arm64. When a target is created
from file, LLDB recognizes it as an arm64 target, but debugserver will
still (technically correct) report the process as being arm64e. For
consistency, set the target to arm64 here.

rdar://92248684

Differential Revision: https://reviews.llvm.org/D133069
2022-09-01 16:39:35 -07:00
Zequan Wu afeb2d0a21 [LLDB][NativePDB] Fix a minor bug.
llvm::codeview::visitMemberRecordStream in CompleteTagDecl will call
GetOrCreateType create type if not seen before, which inserts new entries
into m_decl_to_status. This may invalidates status which is a reference to
std::pair::second from DenseMapIterator.
2022-09-01 13:10:57 -07:00
Michał Górny 39e0a87c26 [lldb] [Core] Pass error/status from Communication::ReadThread()
Ensure that the ConnectionStatus and Status from
Communication::ReadThread() is correctly passed to ::Read() in order
to fix further discrepancies between ::Read() calls in non-threaded
and threaded modes.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D132577
2022-09-01 14:16:38 +02:00
David Spickett d46ea783e6 [LLDB] Simplify cmake for instruction emulation unit tests
I got suspicious because of checking "ARM" for an "ARM64" plugin.
As far as I can tell these never needed an llvm target to function.

Looking at the corresponding cmake for the libraries under test they
don't reference target libraries either.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D133024
2022-09-01 09:40:04 +00:00
Muhammad Omair Javaid 0e6a71e6a3 [LLDB] Make build.py use uname to set platform
This patch makes build helper script build.py to use platform.uname for
machine/architecture detection. Visual studio environment when set using
various batch files like vcvars*.bat set PLATFORM environment variable
however VsDevCmd.bat does not set PLATFORM variable.

Differential Revision: https://reviews.llvm.org/D133011
2022-09-01 14:00:47 +05:00
Muhammad Omair Javaid 4db7832203 [LLDB] Make API tests to run using MSYS tools
MSYS 'uname' on windows returns "MSYS_NT*" instead of windows32 and also
MSYS 'pwd' returns non-windows path string.
This patch fixes Makefile.rules to make adjustments required to run LLDB
API tests using MSYS tools.

Differential Revision: https://reviews.llvm.org/D133002
2022-09-01 14:00:46 +05:00
Jim Ingham a2670b92a2 Fix a bug in lldb-dotest that was uncovered by setting no value for dotest_args_str.
We were splitting the string, and adding that array to cmd.  But split generated
[''] which shows up later on as an empty "test directory search path".  That got
extended to the CWD + "" which generally doesn't have any tests, so

lldb-dotest -p SomeRealTest.py

would fail with a no matching tests error.

Differential Revision: https://reviews.llvm.org/D133075
2022-08-31 18:00:18 -07:00
Jonas Devlieghere c7511b4ecf
[lldb] Correctly add runtime test dependencies
When a runtime is enabled through LLVM_ENABLE_RUNTIMES, it is loaded
after other projects (i.e. after LLDB). This means that the
corresponding targets don't exist when LLDB is configured. To support
runtimes being enable this way, we need to check if they're listed in
LLVM_ENABLE_RUNTIMES. For runtimes being enabled as projects (i.e.
through LLVM_ENABLE_RUNTIMES) we need to check for the target.

This patch unifies things and correctly adds compiler-rt and libcxx as
test dependencies in both scenarios.
2022-08-31 16:37:35 -07:00
Jonas Devlieghere f328922f55
[lldb] Make the rumtimes target a test dependency
Make the rumtimes target a test dependency. This is needed or the parts
of the test suite that rely on the libcxx and libcxxabi.

Differential revision: https://reviews.llvm.org/D133046
2022-08-31 14:25:07 -07:00
Jonas Devlieghere 0044cb4b20
[lldb] Fix two bugs in ObjectContainerMachOFileset
Fix two small issues in the live-memory variant of ObjectContainerMachOFileset.

Differential revision: https://reviews.llvm.org/D132973
2022-08-30 14:07:20 -07:00
Jim Ingham 5ad6ed0e55 Change the meaning of a UUID with all zeros for data.
Previously, depending on how you constructed a UUID from data or a
StringRef, an input value of all zeros was valid (e.g. setFromData)
or not (e.g. setFromOptionalData).  Since there was no way to tell
which interpretation to use, it was done somewhat inconsistently.
This standardizes the meaning of a UUID of all zeros to Not Valid,
and removes all the Optional methods and their uses, as well as the
static factories that supported them.

Differential Revision: https://reviews.llvm.org/D132191
2022-08-30 10:17:58 -07:00
Martin Storsjö 118038e878 [lldb] Use the NativeSock type instead of plain 'int'
This fixes a warning when building for Windows:

    ../tools/lldb/source/Host/common/TCPSocket.cpp:297:16: warning: comparison of integers of different signs: 'int' and 'const NativeSocket' (aka 'const unsigned long long') [-Wsign-compare]
          if (sock != kInvalidSocketValue) {
              ~~~~ ^  ~~~~~~~~~~~~~~~~~~~

Differential Revision: https://reviews.llvm.org/D132841
2022-08-30 10:07:44 +03:00
Dave Lee a3172df59c [lldb] Quietly source lit-lldb-init
Improve utility of `FileCheck` output when a shell test fails.

The conflict is from:

1. On failure, `FileCheck` prints 5 lines of context
2. Shell tests first source `lit-lldb-init`, having the effect of printing its contents

If a `FileCheck` failure happens at the beginning of the input, then the
context shown is the `lit-lldb-init`, as it's over 5 lines and is the first
thing printed. As the init contents are fairly static, and presumably
uninteresting to most test failures, it seems reasonable to not print it.

Unfortunately it's not possible to use the `--source-quietly` flag in the lldb
invocation, because it will quiet all other `--source` flags on the command
line, making many tests fail.

This fix is a level of indirection, where a new sibling file named
`lit-lldb-init-quiet` is created, and its static contents are:

```
command source -C --silent-run true lit-lldb-init
```

This achieves the result of loading `lit-lldb-init` quietly. The `-C` flag
loads the path relatively.

Differential Revision: https://reviews.llvm.org/D132694
2022-08-29 10:22:01 -07:00
Dave Lee 9537bfeedf [lldb] Remove mention of dotest.pl 2022-08-29 10:21:40 -07:00
Dave Lee 296f7614ed [lldb][test] Speed up lldb arch determination (NFC)
While investigation slow tests, I looked into why `TestMultithreaded.py`. One
of the reasons is that it determines the architecture of lldb by running:

```
lldb -o 'file path/to/lldb' -o 'quit'
```

On my fairly fast machine, this takes 24 seconds, and `TestMultithreaded.py`
calls this function 4 times.

With this change, this command now takes less than 0.2s on the same machine.

The reason it's slow is symbol table and debug info loading, as indicated by
the new progress events printed to the console. One setting reduced the time in
half:

```
settings set target.preload-symbols false
```

Further investigation, by profiling with Instruments on macOS, showed that
loading time was also caused by looking for scripts. The setting that
eliminates this time is:

```
settings set target.load-script-from-symbol-file false
```

Differential Revision: https://reviews.llvm.org/D132803
2022-08-29 10:20:51 -07:00
Martin Storsjö 5f0080fbe8 [lldb] Fix warnings about unused variables when building without asserts. NFC. 2022-08-29 13:25:38 +03:00
Kazu Hirata 920ffab9cc [lldb] Use nullptr instead of NULL (NFC)
Identified with modernize-use-nullptr.
2022-08-27 21:21:07 -07:00
Kazu Hirata 0660249cca [lldb] Remove a redundaunt return statement (NFC)
Identified with readability-redundant-control-flow.
2022-08-27 21:21:05 -07:00
Chelsea Cassanova 53f1cc85e3 [lldb][docs] Fix formatting in fuzzing doc
The page for fuzzing LLDB had incorrectly formatted code,
this commit fixes that.

Differential revision: https://reviews.llvm.org/D132775
2022-08-26 22:15:38 -05:00
Chelsea Cassanova 43d7320e71 [lldb][docs] Add documentation for LLDB fuzzers
This commit adds a new page to the LLDB HTML documentation for the LLDB
fuzzers. The page primarily explains what the fuzzers are as well as how
to build them, run them and investigate and reproduce bugs.

Differential revision: https://reviews.llvm.org/D132148
2022-08-26 18:35:21 -05:00
Pavel Labath 59656c0492 [lldb] Make CommunicationTest compatible with windows
Our (TCP) socket support is in a much better state than pipes. Use that
for testing the Communication class.

Move the CreateTCPConnectedSockets function
(SocketTestUtilities.{h,cpp}) to a place where it can be used from
Communication tests.
2022-08-26 15:25:46 +02:00
Pavel Labath afdfb3ae6b [lldb] Skip TestCoroutineHandle.py on libstdc++<11 2022-08-26 14:04:04 +02:00
Felipe de Azevedo Piovezan bb26ebb4d1 [lldb] Fix dotest argument order
When running LLDB API tests, a user can override test arguments with
LLDB_TEST_USER_ARGS. However, these flags used to be concatenated with a
CMake-derived variable LLDB_TEST_COMMON_ARGS, as below:

```
set(LLDB_DOTEST_ARGS ${LLDB_TEST_COMMON_ARGS};${LLDB_TEST_USER_ARGS}
    CACHE INTERNAL STRING)
```

This is problematic, because LLDB_TEST_COMMON_ARGS must be processed
first, while LLDB_TEST_USER_ARGS args must be processed last, so that
user overrides are respected. Currently, if a user attempts to override
one of the "inferred" flags, the user's request is ignored. This is the
case, for example, with `--libcxx-include-dir` and
`--libcxx-library-dir`. Both flags are needed by the greendragon bots.

This commit removes the concatenation above, keeping the two original
variables throughout the entire flow, processing the user's flag last.

The variable LLDB_TEST_COMMON_ARGS needs to be a CACHE property, but it
is modified throughout the CMake file with `set` or `list` or `string`
commands, which don't work with properties. As such, a temporary
variable `LLDB_TEST_COMMON_ARGS_VAR` is created.

This was tested locally by invoking CMake with:
-DLLDB_TEST_USER_ARGS="--libcxx-include-dir=blah --libcxx-library-dir=blah2"
and checking that tests failed appropriately.

Differential Revision: https://reviews.llvm.org/D132642
2022-08-26 06:52:40 -04:00
Michael Buch 5955edf8a4 [lldb][Test] Add missing breakpoint in TestNamespaceLookup.py 2022-08-26 10:28:28 +01:00
Michael Buch 2b95b50dd6 [lldb][ClangExpression] Fix LLDB_LOG incorrect format specifier
Previously this would log:
```
 FindExternalLexicalDecls on (ASTContext*)0x00000005CE825200 'Expression
ASTContext for '<user expression 0>'' in 'weak_ptr'
(%sDecl*)ClassTemplateSpecialization
 FindExternalLexicalDecls on (ASTContext*)0x00000005CE825200 'Expression
ASTContext for '<user expression 0>'' in '__shared_count'
(%sDecl*)CXXRecord
```

Note that the `%s` isn't actually respected. This patch fixes this
by providing the format specifiers that `lldb::formatv` supports.

Differential Revision: https://reviews.llvm.org/D132709
2022-08-26 10:06:38 +01:00
Adrian Vogelsgesang 6f88388f61 [lldb][test] Fix nullptr test expctation for 32-bit system
Follow-up to https://reviews.llvm.org/D132415

Fixes https://lab.llvm.org/buildbot/#/builders/17/builds/26630
2022-08-25 17:11:57 -07:00
Jonas Devlieghere e360281fa7
[lldb] Computer the slide when and apply it to each fileset's vm addr
Computer the slide when and apply it to each entry's vm addr when
reading from memory.

Differential revision: https://reviews.llvm.org/D132710
2022-08-25 16:38:01 -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
Greg Clayton 613336da8c Don't index the skeleton CU when we have a fission compile unit.
When fission is enabled, we were indexing the skeleton CU _and_ the .dwo CU. Issues arise when users enable compiler options that add extra data to the skeleton CU (like -fsplit-dwarf-inlining) and there can end up being types in the skeleton CU due to template parameters. We never want to index this information since the .dwo file has the real definition, and we really don't want function prototypes from this info since all parameters are removed. The index doesn't work correctly if it does index the skeleton CU as the DIE offset will assume it is from the .dwo file, so even if we do index the skeleton CU, the index entries will try and grab information from the .dwo file using the wrong DIE offset which can cause errors to be displayed or even worse, if the DIE offsets is valid in the .dwo CU, the wrong DIE will be used.

We also fix DWO ID detection to use llvm::Optional<uint64_t> to make sure we can load a .dwo file with a DWO ID of zero.

Differential Revision: https://reviews.llvm.org/D131437
2022-08-25 14:48:04 -07:00
John Ericson 34fe6ddce1 Revert "[CMake] Avoid `LLVM_BINARY_DIR` when other more specific variable are better-suited"
This reverts commit ad8c34bc30.
2022-08-25 11:13:46 -04:00
Felipe de Azevedo Piovezan baeb17cdfa [lldb] Add more dylib paths for exception breakpoints
When setting a breakpoint upon throwing exceptions, LLDB only
searches for the libc++abi code inside dylibs named:
  1. libc++abi.dylib
  2. libSystem.B.dylib

However, this fails to account for libs with a version number. For
example, when building the libcxx and libcxxabi runtimes, the following
dylibs are generated:

build/lib/libc++abi.1.0.dylib
build/lib/libc++abi.1.dylib -> libc++abi.1.0.dylib
build/lib/libc++abi.dylib -> libc++abi.1.dylib

If we are debugging a program linked against any of the "versioned"
libs, the breakpoint doesn't work. This commit adds these names to the
search list.

Differential Revision: https://reviews.llvm.org/D132598
2022-08-25 06:46:04 -04:00
Felipe de Azevedo Piovezan 14d5ae2038 [lldb][nfc] Remove unused makefile test variables
The variables LLDB_USING_LIBCPP and LLDB_USING_LIBSTDCPP are no longer
used anywhere.

Differential Revision: https://reviews.llvm.org/D132596
2022-08-25 06:39:01 -04:00
Michael Buch 9427487fdb [lldb][Test] Prevent generating DW_AT_location for unused argument
This test simply checks whether we can print an optimized
function argument. With recent changes to Clang the assumption
that we don't generate a `DW_AT_location` attribute for the
unused funciton parameter breaks.

This patch tries harder to get Clang to drop the location
from DWARF by making it generate an `undef` for `unused1`.
Drop the check for `unused2` since it adds no benefit.

Differential Revision: https://reviews.llvm.org/D132635
2022-08-25 08:49:13 +01:00