Commit Graph

388 Commits

Author SHA1 Message Date
Jonas Devlieghere 5650eb5b00 [Reproducers] Stop recording instead of deallocating
The command interpreter holds a pointer to a DataRecorder. After
generating the reproducer, we deallocated all the DataRecorders, causing
the command interpreter to hold a non-null reference to an invalid
object.

This patch changes the behavior of the command provider to stop the
DataRecorders when a reproducer is generated, rather than deallocating
them.

llvm-svn: 355940
2019-03-12 17:10:28 +00:00
Adrian Prantl f05b42e960 Bring Doxygen comment syntax in sync with LLVM coding style.
This changes '@' prefix to '\'.

llvm-svn: 355841
2019-03-11 17:09:29 +00:00
Adrian Prantl 28f7466f4e Promote more debug-only assertions to regular assertions.
llvm-svn: 355569
2019-03-07 00:14:20 +00:00
Adrian Prantl 0e4c482124 Pass ConstString by value (NFC)
My apologies for the large patch. With the exception of ConstString.h
itself it was entirely produced by sed.

ConstString has exactly one const char * data member, so passing a
ConstString by reference is not any more efficient than copying it by
value. In both cases a single pointer is passed. But passing it by
value makes it harder to accidentally return the address of a local
object.

(This fixes rdar://problem/48640859 for the Apple folks)

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

llvm-svn: 355553
2019-03-06 21:22:25 +00:00
Zachary Turner 805e71060e Move ProcessInfo from Host to Utility.
There are set of classes in Target that describe the parameters of a
process - e.g. it's PID, name, user id, and similar. However, since it
is a bare description of a process and contains no actual functionality,
there's nothing specifically that makes this appropriate for being in
Target -- it could just as well be describing a process on the host, or
some hypothetical virtual process that doesn't even exist.

To cement this, I'm moving these classes to Utility. It's possible that
we can find a better place for it in the future, but as it is neither
Host specific nor Target specific, Utility seems like the most appropriate
place for the time being.

After this there is only 2 remaining references to Target from Host,
which I'll address in a followup.

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

llvm-svn: 355342
2019-03-04 21:51:03 +00:00
Pavel Labath aa51e6a683 Refactor user/group name resolving code
Summary:
This creates an abstract base class called "UserIDResolver", which can
be implemented to provide user/group ID resolution capabilities for
various objects. Posix host implement a PosixUserIDResolver, which does
that using posix apis (getpwuid and friends).  PlatformGDBRemote
forwards queries over the gdb-remote link, etc. ProcessInstanceInfo
class is refactored to make use of this interface instead of taking a
platform pointer as an argument. The base resolver class already
implements caching and thread-safety, so implementations don't have to
worry about that.

The main motivating factor for this was to remove external dependencies
from the ProcessInstanceInfo class (so it can be put next to
ProcessLaunchInfo and friends), but it has other benefits too:
- ability to test the user name caching code
- ability to test ProcessInstanceInfo dumping code
- consistent interface for user/group resolution between Platform and
  Host classes.

Reviewers: zturner, clayborg, jingham

Subscribers: mgorny, lldb-commits

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

llvm-svn: 355323
2019-03-04 18:48:00 +00:00
Pavel Labath 113c4c108d Fix gcc build for r355249
automatic move should not fire when returning type T in a function with
result type Expected<T>. Some compilers seem to allow that nonetheless.

llvm-svn: 355270
2019-03-02 16:23:07 +00:00
Jonas Devlieghere d77c2e0926 [Reproducers] Capture and replay interpreter commands.
This patch adds the necessary logic to capture and replay commands
entered into the command interpreter. A DataRecorder shadows the input
and writes its data to a know file. During replay this file is used as
the command interpreter's input.

It's possible to the command interpreter more than once, with a
different input source. We support this scenario by using multiple
buffers. The synchronization for this takes place at the SB layer, where
we create a new recorder every time the debugger input is changed.
During replay we use the corresponding buffer as input.

Differential revision: https://reviews.llvm.org/D58564

llvm-svn: 355249
2019-03-02 00:20:26 +00:00
Jonas Devlieghere 8c436ce3a1 [Reproducers] Add more logging to reproducer instrumentation
Debugging issues with instrumentation capture and replay can be
particularly tricky, especially because part of the process takes places
even before the debugger is initialized. This patch adds more logging
capabilities to these classes, hidden behind a macro define.

Differential revision: https://reviews.llvm.org/D58566

llvm-svn: 355002
2019-02-27 16:40:08 +00:00
Alex Langford 6d6288ae97 [Utility] Fix ArchSpec.MergeFrom to correctly merge environments
Summary:
This behavior was originally added in rL252264 (git commit 76a7f365da)
in order to be extra careful with handling platforms like watchos and tvos.
However, as far as triples go, those two (and others) are treated as OSes and
not environments, so that should not really apply here.

Additionally, this behavior is incorrect and can lead to incorrect ArchSpecs.
Because android is specified as an environment and not an OS, not propogating
the environment can lead to modules and targets being misidentified.

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

llvm-svn: 354938
2019-02-27 00:47:39 +00:00
Alex Langford bee015efb5 [Utility] Remove Triple{Environment,OS,Vendor}IsUnspecifiedUnknown from ArchSpec
Summary:
These functions should always return the opposite of the
`Triple{Environment,OS,Vendor}WasSpecified` functions. Unspecified unknown is
the same as unspecified, which is why one set of functions should give us what
we want. It's possible to have specified unknown, which is why we can't just
rely on checking the enum values of vendor/os/environment. We must also ensure
that the names of these are empty and not "unknown".

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

llvm-svn: 354933
2019-02-26 23:50:19 +00:00
Jonas Devlieghere 936c62422f [Reproducers] Initialize reproducers before initializing the debugger.
As per the discussion on the mailing list:
http://lists.llvm.org/pipermail/lldb-commits/Week-of-Mon-20190218/048007.html

This commit implements option (3):

> Go back to initializing the reproducer before the rest of the debugger.
> The method wouldn't be instrumented and guarantee no other SB methods are
> called or SB objects are constructed. The initialization then becomes part
> of the replay.

Differential revision: https://reviews.llvm.org/D58410

llvm-svn: 354631
2019-02-21 22:26:16 +00:00
Pavel Labath 7f815a9a42 Have Stream::PutCStringAsRawHex8 take llvm::StringRef
This enables the function to be called with a StringRef without jumping
through any hoops. I rename the function to "PutStringAsRawHex8" to
honor the extended interface. I also remove ".c_str()" from any calls to
this function I could find.

llvm-svn: 353841
2019-02-12 14:28:55 +00:00
Pavel Labath 841bea933b Breakpad: auto-detect path style of file entries
Summary:
This adds support for auto-detection of path style to SymbolFileBreakpad
(similar to how r351328 did the same for DWARF). We guess each file
entry separately, as we have no idea which file came from which compile
units (and different compile units can have different path styles). The
breakpad generates should have already converted the paths to absolute
ones, so this guess should be reasonable accurate, but as always with
these kinds of things, it is hard to give guarantees about anything.

In an attempt to bring some unity to the path guessing logic, I move the
guessing logic from inside SymbolFileDWARF into the FileSpec class and
have both symbol files use it to implent their desired behavior.

Reviewers: clayborg, lemo, JDevlieghere

Subscribers: aprantl, markmentovai, lldb-commits

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

llvm-svn: 353702
2019-02-11 14:11:00 +00:00
Pavel Labath 76016ba1ca Fix some warnings introduced in r353324 (ReproducerInstrumentation patch)
GetIndexForObjectImpl generated a bunch of "conversion casts away
constness warnings". Change the function to use "const void *" (and
static_cast, while I'm at it), to avoid this.

Driver.cpp: unused variable "replay" (this was actually caused by a
subsequent partial revert of this patch). I just finish the revert by
removing the variable completely.

llvm-svn: 353405
2019-02-07 13:51:38 +00:00
Jonas Devlieghere 58947cf854 [Reproducers] SBReproducer framework: Capture & Replay
This is part two of the reproducer instrumentation framework. It
contains the code to capture and replay function calls. The main user of
this framework will be the SB API layer.

For all the details refer to the RFC on the mailing list:
http://lists.llvm.org/pipermail/lldb-dev/2019-January/014530.html

Differential revision: https://reviews.llvm.org/D56322

llvm-svn: 353324
2019-02-06 18:57:42 +00:00
Jan Kratochvil bb3609e49d Fix strlen() of unbound array undefined behavior
LLDB testsuite fails when built by GCC8 on:
  LLDB :: SymbolFile/DWARF/find-basic-namespace.cpp

This is because this code in LLDB codebase has undefined behavior:

  #include <algorithm>
  #include <string.h>
  // lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp:1731
  static struct section_64 {
    char sectname[16];
    char segname[16];
  } sect64 = { {'_','_','a','p','p','l','e','_','n','a','m','e','s','p','a','c'}, "__DWARF" };
  int main() {
    return std::min<size_t>(strlen(sect64.sectname), sizeof(sect64.sectname));
  }

It has been discussed as a (false) bugreport to GCC:
  wrong-code: LLDB testcase fails: SymbolFile/DWARF/find-basic-namespace.cpp
  https://bugzilla.redhat.com/show_bug.cgi?id=1672436

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

llvm-svn: 353280
2019-02-06 08:44:13 +00:00
Jonas Devlieghere 494fd8f84f [Reproducers] Instrumentation Framework: Serialization
This is the is serialization/deserialization part of the reproducer
instrumentation framework.

For all the details refer to the RFC on the mailing list:
http://lists.llvm.org/pipermail/lldb-dev/2019-January/014530.html

Differential revision: https://reviews.llvm.org/D57714

llvm-svn: 353195
2019-02-05 18:46:36 +00:00
Davide Italiano 042f770738 [Scalar] Remove partially wrong and unused functions.
I originally thought about fixing them, but hey, nobody is
using them anyway.

llvm-svn: 352643
2019-01-30 18:40:05 +00:00
Davide Italiano 92a470edce [Scalar] Hoist a duplicated (and sometimes wrong) comment.
Pointed out by Zachary and Adrian.

llvm-svn: 352641
2019-01-30 18:24:16 +00:00
Davide Italiano 51d46bd4d2 [Scalar] Implement support for 512-bit values.
(useful, e.g. when reading 512-bits registers, a-la AVX-512).

<rdar://problem/46886288>

llvm-svn: 352639
2019-01-30 18:05:36 +00:00
Jonas Devlieghere 46575176e9 [Reproducers] Add file provider
This patch adds the file provider which is responsible for capturing
files used by LLDB.

When capturing a reproducer, we use a file collector that is very
similar to the one used in clang. For every file that we touch, we add
an entry with a mapping from its virtual to its real path. When we
decide to generate a reproducer we copy over the files and their
permission into to reproducer folder.

When replaying a reproducer, we load the VFS mapping and instantiate a
RedirectingFileSystem. The latter will transparently use the files
available in the reproducer.

I've tested this on two macOS machines with an artificial example.
Still, it is very likely that I missed some places where we (still) use
native file system calls. I'm hoping to flesh those out while testing
with more advanced examples. However, I will fix those things in
separate patches.

Differential revision: https://reviews.llvm.org/D54617

llvm-svn: 352538
2019-01-29 20:36:38 +00:00
Jim Ingham f3ecbfc164 Add UUID::SetFromOptionalStringRef, use it in DynamicLoaderDarwin
We use UUID::fromOptionalData to read UUID's from the Mach-O files, so UUID's
of all 0's are invalid UUID's.
We also get uuid's from debugserver, which need to match the file UUID's.  So
we need an API that treats "000000000" as invalid as well.  Added that and use it.

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

llvm-svn: 352122
2019-01-24 22:43:44 +00:00
Chandler Carruth 2946cd7010 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

llvm-svn: 351636
2019-01-19 08:50:56 +00:00
Jonas Devlieghere e912cc512d [Reproducers] Refactor reproducer info
In the original reproducer design, I expected providers to be more
dynamic than they turned out. For example, we don't have any instances
where one provider has multiple files. Additionally, I expected there to
be less locality between capture and replay, with the provider being
defined in one place and the replay code to live in another. Both
contributed to the design of the provider info.

This patch refactors the reproducer info to be something static. This
means less magic strings and better type checking. The new design still
allows for the capture and replay code to live in different places as
long as they both have access to the new statically defined info class.

I didn't completely get rid of the index, because it is useful for (1)
sanity checking and (2) knowing what files are used by the reproducer.

Differential revision: https://reviews.llvm.org/D56814

llvm-svn: 351501
2019-01-18 01:04:59 +00:00
Pavel Labath 7d36d723ab DWARF: Add some support for non-native directory separators
Summary:
If we opened a file which was produced on system with different path
syntax, we would parse the paths from the debug info incorrectly.

The reason for that is that we would parse the paths as they were
native. For example this meant that on linux we would treat the entire
windows path as a single file name with no directory component, and then
we would concatenate that with the single directory component from the
DW_AT_comp_dir attribute. When parsing posix paths on windows, we would
at least get the directory separators right, but we still would treat
the posix paths as relative, and concatenate them where we shouldn't.

This patch attempts to remedy this by guessing the path syntax used in
each compile unit. (Unfortunately, there is no info in DWARF which would
give the definitive path style used by the produces, so guessing is all
we can do.) Currently, this guessing is based on the DW_AT_comp_dir
attribute of the compile unit, but this can be refined later if needed
(for example, the DW_AT_name of the compile unit may also contain some
useful info). This style is then used when parsing the line table of
that compile unit.

This patch is sufficient to make the line tables come out right, and
enable breakpoint setting by file name work correctly. Setting a
breakpoint by full path still has some kinks (specifically, using a
windows-style full path will not work on linux because the path will be
parsed as a linux path), but this will require larger changes in how
breakpoint setting works.

Reviewers: clayborg, zturner, JDevlieghere

Subscribers: aprantl, lldb-commits

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

llvm-svn: 351328
2019-01-16 12:30:41 +00:00
Jonas Devlieghere 9bbba276e9 Change std::sort to llvm::sort to detect non-determinism.
LLVM added wrappers to std::sort (r327219) that randomly shuffle the
container before sorting. The goal is to uncover non-determinism due to
undefined sorting order of objects having the same key.

This can be enabled with -DLLVM_ENABLE_EXPENSIVE_CHECKS=ON.

llvm-svn: 350679
2019-01-08 23:25:06 +00:00
Davide Italiano ff92a1a7cf [Scalar] Simplify comparison operators and add coverage.
llvm-svn: 350428
2019-01-04 19:23:52 +00:00
Davide Italiano db057e7792 [RegisterValue] Rewrite operator!= in terms of operator==. NFCI.
llvm-svn: 350149
2018-12-29 05:05:23 +00:00
Pavel Labath 4870fa9a40 Delete lldb_utility::Range
This class is unused, and there is already a lldb_private::Range
(defined in lldb/Core/RangeMap.h), which has similar functionality.

llvm-svn: 350088
2018-12-27 09:44:27 +00:00
Davide Italiano 18a0ce9813 [Scalar] Implement operator!= using operator==.
Summary: Adding some test coverage while I'm around.

Reviewers: JDevlieghere, aprantl, zturner, clayborg, jingham

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

llvm-svn: 349970
2018-12-21 22:42:00 +00:00
Jonas Devlieghere a6682a413d Simplify Boolean expressions
This patch simplifies boolean expressions acorss LLDB. It was generated
using clang-tidy with the following command:

run-clang-tidy.py -checks='-*,readability-simplify-boolean-expr' -format -fix $PWD

Differential revision: https://reviews.llvm.org/D55584

llvm-svn: 349215
2018-12-15 00:15:33 +00:00
Pavel Labath 181b823b04 Move Broadcaster+Listener+Event combo from Core into Utility
Summary:
These are general purpose "utility" classes, whose functionality is not
debugger-specific in any way. As such, I believe they belong in the
Utility module.

This doesn't break any particular dependency (yet), but it reduces the
number of Core dependencies across the board.

Reviewers: zturner, jingham, teemperor, clayborg

Subscribers: mgorny, lldb-commits

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

llvm-svn: 349157
2018-12-14 15:59:49 +00:00
Jonas Devlieghere 65e5e2781f [NFC] Small code cleanups in utility.
Fix a few small annoyances in Utility I ran into.

llvm-svn: 348996
2018-12-13 00:15:17 +00:00
Adrian Prantl 7b8a03751c Add a unit test for ArchSpec matching to document how it behaves (and test it).
llvm-svn: 348440
2018-12-06 00:43:55 +00:00
Jonas Devlieghere c2820bf23e [Reproducers] Only creaate the bottom-most dir
As Pavel noted on the mailing list we should only create the bottom-most
directory if it doesn't exist. This should also fix the test case on
Windows as we can use lit's temp directory.

llvm-svn: 348289
2018-12-04 18:16:49 +00:00
Jonas Devlieghere 15eacd741f [Reproducers] Change how reproducers are initialized.
This patch changes the way the reproducer is initialized. Rather than
making changes at run time we now do everything at initialization time.
To make this happen we had to introduce initializer options and their SB
variant. This allows us to tell the initializer that we're running in
reproducer capture/replay mode.

Because of this change we also had to alter our testing strategy. We
cannot reinitialize LLDB when using the dotest infrastructure. Instead
we use lit and invoke two instances of the driver.

Another consequence is that we can no longer enable capture or replay
through commands. This was bound to go away form the beginning, but I
had something in mind where you could enable/disable specific providers.
However this seems like it adds very little value right now so the
corresponding commands were removed.

Finally this change also means you now have to control this through the
driver, for which I replaced --reproducer with --capture and --replay to
differentiate between the two modes.

Differential revision: https://reviews.llvm.org/D55038

llvm-svn: 348152
2018-12-03 17:28:29 +00:00
Jonas Devlieghere 68ed93d252 [Reproducers] Improve reproducer API and add unit tests.
When I landed the initial reproducer framework I knew there were some
things that needed improvement. Rather than bundling it with a patch
that adds more functionality I split it off into this patch. I also
think the API is stable enough to add unit testing, which is included in
this patch as well.

Other improvements include:

 - Refactor how we initialize the loader and generator.
 - Improve naming consistency: capture and replay seems the least ambiguous.
 - Index providers by name and make sure there's only one of each.
 - Add convenience methods for creating and accessing providers.

Differential revision: https://reviews.llvm.org/D54616

llvm-svn: 347716
2018-11-27 22:11:02 +00:00
Tatyana Krasnukha 3f166e48d1 [CMake] Pass full libedit path to linker
Otherwise, linker fails with "cannot find -ledit" in case of custom libedit installation.

llvm-svn: 347693
2018-11-27 19:41:30 +00:00
Haojian Wu 01b098840f Fix the "make_unique is ambiguous" compiler error.
llvm-svn: 346839
2018-11-14 09:42:28 +00:00
Jonas Devlieghere 9e046f02e3 Add GDB remote packet reproducer.
llvm-svn: 346780
2018-11-13 19:18:16 +00:00
Jonas Devlieghere 87e403aa4f Re-land "Extract construction of DataBufferLLVM into FileSystem"
This fixes some UB in isLocal detected by the sanitized bot.

llvm-svn: 346707
2018-11-12 21:24:50 +00:00
Davide Italiano 9a89d93d62 Revert "Extract construction of DataBufferLLVM into FileSystem"
It broke the lldb sanitizer bots.

llvm-svn: 346694
2018-11-12 19:08:19 +00:00
Jonas Devlieghere ceff6644bb Remove header grouping comments.
This patch removes the comments grouping header includes. They were
added after running IWYU over the LLDB codebase. However they add little
value, are often outdates and burdensome to maintain.

llvm-svn: 346626
2018-11-11 23:17:06 +00:00
Jonas Devlieghere 672d2c1255 Remove comments after header includes.
This patch removes the comments following the header includes. They were
added after running IWYU over the LLDB codebase. However they add little
value, are often outdates and burdensome to maintain.

Differential revision: https://reviews.llvm.org/D54385

llvm-svn: 346625
2018-11-11 23:16:43 +00:00
Jonas Devlieghere 1cc0714c68 Extract construction of DataBufferLLVM into FileSystem
This moves construction of data buffers into the FileSystem class. Like
some of the previous refactorings we don't translate the path yet
because the functionality hasn't been landed in LLVM yet.

Differential revision: https://reviews.llvm.org/D54272

llvm-svn: 346598
2018-11-10 22:44:06 +00:00
Jonas Devlieghere 72787ac661 Revert "[FileSystem] Make use of FS in TildeExpressionResolver"
The whole point of this change was making it possible to resolve paths
without depending on the FileSystem, which is not what I did here. Not
sure what I was thinking...

llvm-svn: 346466
2018-11-09 01:59:28 +00:00
Jonas Devlieghere 9560f353ed [FileSystem] Make use of FS in TildeExpressionResolver
In order to call real_path from the TildeExpressionResolver we need
access to the FileSystem. Since the resolver lives under utility we have
to pass in the FS.

llvm-svn: 346457
2018-11-09 00:50:50 +00:00
Jonas Devlieghere 8f3be7a32b [FileSystem] Move path resolution logic out of FileSpec
This patch removes the logic for resolving paths out of FileSpec and
updates call sites to rely on the FileSystem class instead.

Differential revision: https://reviews.llvm.org/D53915

llvm-svn: 345890
2018-11-01 21:05:36 +00:00
Jonas Devlieghere dbd7fabaa0 [FileSystem] Remove Exists() from FileSpec
This patch removes the Exists method from FileSpec and updates its uses
with calls to the FileSystem.

Differential revision: https://reviews.llvm.org/D53845

llvm-svn: 345854
2018-11-01 17:09:25 +00:00