Commit Graph

250 Commits

Author SHA1 Message Date
Raphael Isemann 0f3ed7a48d [lldb] Fix incorrect test data in FileSpecTest.IsRelative
Found by clang-tidy's bugprone-suspicious-missing-comma.
2021-04-15 12:42:47 +02:00
Pavel Labath 3bea7306e8 [lldb] Fix compilation with gcc-6.5
This fixes (works around) two errors with gcc-6.5.
- in the RegisterContext_x86 files, gcc is unable to synthesize a
  default constructor -- it thinks it needs to initialize the virtual
  base class, even though said classes are abstract. I fix that by
  providing a dummy constructor.
- In ReproducerInstrumentationTest, it is not able to deduce that the
  TestingRegistry class is movable (it contains a map of unique
  pointers). I change the type from Optional<TestingRegistry> to
  unique_ptr<TestingRegistry), so that moving is not required
  (copying/moving a polymorphic type is not a very good idea in any
  case).
2021-04-01 08:44:50 +02:00
Michał Górny 6c1a8039de [lldb] [server] Support for multiprocess extension
Add a minimal support for the multiprocess extension in lldb-server.
The server indicates support for it via qSupported, and accepts
thread-ids containing a PID.  However, it still does not support
debugging more than one inferior, so any other PID value results
in an error.

Differential Revision: https://reviews.llvm.org/D98482
2021-03-30 15:09:27 +02:00
Jonas Devlieghere ac25e8628c [lldb] Deal gracefully with concurrency in the API instrumentation.
Prevent lldb from crashing when multiple threads are concurrently
accessing the SB API with reproducer capture enabled.

The API instrumentation records both the input arguments and the return
value, but it cannot block for the duration of the API call. Therefore
we introduce a sequence number that allows to to correlate the function
with its result and add locking to ensure those two parts are emitted
atomically.

Using the sequence number, we can detect situations where the return
value does not succeed the function call, in which case we print an
error saying that concurrency is not (currently) supported. In the
future we might attempt to be smarter and read ahead until we've found
the return value matching the current call.

Differential revision: https://reviews.llvm.org/D92820
2020-12-10 09:37:49 -08:00
Jonas Devlieghere dcdd231df6 [lldb] Return the original path when tilde expansion fails.
Differential revision: https://reviews.llvm.org/D92513
2020-12-02 16:01:30 -08:00
Pavel Labath ac6799d25a [lldb] Improve RegisterValue::GetScalarValue
Using Scalar::SetValueFromData, we make the code simpler, handle
big-endian systems properly, _and_ avoid type aliasing issues.
2020-11-04 14:53:06 +01:00
Pavel Labath d2700b7873 [lldb/Utility] Add unit tests for RegisterValue::GetScalarValue
Buggy cases are commented out.

Also sneak in a modernization of a RegisterValue constructor.
2020-11-03 16:12:32 +01:00
Raphael Isemann bb1d702e25 [lldb][NFC] Make GetShellSafeArgument return std::string and unittest it. 2020-10-22 14:47:10 +02:00
Alexandre Ganea 79809f58b0 [LLDB] On Windows, fix tests
This patch fixes a few issues seen when running `ninja check-lldb` in a Release build with VS2017:

- Some binaries couldn't be found (such as lldb-vscode.exe), because .exe wasn't appended to the file name.
- Many tests used to fail since our installed locale is in French - the OS error messages are not emitted in English.
- Our codepage being Windows-1252, python failed to decode some error messages with accentuations.

Differential Revision: https://reviews.llvm.org/D88975
2020-10-08 11:46:59 -04:00
Pavel Labath 219ccdfdde [lldb/Utility] Use APSInt in the Scalar class
This enables us to further simplify some code because it no longer needs
to switch on the signedness of the type (APSInt handles that).
2020-08-27 15:05:47 +02:00
Jonas Devlieghere bb894b9782 [lldb] Extract reproducer providers & co into their own header.
Extract all the provider related logic from Reproducer.h and move it
into its own header ReproducerProvider.h. These classes are seeing most
of the development these days and this reorganization reduces
incremental compilation from ~520 to ~110 files when making changes to
the new header.
2020-08-22 10:04:27 -07:00
Pavel Labath 8a8a2dd316 [lldb/Utility] Simplify Scalar handling of float types
Similarly to D85836, collapse all Scalar float types to a single enum
value, and use APFloat semantics to differentiate between. This
simplifies the code, and opens to door to supporting other floating
point semantics (which would be needed for fully supporting
architectures with more interesting float types such as PPC).

Differential Revision: https://reviews.llvm.org/D86220
2020-08-20 16:26:02 +02:00
Pavel Labath 67cdb899c6 [lldb/Utility] Simplify and generalize Scalar class
The class contains an enum listing all host integer types as well as
some non-host types. This setup is a remnant of a time when this class
was actually implemented in terms of host integer types. Now that we are
using llvm::APInt, they are mostly useless and mean that each function
needs to enumerate all of these cases even though it treats most of them
identically.

I only leave e_sint and e_uint to denote the integer signedness, but I
want to remove that in a follow-up as well.

Removing these cases simplifies most of these functions, with the only
exception being PromoteToMaxType, which can no longer rely on a simple
enum comparison to determine what needs to be promoted.

This also makes the class ready to work with arbitrary integer sizes, so
it does not need to be modified when someone needs to add a larger
integer size.

Differential Revision: https://reviews.llvm.org/D85836
2020-08-17 11:09:56 +02:00
Adrian McCarthy 7ddfb956e1 [lldb] Fix unit test parsing to handle CR+LF as well as LF
Apparently when the strings are created, the `'\n'` is converted to the
platform's natural new line indicator, which is CR+LF on Windows.  But
upon reading back with `sscanf`, the CRs caused a matching failure.
2020-08-12 13:56:16 -07:00
Adrian Prantl 05df9cc703 Correctly detect legacy iOS simulator Mach-O objectfiles
The code in ObjectFileMachO didn't disambiguate between ios and
ios-simulator object files for Mach-O objects using the legacy
ambiguous LC_VERSION_MIN load commands. This used to not matter before
taught ArchSpec that ios and ios-simulator are no longer compatible.

rdar://problem/66545307

Differential Revision: https://reviews.llvm.org/D85358
2020-08-06 12:40:45 -07:00
Fred Riss 8120eba5fc [lldb/ArchSpec] Always match simulator environment in IsEqualTo
Summary:
Initially, Apple simulator binarie triples didn't use a `-simulator`
environment and were just differentiated based on the architecture.
For example, `x86_64-apple-ios` would obviously be a simualtor as iOS
doesn't run on x86_64. With Catalyst, we made the disctinction
explicit and today, all simulator triples (even the legacy ones) are
constructed with an environment. This is especially important on Apple
Silicon were the architecture is not different from the one of the
simulated device.

This change makes the simulator part of the environment always part of
the criteria to detect whether 2 `ArchSpec`s are equal or compatible.

Reviewers: aprantl

Subscribers: inglorion, dexonsmith, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D84716
2020-07-27 17:33:37 -07:00
Pavel Labath e89414f406 [lldb/Utility] Clean up Scalar constructors
- move initialization to initializer lists
- make desctructor non-virtual (nothing else is)
- fix long double constructor so that it actually works
2020-07-27 10:06:56 +02:00
Pavel Labath 81d7ebaf5c [lldb/Utility] Fix a bug in RangeMap::CombineConsecutiveRanges
The function didn't combine a large entry which overlapped several other
entries, if those other entries were not overlapping among each other.

E.g., (0,20),(5,6),(10,11) produced (0,20),(10,11)

Now it just produced (0,20).
2020-07-27 10:06:56 +02:00
Adrian Prantl e937840dbd Upstream macCatalyst support in ArchSpec and associated unit tests. 2020-07-24 18:01:41 -07:00
Pavel Labath 7fadd70069 [lldb/Utility] Simplify Scalar::SetValueFromData
The function was fairly complicated and didn't support new bigger
integer sizes. Use llvm function for loading an APInt from memory to
write a unified implementation for all sizes.
2020-07-20 15:56:56 +02:00
Pavel Labath 1847f4dd75 [lldb/Utility] Rewrite Scalar::SetValueFromCString
The function's reliance on host types meant that it was needlessly
complicated, and did not handle the newer (wider) types. Rewrite it in
terms of APInt/APFloat functions to save code and improve functionality.
2020-07-13 16:44:42 +02:00
Jonas Devlieghere 169c83208f [ldb/Reproducers] Add YamlRecorder and MultiProvider
This patch does several things that are all closely related:

 - It introduces a new YamlRecorder as a counterpart to the existing
   DataRecorder. As the name suggests the former serializes data as yaml
   while the latter uses raw texts or bytes.

 - It introduces a new MultiProvider base class which can be backed by
   either a DataRecorder or a YamlRecorder.

 - It reimplements the CommandProvider in terms of the new
   MultiProvider.

Finally, it adds unit testing coverage for the MultiProvider, a naive
YamlProvider built on top of the new YamlRecorder and the existing
MutliLoader.

Differential revision: https://reviews.llvm.org/D83441
2020-07-10 12:48:22 -07:00
Jonas Devlieghere 5e9b16b67f [lldb] Fix unaligned load in DataExtractor
Somehow UBSan would only report the unaligned load in TestLinuxCore.py
when running the tests with reproducers. This patch fixes the issue by
using a memcpy in the GetDouble and the GetFloat method.

Differential revision: https://reviews.llvm.org/D83256
2020-07-07 10:13:41 -07:00
Pavel Labath 52495b98ee [lldb/Utility] Fix float->integral conversions in Scalar APInt getters
These functions were doing a bitcast on the float value, which is not
consistent with the other getters, which were doing a numeric conversion
(47.0 -> 47). Change these to do numeric conversions too.
2020-07-07 16:59:06 +02:00
Pavel Labath 5daa39aa4c [lldb/Utility] Merge Scalar::Get(Value)TypeAsCString 2020-07-06 10:34:12 +02:00
Pavel Labath b725142c8d [lldb] Fix type conversion in the Scalar getters
Summary:
The Scalar class claims to follow the C type conversion rules. This is
true for the Promote function, but it is not true for the implicit
conversions done in the getter methods.

These functions had a subtle bug: when extending the type, they used the
signedness of the *target* type in order to determine whether to do
sign-extension or zero-extension. This is not how things work in C,
which uses the signedness of the *source* type. I.e., C does
(sign-)extension before it does signed->unsigned conversion, and not the
other way around.

This means that: (unsigned long)(int)-1
      is equal to (unsigned long)0xffffffffffffffff
      and not (unsigned long)0x00000000ffffffff

Unsurprisingly, we have accumulated code which depended on this
inconsistent behavior. It mainly manifested itself as code calling
"ULongLong/SLongLong" as a way to get the value of the Scalar object in
a primitive type that is "large enough". Previously, the ULongLong
conversion did not do sign-extension, but now it does.

This patch makes the Scalar getters consistent with the declared
semantics, and fixes the couple of call sites that were using it
incorrectly.

Reviewers: teemperor, JDevlieghere

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D82772
2020-07-02 18:02:57 +02:00
Pavel Labath 8270a903ba [lldb] Scalar re-fix UB in float->int conversions
The refactor in 48ca15592f reintroduced UB when converting out-of-bounds
floating point numbers to integers -- the behavior for ULongLong() was
originally fixed in r341685, but did not survive my refactor because I
based my template code on one of the methods which did not have this
fix.

This time, I apply the fix to all float->int conversions, instead of
just the "double->unsigned long long" case. I also use a slightly
simpler version of the code, with fewer round-trips
(APFloat->APSInt->native_int vs
APFloat->native_float->APInt->native_int).

I also add some unit tests for the conversions.
2020-07-01 10:29:42 +02:00
Pavel Labath d0fa52cc37 [lldb] Rewrite Scalar::GetBytes
This function was modifying and returning pointers to static storage,
which meant that any two accesses to different Scalar objects could
potentially race (depending on which types the objects were storing and
the host endianness).

In the new version the user is responsible for providing a buffer into
which this method will store its binary representation. The main caller
(RegisterValue::GetBytes) already has one such buffer handy, so this did
not require any major rewrites.

To make that work, I've needed to mark the RegisterValue value buffer
mutable -- not an ideal solution, but definitely better than modifying
global storage. This could be further improved by changing
RegisterValue::GetBytes to take a buffer too.
2020-06-25 15:31:48 +02:00
Pavel Labath 16e17ca16a [lldb] Refactor Scalar::TruncOrExtendTo
The "type" argument to the function is mostly useless -- the only
interesting aspect of it is signedness. Pass signedness directly and
compute the value of bits and signedness fields -- that's exactly
what the single caller of this function does.
2020-06-24 15:58:33 +02:00
Jaroslav Sevcik 1beffc1888 Support build-ids of other sizes than 16 in UUID::SetFromStringRef
SBTarget::AddModule currently handles the UUID parameter in a very
weird way: UUIDs with more than 16 bytes are trimmed to 16 bytes. On
the other hand, shorter-than-16-bytes UUIDs are completely ignored. In
this patch, we change the parsing code to handle UUIDs of arbitrary
size.

To support arbitrary size UUIDs in SBTarget::AddModule, this patch
changes UUID::SetFromStringRef to parse UUIDs of arbitrary length. We
subtly change the semantics of SetFromStringRef - SetFromStringRef now
only succeeds if the entire input is consumed to prevent some
prefix-parsing confusion. This is up for discussion, but I believe
this is more consistent - we always return false for invalid UUIDs
rather than sometimes truncating to a valid prefix. Also, all the
call-sites except the API and interpreter seem to expect to consume
the entire input.

This also adds tests for adding existing modules 4-, 16-, and 20-byte
build-ids. Finally, we took the liberty of testing the minidump
scenario we care about - removing placeholder module from minidump and
replacing it with the real module.

Reviewed By: labath, friss

Differential Revision: https://reviews.llvm.org/D80755
2020-06-07 10:03:41 +00:00
Adrian Prantl 3d7b926dd1 Move GetXcode*Directory into HostInfo (NFC)
These functions really don't belong into PlatformDarwin, since they
actualy query state of the Host and not of the remote platform.
2020-06-05 11:59:22 -07:00
Jan Kratochvil 476f520a0b [lldb] Fix SLEB128 decoding
Bug 46181 shows SLEB128 0xED9A924C00011151 decoded as 0xffffffff80011151.
        LLDB show a wrong value for function argument
        https://bugs.llvm.org/show_bug.cgi?id=46181

Differential Revision: https://reviews.llvm.org/D81119
2020-06-04 19:41:24 +02:00
Andy Yankovsky 798644e0a4 [Scalar] Fix assignment operator for long long.
Summary:
Assignment operator `operator=(long long)` currently allocates `sizeof(long)`.
On some platforms it works as they have `sizeof(long) == sizeof(long long)`,
but on others (e.g. Windows) it's not the case.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D80995
2020-06-03 13:26:25 +02:00
Jonas Devlieghere bad61548b2 [Reproducers] Serialize process arguments in ProcessInfo
While debugging why TestProcessList.py failed during passive replay, I
remembered that we don't serialize the arguments for ProcessInfo. This
is necessary to make the test pass and to make platform process list -v
behave the same during capture and replay.

Differential revision: https://reviews.llvm.org/D79646
2020-05-12 11:12:37 -07:00
Adrian Prantl ae920a81ff Add an API to construct an XcodeSDK from an SDK type.
Also, this moves numSDKs out of the actual enum, as to not mess with
the switch-cases-covered warning.

Differential Revision: https://reviews.llvm.org/D79603
2020-05-08 10:47:13 -07:00
Adrian Prantl dec1c94e80 Add a function to detect whether an Xcode SDK supports Swift
Differential Revision: https://reviews.llvm.org/D79535
2020-05-07 11:29:31 -07:00
Adrian Prantl 6e95d51ecf Add an XcodeSDK::GetSDKTypeForTriple function
This is something used in swift-lldb, but of general usefulness.

Differential Revision: https://reviews.llvm.org/D79538

<rdar://problem/62684906>
2020-05-07 11:12:42 -07:00
Reid Kleckner 58c7bf246e Update LLDB filespec tests for remove_dots change
It looks like the new implementation is correct, since there were TODOs
here about getting the new behavior.

I am not sure if "C:..\.." should become "C:" or "C:\", though. The new
output doesn't precisely match the TODO message, but it seems
appropriate given the specification of remove_dots and how .. traversals
work at the root directory.
2020-05-04 17:27:16 -07:00
Adrian Prantl b9c7e276bd Disable path-sensitive test on Windows. 2020-04-24 15:21:54 -07:00
Adrian Prantl 79feafa514 Add an internal bit to the XcodeSDK class.
For developing the OS itself there exists an "internal" variant of
each SDK. This patch adds support for these SDK directories to the
XcodeSDK class.

Differential Revision: https://reviews.llvm.org/D78675
2020-04-24 12:55:53 -07:00
Pavel Labath f512b978b0 [lldb/Utility] Improve error_code->Status conversion
Both entities have the notion of error "namespaces". Map the errno
namespace correctly.
2020-04-23 16:12:41 +02:00
Jonas Devlieghere e687aa8282 [lldb/Reproducers] Fix passive replay for (char*, size_t) functions.
Several SB API functions return strings using (char*, size_t) output
arguments. During capture, we serialize an empty string for the char*
because the memory can be uninitialized.

During active replay, we have custom replay redirects that ensure that
we don't override the buffer from which we're reading, but rather write
to a buffer on the heap with the given length. This is sufficient for
the active reproducer use case, where we only care about the side
effects of the API calls, not the values actually returned.

This approach does not not work for passive replay because here we
ignore all the incoming arguments, and re-execute the current function
with the arguments deserialized from the reproducer. This means that
these function will update the deserialized copy of the arguments,
rather than whatever was passed in by the SWIG wrapper.

To solve this problem, this patch extends the reproducer instrumentation
to handle this special case for passive replay. We nog ignore the
replayer in the registry and the incoming char pointer, and instead
reinvoke the current method on the deserialized class, and populate the
output argument.

Differential revision: https://reviews.llvm.org/D77759
2020-04-20 13:26:11 -07:00
Jonas Devlieghere e128d53895 [lldb/Test] Don't friend std::make_unique
This wasn't a great idea to begin with, as you can't really rely on the
implementation, but since it also doesn't work with MSVC I've just made
the ctors public.
2020-04-20 11:48:52 -07:00
Jonas Devlieghere 950a8aa165 [lldb/Reproducers] Support new replay mode: passive replay
Support passive replay as proposed in the RFC [1] on lldb-dev and
described in more detail on the lldb website [2].

This patch extends the LLDB_RECORD macros to re-invoke the current
function with arguments deserialized from the reproducer. This relies on
the function being called in the exact same order as during replay. It
uses the same mechanism to toggle the API boundary as during recording,
which guarantees that only boundary crossing calls are replayed.

Another major change is that before this patch we could ignore the
result of an API call, because we only cared about the observable
behavior. Now we need to be able to return the replayed result to the
SWIG bindings.

We reuse a lot of the recording infrastructure, which can be a little
confusing. We kept the existing naming to limit the amount of churn, but
might revisit that in a future patch.

[1] http://lists.llvm.org/pipermail/lldb-dev/2020-April/016100.html
[2] https://lldb.llvm.org/resources/reproducers.html

Differential revision: https://reviews.llvm.org/D77602
2020-04-20 09:41:40 -07:00
Jonas Devlieghere cc220d4031 [lldb/Test] Use RAII for reproducer instrumentation data in unittest.
Use a RAII object to manage the lifetime of the reproducer
instrumentation data.
2020-04-14 14:46:39 -07:00
Jonas Devlieghere f78fcd6906 [lldb/Test] Rewrite ReproducerInstrumentationTest
The instrumentation unit tests' current implementation uses global
variables to track constructor calls for the instrumented classes during
replay. This is suboptimal because it indirectly relies on how the
reproducer instrumentation is implemented. I found out when adding
support for passive replay and the test broke because we made an extra
(temporary) copy of the instrumented objects.

Additionally, the old approach wasn't very self-explanatory. It took me
a bit of time to understand why we were expecting the number of objects
in the test.

This patch rewrites the test and uses the index-to-object-mapping to
verify the objects created during replay. You can now specify the
expected objects, in order, and whether they should be valid or not. I
find that it makes the tests much easier to understand. More
importantly, this approach is resilient to implementation detail changes
in the instrumentation.
2020-04-10 16:50:44 -07:00
Adrian Prantl 1e05d7b3d3 Remap the target (Xcode) SDK directory to the host SDK directory.
This is mostly useful for Swift support; it allows LLDB to substitute
a matching SDK it shipped with instead of the sysroot path that was
used at compile time.

The goal of this is to make the Xcode SDK something that behaves more
like the compiler's resource directory, as in that it ships with LLDB
rather than with the debugged program. This important primarily for
importing Swift and Clang modules in the expression evaluator, and
getting at the APINotes from the SDK in Swift.

For a cross-debugging scenario, this means you have to have an SDK for
your target installed alongside LLDB. In Xcode this will always be the
case.

rdar://problem/60640017

Differential Revision: https://reviews.llvm.org/D76471
2020-04-06 15:51:30 -07:00
Kazuaki Ishizaki e9264b746b [lldb] NFC: Fix trivial typo in comments, documents, and messages
Differential Revision: https://reviews.llvm.org/D77460
2020-04-07 01:06:16 +09:00
Emre Kultursay 57be22fa17 [LLDB] Fix parsing of IPv6 host:port inside brackets
Summary:
When using IPv6 host:port pairs, typically the host is put inside
brackets, such as [2601🔢...:0213]:5555, and the UriParser
can handle this format.

However, the Android infrastructure in LLDB assumes an additional
brackets around the host:port pair, such that the entire host:port
string can be treated as the host (which is used as an Android Serial
Number), and UriParser cannot handle multiple brackets. Parsing
inputs with such extra backets requires searching the closing bracket
from the right.

Test: BracketedHostnameWithPortIPv6 covers the case mentioned above

Reviewers: #lldb, labath

Reviewed By: labath

Subscribers: kwk, shafik, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D76736
2020-03-26 11:35:54 +01:00
Jonas Devlieghere 14970669dd [lldb/Test] Add unittest for FileSpec::operator bool() 2020-03-18 15:08:23 -07:00