Commit Graph

619 Commits

Author SHA1 Message Date
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
David Spickett c1e6f1a7b1 [lldb] Fix gcc 5.4.0 compile error
Specify type when constructing PromotionKeys,
this fixes error:
"chosen constructor is explicit in copy-initialization"
when compiling lldb with GCC 5.4.0.

This is due to std::tuple having an explicit
default constructor, see:
http://cplusplus.github.io/LWG/lwg-defects.html#2193

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D86690
2020-08-27 10:23:05 +01:00
Jonas Devlieghere 521220690a [lldb] Make Reproducer compatbile with SubsystemRAII (NFC)
Make Reproducer compatbile with SubsystemRAII and use it in
LocateSymbolFileTest.
2020-08-25 13:00:04 -07:00
Jonas Devlieghere a842950b62 [lldb] Add a SymbolFileProvider to record and replay calls to dsymForUUID
When replaying a reproducer captured from a core file, we always use
dsymForUUID for the kernel binary. When enabled, we also use it to find
kexts. Since these files are already contained in the reproducer,
there's no reason to call out to an external tool. If the tool returns a
different result, e.g. because the dSYM got garbage collected, it will
break reproducer replay. The SymbolFileProvider solves the issue by
mapping UUIDs to module and symbol paths in the reproducer.

Differential revision: https://reviews.llvm.org/D86389
2020-08-24 15:09:08 -07:00
Gongyu Deng 3cd8d7b172 [lldb] Remote disk file/directory completion for platform commands
1. Extended the gdb-remote communication related classes with disk file/directory
   completion functions;
2. Added two common completion functions RemoteDiskFiles and
   RemoteDiskDirectories based on the functions above;
3. Added completion for these commands:
   A. platform get-file <remote-file> <local-file>;
   B. platform put-file <local-file> <remote-file>;
   C. platform get-size <remote-file>;
   D. platform settings -w <remote-dir>;
   E. platform open file <remote-file>.
4. Added related tests for client and server;
5. Updated docs/lldb-platform-packets.txt.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D85284
2020-08-24 17:55:54 +02:00
Pavel Labath 0e301fd023 [lldb/Utility] Remove some Scalar type accessors
Now that the number of Scalar "types" has been reduced, these don't make
sense anymore.
2020-08-24 11:45:30 +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
Jonas Devlieghere 73af341beb [lldb] Capture and load home directory from the reproducer.
When replaying the reproducer, lldb should source the .lldbinit file
that was captured by the reproducer and not the one in the current home
directory. This requires that we store the home directory as part of the
reproducer. By returning the virtual home directory during replay, we
ensure the correct virtual path gets constructed which the VFS can then
find and remap to the correct file in the reproducer root.

This patch adds a new HomeDirectoryProvider, similar to the existing
WorkingDirectoryProvider. As the home directory is not part of the VFS,
it is stored in LLDB's FileSystem instance.
2020-08-20 18:08:59 -07:00
Jonas Devlieghere c90ca0c8e4 [lldb] Implement WorkingDirectoryProvider in terms of DirectoryProvider (NFC)
Add an abstract base class that can be used to create other directory
providers.
2020-08-20 18:08:59 -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
Pavel Labath 40d774265b [lldb/Utility] Simplify Scalar::PromoteToMaxType
The function had very complicated signature, because it was trying to
avoid making unnecessary copies of the Scalar object. However, this
class is not hot enough to worry about these kinds of optimizations. My
making copies unconditionally, we can simplify the function and all of
its call sites.

Differential Revision: https://reviews.llvm.org/D85906
2020-08-14 11:09:16 +02: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
Jonas Devlieghere 9097ef84ce [lldb] Remove pointless assign to found_suffix (NFC) 2020-08-05 22:54:03 -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
Fred Riss ef748b58d3 [lldb] NFC: Use early exit in ArchSpec::IsEqualTo 2020-07-27 14:12:02 -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
Adrian Prantl e937840dbd Upstream macCatalyst support in ArchSpec and associated unit tests. 2020-07-24 18:01:41 -07:00
Jonas Devlieghere ccdb5b4bbe [lldb] Pass ConstString by value (again) (NFC)
This reverts "Eliminate unneeded value parameters in Utility" for
ConstString. As Pavel pointed out on the mailing list, the class *is*
trivially copyable.
2020-07-23 09:08:32 -07:00
Jonas Devlieghere 0d5fc82245 [lldb] Eliminate unneeded value parameters in Utility (NFC)
Eliminates value parameter for types that are not trivially copyable.
2020-07-22 13:56:23 -07:00
Jonas Devlieghere 9f8d481d68 [lldb/Reproducers] Don't recursively record everything in the CWD
RecordInterestingDirectory was added to collect dSYM bundles and their
content. For the current working directory we only want the directory to
be part of the VFS, not necessarily its contents. This patch renames the
current method to RecordInterestingDirectoryRecursively and adds a new
one that's not recursive.
2020-07-21 09:02:38 -07:00
Jonas Devlieghere 3f16114ddb [lldb] Fix method name to match LLDB code style (NFC)
recordInterestingDirectory -> RecordInterestingDirectory
2020-07-20 11:54:11 -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
Muhammad Omair Javaid a65da5f592 [LLDB] Update AArch64 Dwarf and EH frame register numbers
This patch updates ARM64_ehframe_Registers.h and ARM64_DWARF_Registers.h
with latest register numbers in line with AArch64 SVE support.

For refernce take a look at "DWARF for the ARM® 64-bit Architecture (AArch64)
with SVE support" manual from Arm.
Version used: abi_sve_aadwarf_100985_0000_00_en.pdf
2020-07-10 11:45:39 +05:00
Pavel Labath 88c82474d2 [lldb/Utility] Simplify Scalar float accessors
Make use of APFloat conversion methods to avoid needing to switch based
on the stored value type.
2020-07-08 13:57:32 +02: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 228ea81583 [lldb/Utility] Simplify more Scalar methods
A lot of the methods handle all integral and all floating point types
the same way. They can be changed to switch on the category of the type,
instead of the actual type, saving a lot of boilerplate.

This patch does that for the methods where I could be reasonably certain
of their expected semantics.
2020-07-03 16:35:14 +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
Jonas Devlieghere 2501e86acd [lldb/Scalar] Fix undefined behavior
Fix UBSan error detected in TestDataFormatterObjCCF.py and
TestDataFormatterObjCNSDate.py:

Scalar.cpp:698:27: runtime error: -4.96303e+08 is outside the range of
representable values of type 'unsigned long long'.
2020-06-30 12:41:41 -07:00
Pavel Labath 48ca15592f [lldb] Deduplicate Scalar integral getters
These functions all follow the same pattern. Use template functions to
deduplicate.
2020-06-29 15:24:39 +02:00
Pavel Labath ce275d3030 [lldb] Rewrite Scalar::Promote
This function was implementing c-like promotion rules by switching on
the both types. C promotion rules are complicated, but they are not
*that* complicated -- they basically boil down to:
- wider types trump narrower ones
- unsigned trump signed
- floating point trumps integral

With a couple of helper functions, we can rewrite the function in terms
of these rules and greatly reduce the size and complexity of this
function.
2020-06-26 11:46:47 +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
Eric Christopher efb328f674 As part of using inclusive language with the llvm project,
migrate away from the use of blacklist and whitelist.
2020-06-19 14:48:48 -07:00
Raphael Isemann f5eaa2afe2 [lldb] Replace std::isprint/isspace with llvm's locale-independent version
Summary:
LLVM is using its own isPrint/isSpace implementation that doesn't change depending on the current locale. LLDB should do the same
to prevent that internal logic changes depending on the set locale.

Reviewers: JDevlieghere, labath, mib, totally_not_teemperor

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D82175
2020-06-19 19:17:56 +02:00
Pavel Labath e966a5deaa [lldb] Remove Scalar operator= overloads
The are not needed as Scalar is implicitly constructible from all of
these types (so the compiler will use a combination of a constructor +
move assignment instead), and they make it very easy for implementations
of assignment and construction operations to diverge.
2020-06-11 13:55:02 +02:00
Raphael Isemann bb9d93f4d5 [lldb] Replace the LEB128 decoding logic in LLDB's DataExtractor with calls to LLVM's LEB128 implementation
Reviewers: labath, JDevlieghere

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D81453
2020-06-10 16:35:09 +02:00
Pavel Labath 040eca7717 [lldb/Utility] Remove m_ieee_quad from Scalar
This field is unused (the only way to change its value is via a
constructor which is never called), and as far as I can tell it has been
unused since it was introduced in D12100. It also has some soundness
issues -- e.g.  operator= does not reinitialize it, but uses the old
value from the overwritten object.

It sounds like this class should be able to support different floating
point semantics, but if that is needed, it would be better to start
afresh -- probably by passing in an APFloat::fltSemantics object instead
of a bool flag.
2020-06-10 15:15:01 +02:00
Jonas Devlieghere de019b88dd [lldb/Interpreter] Support color in CommandReturnObject
Color the error: and warning: part of the CommandReturnObject output,
similar to how an error is printed from the driver when colors are
enabled.

Differential revision: https://reviews.llvm.org/D81058
2020-06-09 10:45:45 -07: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 846909e2ab [lldb] Fix UBSan regression in GetSLEB128
It regressed recently by my: https://reviews.llvm.org/D81119
2020-06-05 12:00:44 +02: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 e7f1067ad6 [lldb/Reproducers] Skip API logging in the DUMMY macro
The purpose of the LLDB_RECORD_DUMMY macro is twofold: it is used in
functions that take arguments that we don't know how to serialize (e.g.
void*) and it's used by function where we want to avoid doing excessive
work because they can be called from a signal handler (e.g.
setTerminalWidth).

To support the latter case, I've disabled API logging form the Recorder
ctor used by the DUMMY macro. This ensures we don't allocate memory when
called from a signal handler.
2020-05-27 10:35:43 -07:00