Commit Graph

575 Commits

Author SHA1 Message Date
Jonas Devlieghere 12c185ac5e [lldb/Reproducers] Fix reproducer instrumentation formatting (NFC) 2020-01-29 21:38:30 -08:00
Jonas Devlieghere 056f01f895 [lldb/Reproducers] Assert when trying to get object for invalid index.
Assert when trying to get an object for an index we haven't seen before.
This will crash anyway, the assertion is just a bit more informative.
2020-01-29 21:34:54 -08:00
Jonas Devlieghere 446e4e4cf6 [lldb/Reproducers] Account for char** being a nullptr 2020-01-29 16:32:48 -08:00
Jonas Devlieghere 91aa67bf29 [lldb/Reproducers] Add (de)serialization overload for char**
This patch adds an overload to serialize and deserialize char** types.
This is necessary for things like the SBLaunchInfo ctor. We serialize
the array length followed by each individual item.
2020-01-29 14:08:21 -08:00
Jonas Devlieghere 33fa6727b7 [lldb/Reproducers] Add logging to the string template specialization
Only the templated function had logging for deserialization. The string
deserializer is implemented as a specialization and now prints to the
log as well.
2020-01-29 09:16:43 -08:00
Benjamin Kramer adcd026838 Make llvm::StringRef to std::string conversions explicit.
This is how it should've been and brings it more in line with
std::string_view. There should be no functional change here.

This is mostly mechanical from a custom clang-tidy check, with a lot of
manual fixups. It uncovers a lot of minor inefficiencies.

This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-28 23:25:25 +01:00
Raphael Isemann 808142876c [lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).

This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).

Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere

Reviewed By: JDevlieghere

Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 08:52:55 +01:00
Jonas Devlieghere c4144caf9b [lldb/Reproducer] Disable buffering of stdout during replay
Different buffering behavior during capture and replay caused some of
the shell tests to fail when run from a reproducer. By disabling stdout
buffering we get a better approximation of how things get flushed during
an regular debug session. There is a performance impact but since this
only affects replay this is acceptable.
2020-01-22 16:17:08 -08:00
Jonas Devlieghere 982a77b694 [lldb/Reproducers] Print more info for reproducer status
Reproducer status now prints the capture/replay path. It will also print
the status of auto generation when enabled.
2020-01-15 20:25:44 -08:00
Jonas Devlieghere 066e817b42 [lldb/Reproducers] Add a flag to always generating a reproducer
Add a flag which always generates a reproducer when normally it would be
discarded. This is meant for testing purposes to capture a debugger
session without modification the session itself.
2020-01-15 19:45:54 -08:00
Jonas Devlieghere b54a50f52e [lldb/Reproducers] Extract function for reading environment override (NFC)
Create a helper function for reading reproducer overrides from
environment variables.
2020-01-15 19:14:28 -08:00
Paolo Severini 4bafceced6 [LLDB] Add ObjectFileWasm plugin for WebAssembly debugging
Summary:
This is the first in a series of patches to enable LLDB debugging of
WebAssembly targets.

Current versions of Clang emit (partial) DWARF debug information in WebAssembly
modules and we can leverage this debug information to give LLDB the ability to
do source-level debugging of Wasm code that runs in a WebAssembly engine.

A way to do this could be to use the remote debugging functionalities provided
by LLDB via the GDB-remote protocol. Remote debugging can indeed be useful not
only to connect a debugger to a process running on a remote machine, but also to
connect the debugger to a managed VM or script engine that runs locally,
provided that the engine implements a GDB-remote stub that offers the ability to
access the engine runtime internal state.

To make this work, the GDB-remote protocol would need to be extended with a few
Wasm-specific custom query commands, used to access aspects of the Wasm engine
state (like the Wasm memory, Wasm local and global variables, and so on).
Furthermore, the DWARF format would need to be enriched with a few Wasm-specific
extensions, here detailed: https://yurydelendik.github.io/webassembly-dwarf.

This CL introduce classes **ObjectFileWasm**, a file plugin to represent a Wasm
module loaded in a debuggee process. It knows how to parse Wasm modules and
store the Code section and the DWARF-specific sections.

Reviewers: jasonmolenda, clayborg, labath

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D71575
2020-01-15 16:25:35 -08:00
Jonas Devlieghere fd19ffc6a5 [lldb/Utility] Use assert instead of llvm_unreachable for LLDBAssert
llvm_unreachable is marked noreturn so the compiler can assume the code
for printing the error message in release builds isn't hit which defeats
the purpose.
2020-01-14 09:14:28 -08:00
Jonas Devlieghere d1e3b23be4 [lldb/Utility] Add std::move to make placate clang 3.8
This fixes an error thrown by clang 3.8 that no viable conversion from
returned value to the function return type.
2020-01-13 18:25:23 -08:00
Raphael Isemann 65fdb34219 [lldb][NFC] Use static_cast instead of reinterpret_cast where possible
Summary: There are a few places in LLDB where we do a `reinterpret_cast` for conversions that we could also do with `static_cast`. This patch moves all this code to `static_cast`.

Reviewers: shafik, JDevlieghere, labath

Reviewed By: labath

Subscribers: arphaman, usaxena95, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D72161
2020-01-07 13:03:56 +01:00
Jonas Devlieghere d2b19d455d [lldb/Utility] YAML validation should be orthogonal to packet semantics.
It's not up to YAML to validate the semantics of the GDB remote packet
struct. This is especially wrong here as there's nothing that says that
the amount of bytes transmitted  matches the packet payload size.
2020-01-03 14:23:42 -08:00
Raphael Isemann ba6f25d7d3 [lldb][NFC] Make clang-format happy by removing trailing space in ArchSpec.cpp 2019-12-17 09:13:48 +01:00
Raphael Isemann 3ca771ba59 [lldb][NFC] Remove unused includes in Utility's source files 2019-12-13 12:33:47 +01:00
Eric Christopher 1d41d1bcdf Revert "Temporarily revert [lldb] e81268d - [lldb/Reproducers] Support multiple GDB remotes"
On multiple retry this issue won't duplicate - will revisit with author if
duplication works again.

This reverts commit c9e0b354e2.
2019-12-10 15:04:45 -08:00
Eric Christopher c9e0b354e2 Temporarily revert [lldb] e81268d - [lldb/Reproducers] Support multiple GDB remotes
This was causing a crash in opt+assert builds on linux and a follow-up
message was posted.

This reverts commit e81268d03e
2019-12-10 12:29:46 -08:00
Jonas Devlieghere e81268d03e [lldb/Reproducers] Support multiple GDB remotes
When running the test suite with always capture on, a handful of tests
are failing because they have multiple targets and therefore multiple
GDB remote connections. The current reproducer infrastructure is capable
of dealing with that.

This patch reworks the GDB remote provider to support multiple GDB
remote connections, similar to how the reproducers support shadowing
multiple command interpreter inputs. The provider now keeps a list of
packet recorders which deal with a single GDB remote connection. During
replay we rely on the order of creation to match the number of packets
to the GDB remote connection.

Differential revision: https://reviews.llvm.org/D71105
2019-12-10 11:16:52 -08:00
Raphael Isemann fc39b94849 [lldb][NFC] Move [SU]Int64ValueIsValidForByteSize to RegisterValue
These functions are an implementation detail of RegisterValue, so
it doesn't make a lot of sense to implement them in a totally
unrelated class.
2019-12-06 11:16:39 +01:00
Raphael Isemann b6e2cf3270 [lldb][NFC] Remove ability to pass a custom printf format to DataExtractor::PutToLog
This is luckily not used anywhere.
2019-12-06 10:27:45 +01:00
Raphael Isemann 777d1f7272 [lldb] Migrate VMRange::Dump to raw_ostream 2019-12-06 10:19:20 +01:00
Raphael Isemann 4dac97eb1e [lldb][NFC] Migrate FileSpec::Dump to raw_ostream 2019-12-06 09:40:42 +01:00
shafik fffd70291e [LLDB] Replacing use of ul suffix in GetMaxU64Bitfield since it not guarenteed to be 64 bit
GetMaxU64Bitfield(...) uses the ul suffix but we require a 64 bit unsigned integer and ul could be 32 bit. So this replacing it with a explicit cast and refactors the code around it to use an early exit.

Differential Revision: https://reviews.llvm.org/D70992
2019-12-05 10:03:53 -08:00
Raphael Isemann 1462f5a4c1 [lldb][NFC] Move Address and AddressRange functions out of Stream and let them take raw_ostream
Summary:
Yet another step on the long road towards getting rid of lldb's Stream class.

We probably should just make this some kind of member of Address/AddressRange, but it seems quite often we just push
in random integers in there and this is just about getting rid of Stream and not improving arbitrary APIs.

I had to rename another `DumpAddress` function in FormatEntity that is dumping the content of an address to make Clang happy.

Reviewers: labath

Reviewed By: labath

Subscribers: JDevlieghere, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D71052
2019-12-05 14:41:33 +01:00
Muhammad Omair Javaid 8b8185bb1b Avoid triple corruption while merging core info
Summary:
This patch fixes a bug where when target triple created from elf information
is arm-*-linux-eabihf and platform triple is armv8l-*-linux-gnueabihf. Merging
both triple results in armv8l--unknown-unknown.

This happens because we order a triple update while calling CoreUpdated and
CoreUpdated creates a new triple with no vendor or environment information.

Making sure we do not update triple and just update to more specific core
fixes the issue.

Reviewers: labath, jasonmolenda, clayborg

Reviewed By: jasonmolenda

Subscribers: jankratochvil, kristof.beyls, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D70155
2019-12-05 13:10:04 +05:00
Jonas Devlieghere dfe9a7943b [lldb/Reproducers] Override capture with LLDB_CAPTURE_REPRODUCER env var
Make it possible to override reproducer capture with the
LLDB_CAPTURE_REPRODUCER environment variable.

The goal of this change is twofold.

(1) I want to be able to enable capturing reproducers during regular
    test runs, both locally and on the bots. To do so I need a way to
    force capture. I cannot do this through the Python API, because
    reproducer capture must be enabled *before* the debugger
    initialized, which happens automatically when doing `import lldb`.

(2) I want to provide an escape hatch for when reproducers are enabled
    by default. Downstream we have reproducer capture enabled by default
    in the driver.

This patch solves both problems by overriding the reproducer mode based
on the environment variable. Acceptable values are 0/1 and ON/OFF.
2019-12-04 16:49:11 -08:00
Pavel Labath 150c8dd13b [lldb] Remove some (almost) unused Stream::operator<<'s
llvm::raw_ostream provides equivalent functionality.
2019-12-04 11:07:46 +01:00
Pavel Labath 28e4942b2c [lldb] Remove FileSpec(FileSpec*) constructor
This constructor was the cause of some pretty weird behavior. Remove it,
and update all code to properly dereference the argument instead.
2019-12-04 10:49:25 +01:00
Pavel Labath 532290e69f [lldb] s/FileSpec::Equal/FileSpec::Match
Summary:
The FileSpec class is often used as a sort of a pattern -- one specifies
a bare file name to search, and we check if in matches the full file
name of an existing module (for example).

These comparisons used FileSpec::Equal, which had some support for it
(via the full=false argument), but it was not a good fit for this job.

For one, it did a symmetric comparison, which makes sense for a function
called "equal", but not for typical searches (when searching for
"/foo/bar.so", we don't want to find a module whose name is just
"bar.so"). This resulted in patterns like:
    if (FileSpec::Equal(pattern, file, pattern.GetDirectory()))
which would request a "full" match only if the pattern really contained
a directory. This worked, but the intended behavior was very unobvious.

On top of that, a lot of the code wanted to handle the case of an
"empty" pattern, and treat it as matching everything. This resulted in
conditions like:
    if (pattern && !FileSpec::Equal(pattern, file, pattern.GetDirectory())
which are nearly impossible to decipher.

This patch introduces a FileSpec::Match function, which does exactly
what most of FileSpec::Equal callers want, an asymmetric match between a
"pattern" FileSpec and a an actual FileSpec. Empty paterns match
everything, filename-only patterns match only the filename component.

I've tried to update all callers of FileSpec::Equal to use a simpler
interface. Those that hardcoded full=true have been changed to use
operator==. Those passing full=pattern.GetDirectory() have been changed
to use FileSpec::Match.

There was also a handful of places which hardcoded full=false. I've
changed these to use FileSpec::Match too. This is a slight change in
semantics, but it does not look like that was ever intended, and it was
more likely a result of a misunderstanding of the "proper" way to use
FileSpec::Equal.

[In an ideal world a "FileSpec" and a "FileSpec pattern" would be two
different types, but given how widespread FileSpec is, it is unlikely
we'll get there in one go. This at least provides a good starting point
by centralizing all matching behavior.]

Reviewers: teemperor, JDevlieghere, jdoerfert

Subscribers: emaste, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D70851
2019-12-04 10:42:32 +01:00
Raphael Isemann 2f1e7b3d01 [lldb][NFC] Migrate to raw_ostream in ArchSpec::DumpTriple
Reviewers: labath, davide

Reviewed By: davide

Subscribers: clayborg, JDevlieghere, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D70979
2019-12-04 08:28:52 +01:00
Raphael Isemann 4f728bfc13 [lldb][NFC] Use raw_ostream instead of Stream in Baton::GetDescription
Removing raw_ostream here is getting us closer to removing LLDB's Stream
class.
2019-12-02 13:27:21 +01:00
Raphael Isemann f8fb3729e9 [lldb][NFC] Make Stream's IndentLevel an unsigned integers.
We expect it to be always positive values and LLVM/Clang's IndentLevel
values are already unsigned integers, so we should do the same.
2019-12-02 13:01:26 +01:00
Alexandre Ganea bdad3ec75a [LLDB] On Windows, force error message formatting to English
This fixes the Utility/StatusTest.ErrorWin32 unit test on non-English locales.

Differential Revision: https://reviews.llvm.org/D70442
2019-11-28 14:15:13 -05:00
Pavel Labath b18e190b7c [lldb] refactor FileSpec::Equal
The logic of this function was quite hard to follow. Replace it with a
much simpler, equivalent, implementation.
2019-11-28 14:33:25 +01:00
Martin Storsjö f5c54f4032 [LLDB] Always interpret arm instructions as thumb on windows
Windows on ARM always uses thumb mode, and doesn't have most of the
mechanisms that are used in e.g. ELF for distinguishing between arm
and thumb.

Differential Revision: https://reviews.llvm.org/D70796
2019-11-28 11:27:00 +02:00
Pavel Labath 957d9a0335 [lldb] remove unsigned Stream::operator<< overloads
Summary:
I recently re-discovered that the unsinged stream operators of the
lldb_private::Stream class have a surprising behavior in that they print
the number in hex. This is all the more confusing because the "signed"
versions of those operators behave normally.

Now that, thanks to Raphael, each Stream class has a llvm::raw_ostream
wrapper, I think we should delete most of our formatting capabilities
and just delegate to that. This patch tests the water by just deleting
the operators with the most surprising behavior.

Most of the code using these operators was printing user_id_t values. It
wasn't fully consistent about prefixing them with "0x", but I've tried
to consistenly print it without that prefix, to make it more obviously
different from pointer values.

Reviewers: teemperor, JDevlieghere, jdoerfert

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D70241
2019-11-26 14:24:28 +01:00
Davide Italiano 95c770fbfb [Utility] Remove a dead header [PPC64LE_ehframe_Registers.h] 2019-11-14 15:29:47 -08:00
Jonas Devlieghere 8ac053eea2 [LLDB] Cleanup the DataEncoder utility. (NFC)
This commit removes unused methods from the DataEncoder class and cleans
up the API by making all the internal methods private.
2019-11-13 15:44:51 -08:00
Jonas Devlieghere 7ba28644a1 [Reproducer] Discard reproducer directory if not generated.
If lldb was run in capture mode, but no reproducer was generated, make
sure we clean up the reproducer directory.
2019-11-12 20:16:33 -08:00
Muhammad Omair Javaid 9b95835698 [LLDB] Add core definition for armv8l and armv7l
This patch adds core definitions in lldb ArchSpecs for armv8l and armv7l cores.

This was needed because on Linux running on 32-bit Arm v8 we are returned
armv8l in case we are running 32-bit sysroot on 64bit kernel. In case of 32-bit
kernel and 32-bit sysroot running on arm v8 hardware we are returned armv7l.
This is quite common when we run 32 bit arm using docker container.

Signed-off-by: Muhammad Omair Javaid <omair.javaid@linaro.org>

Differential Revision: https://reviews.llvm.org/D69904
2019-11-13 05:40:09 +05:00
Pavel Labath a14eb8f47d lldb: Fix some -Wdeprecated-copy warnings
gcc-9 started warning when a class defined a copy constructor without a
copy assignment operator (or vice-versa).

This fixes those warnings by deleting the other special member too
(after verifying it doesn't do anything non-trivial).
2019-11-11 17:55:49 +01:00
Tatyana Krasnukha faf6b2543e [ARC] Basic support in gdb-remote process plugin
Differential Revision: https://reviews.llvm.org/D55718

llvm-svn: 375122
2019-10-17 15:16:21 +00:00
Raphael Isemann 755420c085 Revert "make ConstString allocate memory in non-tiny chunks"
As discussed in https://reviews.llvm.org/D68549, the actual issue
here seems to be that the BumpPtrAllocator is growing far too slow
because of the 256 different StringPools used as the backend for ConstString.
At the same time the original patch made ConstString allocate memory in
256MiB slabs for the same reason, meaning that the RSS usage of LLDB increased
by a few hundred MiB for all users without bringing any noticeable speedup
for most of them.

llvm-svn: 375062
2019-10-17 00:02:32 +00:00
Jonas Devlieghere 27ef81cd48 [Reproducer] Capture the debugger's working directory
This patch extends the reproducer to capture the debugger's current
working directory. This information will be used later to set the
current working directory of the VFS.

llvm-svn: 375059
2019-10-17 00:01:53 +00:00
Jason Molenda 7dd7a36075 Add arm64_32 support to lldb, an ILP32 codegen
that runs on arm64 ISA targets, specifically 
Apple watches.


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

llvm-svn: 375032
2019-10-16 19:14:49 +00:00
Walter Erquinigo 48a50ee034 [android/process list] support showing process arguments
Summary:
The qfProcessInfo and qsProcessInfo packets currently don't set the processes' arguments, however the platform process list -v command tries to print it.
In this diff I'm adding the arguments as part of the packet, and now the command shows the arguments just like on mac.

On Mac:

507    1      wallace    1876110778 wallace    1876110778 x86_64-apple-macosx      /usr/libexec/secd
503    1      wallace    1876110778 wallace    1876110778 x86_64-apple-macosx      /usr/libexec/secinitd
501    1      wallace    1876110778 wallace    1876110778 x86_64-apple-macosx      /usr/libexec/languageassetd --firstLogin
497    1      wallace    1876110778 wallace    1876110778 x86_64-apple-macosx      /usr/libexec/trustd --agent
496    1      wallace    1876110778 wallace    1876110778 x86_64-apple-macosx      /usr/libexec/lsd
494    1      wallace    1876110778 wallace    1876110778 x86_64-apple-macosx      /System/Library/Frameworks/CoreTelephony.framework/Support/CommCenter -L
491    1      wallace    1876110778 wallace    1876110778 x86_64-apple-macosx      /usr/sbin/distnoted agent
489    1      wallace    1876110778 wallace    1876110778 x86_64-apple-macosx      /usr/libexec/UserEventAgent (Aqua)
484    1      wallace    1876110778 wallace    1876110778 x86_64-apple-macosx      /usr/sbin/cfprefsd agent
483    1      wallace    1876110778 wallace    1876110778 x86_64-apple-macosx      /System/Library/Frameworks/LocalAuthentication.framework/Support/coreauthd
On android:

1561   1016   root       0                     0          aarch64-unknown-linux-android  /system/bin/ip6tables-restore--noflush -w -v
1805   982    1000       1000                  1000                                      android:drmService
1811   982    10189      10189                 10189                                     com.qualcomm.embms:remote
1999   1      1000       1000                  1000       aarch64-unknown-linux-android  /system/bin/tlc_serverCCM
2332   982    10038      10038                 10038                                     com.android.systemui
2378   983    1053       1053                  1053                                      webview_zygote
2448   982    5013       5013                  5013                                      com.sec.location.nsflp2
2465   982    10027      10027                 10027                                     com.google.android.gms.persistent

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

llvm-svn: 375029
2019-10-16 18:47:05 +00:00
Lubos Lunak e2ca7cb504 make ConstString allocate memory in non-tiny chunks
BumpPtrAllocator allocates in 4KiB chunks, which with any larger
project is going to result in a large number of allocations.
Increasing allocation size this way can save 10%-20% of symbol
load time for a huge C++ project with correctly built debuginfo.

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

llvm-svn: 374583
2019-10-11 19:34:39 +00:00
Pavel Labath a8b18baa0f ProcessInstanceInfoMatch: Don't match processes with no name if a name match was requested, take 2
Summary:
The previous attempt at making nameless process not match when searching for a
given name failed because the macos implementation was depending on this detail
in its partial matching strategy. Doing partial matching to avoid expensive
lookups is a perfectly valid thing to do, the way it was implemented seems
somewhat unexpected.

This patch implements it differently by providing special
methods in the ProcessInstanceInfoMatch which match only a subset of fields,
and changes mac host code to use those instead.

Then, it re-applies r373925 to get make the ProcessInstanceInfoMatch with a
name *not* match a nameless process.

Reviewers: JDevlieghere, teemperor, jingham

Subscribers: wallace, lldb-commits

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

llvm-svn: 374529
2019-10-11 10:56:54 +00:00
Raphael Isemann 067bb1f546 [lldb] Fix out of bounds read in DataExtractor::GetCStr and add unit test that function.
Summary:
The `if (*cstr_end == '\0')` in the previous code checked if the previous loop terminated because it
found a null terminator or because it reached the end of the data. However, in the case that we hit
the end of the data before finding a null terminator, `cstr_end` points behind the last byte in our
data and `*cstr_end` reads the memory behind the array (which may be uninitialised)

This patch just rewrites that function use `std::find` and adds the relevant unit tests.

Reviewers: labath

Reviewed By: labath

Subscribers: abidh, JDevlieghere, lldb-commits

Tags: #lldb

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

llvm-svn: 374311
2019-10-10 11:15:38 +00:00
Jonas Devlieghere e21399b02e Revert "ProcessInstanceInfoMatch: Don't match processes with no name if a name match was requested"
This breaks TestProcessAttach and TestHelloWorld on Darwin.

llvm-svn: 374008
2019-10-08 01:16:59 +00:00
Pavel Labath f7bd5bffed ProcessInstanceInfoMatch: Don't match processes with no name if a name match was requested
Since D68289, a couple of tests on linux started being extremely flaky.
All of them were doing name-based attaching and were failing because
they couldn't find an unambiguous process to attach to.

The patch above changed the process finding logic, so that failure to
find a process name does not constitute an error. This meant that a lot
more transient processes showed up in the process list during the test
suite run. Previously, these processes would not appear as they would be
gone by the time we went to read their executable name, arguments, etc.

Now, this alone should not cause an issue were it not for the fact that
we were considering a process with no name as if it matched by default
(even if we were explicitly searching for a process with a specified
name). This meant that any of the "transient" processes with no name
would make the name match ambiguous. That clearly seems like a bug to me
so I fix that.

llvm-svn: 373925
2019-10-07 17:17:53 +00:00
Walter Erquinigo e0a398bf31 [process list] make the TRIPLE column wider
Summary:
Now that `process list` works better on the android platform, the arch aarch64-unknown-linux-android appears quite often.
The existing printed width of the TRIPLE column is not long enough, which doesn't look okay.
E.g.
```
1561   1016                    aarch64-unknown-linux-android ip6tables-restore
1999   1                       aarch64-unknown-linux-android tlc_server
2332   982                                              com.android.systemui
2378   983                                              webview_zygote
```

Now, after adding 6 spaces, it looks better

```
PID    PARENT USER       TRIPLE                         NAME
====== ====== ========== ============================== ============================
...
1561   1016              aarch64-unknown-linux-android  ip6tables-restore
1999   1                 aarch64-unknown-linux-android  tlc_server
2332   982                                              com.android.systemui
2378   983                                              webview_zygote
2448   982                                              com.sec.location.nsflp2
```

Reviewers: clayborg, labath, xiaobai, aadsm

Reviewed By: labath

Subscribers: srhines, kristof.beyls, lldb-commits

Tags: #lldb

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

llvm-svn: 373670
2019-10-03 21:57:01 +00:00
Jonas Devlieghere 2a0c8b1143 [JSON] Remove Utility/JSON.{h|cpp}
This patch is the final step in my quest to get rid of the JSON parser
in LLDB. Vedant's coverage report [1] shows that it was mostly untested.
Furthermore, the LLVM implementation has a much nicer API and using it
means one less thing to maintain for LLDB.

[1] http://lab.llvm.org:8080/coverage/coverage-reports/index.html

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

llvm-svn: 373501
2019-10-02 18:02:36 +00:00
Jonas Devlieghere 57b468820f [JSON] Use LLVM's library for decoding JSON in StructuredData
This patch replaces the hand-rolled JSON decoding in StructuredData with
LLVM's JSON library.

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

llvm-svn: 373360
2019-10-01 17:41:52 +00:00
Jonas Devlieghere 2783d81791 [JSON] Use LLVM's library for encoding JSON in StructuredData
This patch replaces the hand-rolled JSON emission in StructuredData with
LLVM's JSON library.

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

llvm-svn: 373359
2019-10-01 17:41:48 +00:00
Jonas Devlieghere cdec597905 [Reproducer] Always use absolute paths for capture & replay.
The VFS requires files to be have absolute paths. The file collector
makes paths relative to the reproducer root. If the root is a relative
path, this would trigger an assert in the VFS. This patch ensures that
we always make the given path absolute.

Thank you Ted Woodward for pointing this out!

llvm-svn: 373102
2019-09-27 17:30:40 +00:00
Raphael Isemann 1e31558621 [lldb][NFC] Use AppendEmptyArgument in CompletionRequest constructor
We now have a utility function for this purpose.

(Also fixing the typo in the related comment while I'm at it.)

llvm-svn: 372946
2019-09-26 07:06:05 +00:00
Martin Storsjo 544c8f48c8 [LLDB] Add tests for PECOFF arm architecture identification
Add a test case for the change from SVN r372657, and for the
preexisting ARM identification.

Add a missing ArchDefinitionEntry for PECOFF/arm64, and tweak
the ArmNt case to set the architecture to armv7 (ArmNt never ran
on anything lower than that). (This avoids a case where
ArchSpec::MergeFrom would override the arch from arm to armv7 and
ArchSpec::CoreUpdated would reset the OS to unknown at the same time.)

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

llvm-svn: 372741
2019-09-24 12:20:52 +00:00
Raphael Isemann 8126340b3f [lldb] Fix log output and UtilityTests/LogChannelTest.List
I refactored this code in 372691 and it seems I didn't fully
replicate the original log output, so that test was failing.

llvm-svn: 372696
2019-09-24 08:20:05 +00:00
Raphael Isemann ef06dd4328 [lldb] Remove redundant argument lists in CompletionRequest
We currently have two lists in the CompletionRequest that we
inherited from the old API: The complete list of arguments ignoring
where the user requested completion and the list of arguments that
stops at the cursor. Having two lists of arguments is confusing
and can lead to subtle errors, so let's remove the complete list
until we actually need it.

llvm-svn: 372692
2019-09-24 07:22:44 +00:00
Raphael Isemann 6ba63d8851 [lldb] Add completion support for log enable/disable/list
Reviewers: #lldb, JDevlieghere

Reviewed By: JDevlieghere

Subscribers: JDevlieghere, lldb-commits

Tags: #lldb

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

llvm-svn: 372691
2019-09-24 07:18:09 +00:00
Martin Storsjo 8b98f12a7a [LLDB] Check for _WIN32 instead of _MSC_VER for code specific to windows in general
These ifdefs contain code that isn't specific to MSVC but useful for
any windows target, like MinGW.

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

llvm-svn: 372592
2019-09-23 12:03:56 +00:00
Martin Storsjo 799d61f269 [LLDB] Remove a stray semicolon. NFC.
This fixes build warnings with at least GCC.

llvm-svn: 372588
2019-09-23 12:03:14 +00:00
Raphael Isemann 14f6465c15 [lldb] Make cursor index in CompletionRequest unsigned
The fact that index==-1 means "no arguments" is not obvious and only
used in one place from what I can tell. Also fixes several warnings
about using the cursor index as if it was a size_t when comparing.

Not fully NFC as we now also correctly update the partial argument list
when injecting the fake empty argument in the CompletionRequest
constructor.

llvm-svn: 372566
2019-09-23 09:46:17 +00:00
Raphael Isemann 93ca36d756 [lldb][NFC] Remove argument prefix checking boilerplate when adding completions
llvm-svn: 372561
2019-09-23 08:59:21 +00:00
Jonas Devlieghere 4e053ff1d1 [NFC] Move dumping into GDBRemotePacket
This moves the dumping logic from the GDBRemoteCommunicationHistory
class into the GDBRemotePacket so that it can be reused from the
reproducer command object.

llvm-svn: 372028
2019-09-16 20:02:57 +00:00
Jonas Devlieghere ff5225bfb6 [Reproducer] Move GDB Remote Packet into Utility. (NFC)
To support dumping the reproducer's GDB remote packets, we need the
(de)serialization logic to live in Utility rather than the GDB remote
plugin. This patch renames StreamGDBRemote to GDBRemote and moves the
relevant packet code there.

Its uses in the GDBRemoteCommunicationHistory and the
GDBRemoteCommunicationReplayServer are updated as well.

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

llvm-svn: 371907
2019-09-13 23:14:10 +00:00
Raphael Isemann 0d9a201e26 [lldb][NFC] Remove ArgEntry::ref member
The StringRef should always be identical to the C string, so we
might as well just create the StringRef from the C-string. This
might be slightly slower until we implement the storage of ArgEntry
with a string instead of a std::unique_ptr<char[]>. Until then we
have to do the additional strlen on the C string to construct the
StringRef.

llvm-svn: 371842
2019-09-13 11:26:48 +00:00
Raphael Isemann 1f644bb163 [lldb][NFC] Simplify Args::ReplaceArgumentAtIndex
This code is not on any performance critical path that would
justify this shortening optimization. It also makes it possible
to turn 'ref' into a function (as this is the only place where
we modify this ArgEntry member).

llvm-svn: 371836
2019-09-13 10:41:29 +00:00
Jonas Devlieghere decff073ee [NFC] Sort source files in Utility/CMakeLists.txt
llvm-svn: 371784
2019-09-12 22:34:59 +00:00
Jonas Devlieghere 4a491ec491 [Reproducer] Move the command loader into the reproducer (NFC)
This just moves the CommandLoader utility into the reproducer namespace
and makes it accessible outside the API layer. This is setting things up
for a bigger change.

llvm-svn: 371689
2019-09-11 23:27:12 +00:00
Jonas Devlieghere bcc24e46ba [Reproducer] Move GDB Remote Provider into Reproducer (NFC)
Originally the idea was for providers to be defined close to where they
are used. While this helped designing the providers in such a way that
they don't depend on each other, it also means that it's not possible to
access them from a central place. This proved to be a problem for some
providers and resulted in them living in the reproducer class.

The ProcessGDBRemote provider is the last remaining exception. This
patch makes things consistent and moves it into the reproducer like the
other providers.

llvm-svn: 371685
2019-09-11 23:15:12 +00:00
Adrian Prantl 9b23df63ec Implement DW_OP_convert
This patch adds basic support for DW_OP_convert[1] for integer
types. Recent versions of LLVM's optimizer may insert this opcode into
DWARF expressions. DW_OP_convert is effectively a type cast operation
that takes a reference to a base type DIE (or zero) and then casts the
value at the top of the DWARF stack to that type. Internally this
works by changing the bit size of the APInt that is used as backing
storage for LLDB's DWARF stack.

I managed to write a unit test for this by implementing a mock YAML
object file / module that takes debug info sections in yaml2obj
format.

[1] Typed DWARF stack. http://www.dwarfstd.org/ShowIssue.php?issue=140425.1

<rdar://problem/48167864>

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

llvm-svn: 371532
2019-09-10 16:17:38 +00:00
Raphael Isemann 7841e80e79 [lldb][NFC] Remove Args::StripSpaces
This just reimplemented llvm::StringRef::[r/l]trim().

llvm-svn: 371181
2019-09-06 08:40:31 +00:00
Raphael Isemann dd8e73ffc0 [lldb][NFC] Remove unused Args::GetArgumentQuoteCharAtIndex
llvm-svn: 371176
2019-09-06 07:54:47 +00:00
Pavel Labath 602f29fd7c ProcessInstanceInfo: Fix dumping of invalid user ids
Don't attempt to print invalid user ids. Previously, these would come
out as UINT32_MAX, or as an assertion failure.

llvm-svn: 369906
2019-08-26 13:03:21 +00:00
Raphael Isemann 72ca5f3694 [lldb][NFC] Add ProcessInfo::GetNameAsStringRef to simplify some code
llvm-svn: 369880
2019-08-26 08:22:52 +00:00
Raphael Isemann ae34ed2c0d [lldb][NFC] Remove WordComplete mode, make result array indexed from 0 and remove any undocumented/redundant return values
Summary:
We still have some leftovers of the old completion API in the internals of
LLDB that haven't been replaced by the new CompletionRequest. These leftovers
are:

* The return values (int/size_t) in all completion functions.
* Our result array that starts indexing at 1.
* `WordComplete` mode.

I didn't replace them back then because it's tricky to figure out what exactly they
are used for and the completion code is relatively untested. I finally got around
to writing more tests for the API and understanding the semantics, so I think it's
a good time to get rid of them.

A few words why those things should be removed/replaced:

* The return values are really cryptic, partly redundant and rarely documented.
  They are also completely ignored by Xcode, so whatever information they contain will end up
  breaking Xcode's completion mechanism. They are also partly impossible to even implement
  as we assign negative values special meaning and our completion API sometimes returns size_t.

  Completion functions are supposed to return -2 to rewrite the current line. We seem to use this
  in some untested code path to expand the history repeat character to the full command, but
  I haven't figured out why that doesn't work at the moment.
  Completion functions return -1 to 'insert the completion character', but that isn't implemented
  (even though we seem to activate this feature in LLDB sometimes).
  All positive values have to match the number of results. This is obviously just redundant information
  as the user can just look at the result list to get that information (which is what Xcode does).

* The result array that starts indexing at 1 is obviously unexpected. The first element of the array is
  reserved for the common prefix of all completions (e.g. "foobar" and "footar" -> "foo"). The idea is
  that we calculate this to make the life of the API caller easier, but obviously forcing people to have
  1-based indices is not helpful (or even worse, forces them to manually copy the results to make it
  0-based like Xcode has to do).

* The `WordComplete` mode indicates that LLDB should enter a space behind the completion. The
  idea is that we let the top-level API know that we just provided a full completion. Interestingly we
  `WordComplete` is just a single bool that somehow represents all N completions. And we always
  provide full completions in LLDB, so in theory it should always be true.
  The only use it currently serves is providing redundant information about whether we have a single
  definitive completion or not (which we already know from the number of results we get).

This patch essentially removes `WordComplete` mode and makes the result array indexed from 0.
It also removes all return values from all internal completion functions. The only non-redundant information
they contain is about rewriting the current line (which is broken), so that functionality was moved
to the CompletionRequest API. So you can now do `addCompletion("blub", "description", CompletionMode::RewriteLine)`
to do the same.

For the SB API we emulate the old behaviour by making the array indexed from 1 again with the common
prefix at index 0. I didn't keep the special negative return codes as we either never sent them before (e.g. -2) or we
didn't even implement them in the Editline handler (e.g. -1).

I tried to keep this patch minimal and I'm aware we can probably now even further simplify a bunch of related code,
but I would prefer doing this in follow-up NFC commits

Reviewers: JDevlieghere

Reviewed By: JDevlieghere

Subscribers: arphaman, abidh, lldb-commits

Tags: #lldb

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

llvm-svn: 369624
2019-08-22 07:41:23 +00:00
Jonas Devlieghere 7483005c59 [NFC] Remove unused function GetHexWithFixedSize
The implementation of this function was obviously incorrect, as the
result variable was never used. This led me to check if it was actually
used anywhere, which came back negative.

llvm-svn: 369492
2019-08-21 04:55:53 +00:00
Jonas Devlieghere 4b3c0fd5da [NFC] Remove lldb_utility namespace.
While generating the Doxygen I noticed this lone namespace that has one
class and one function in it. This moves them into lldb_private.

llvm-svn: 369485
2019-08-21 00:50:46 +00:00
Jan Kratochvil 1c56d3df19 [lldb] Use the new Regex::isValid() with no parameter
Differential Revision: https://reviews.llvm.org/D66463

llvm-svn: 369398
2019-08-20 16:08:27 +00:00
Jan Kratochvil f9d90bc5f6 [lldb] D66174 `RegularExpression` cleanup
I find as a good cleanup to drop the Compile method. As I do not find TIMTOWTDI
as an advantage and there is already constructor parameter to compile the
regex.

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

llvm-svn: 369352
2019-08-20 09:24:20 +00:00
Raphael Isemann b8639f5c0f [lldb][NFC] Remove StringList::AutoComplete
We don't need this very specific function in StringList that
we only call once in LLDB.

llvm-svn: 369242
2019-08-19 08:15:46 +00:00
Raphael Isemann 21599876be [lldb][NFC] Address review comments to StringList for-loop support
llvm-svn: 369237
2019-08-19 07:22:19 +00:00
Jonas Devlieghere 3af3f1e8e2 [Utility] Reimplement RegularExpression on top of llvm::Regex
Originally I wanted to remove the RegularExpression class in Utility and
replace it with llvm::Regex. However, during that transition I noticed
that there are several places where need the regular expression string.
So instead I propose to keep the RegularExpression class and make it a
thin wrapper around llvm::Regex.

This patch also removes the workaround for empty regular expressions.
The result is that we are now (more or less) POSIX conformant.

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

llvm-svn: 369153
2019-08-16 21:25:36 +00:00
Raphael Isemann 4c78b78825 [lldb][NFC] Allow for-ranges on StringList
llvm-svn: 369113
2019-08-16 14:27:35 +00:00
Jonas Devlieghere 706cd70569 Fix variable mismatch between signature and body
I updated the signature to conform to the LLDB coding style but
accidentally forgot to update the function body.

llvm-svn: 368962
2019-08-15 05:09:09 +00:00
Jonas Devlieghere a7d4cec437 [NFC] Fix documentation for some utility classes.
This fixes a few warnings emitted when compiling with -Wdocumentation.

llvm-svn: 368959
2019-08-15 04:35:46 +00:00
Jonas Devlieghere a8f3ae7c9c [LLDB] Migrate llvm::make_unique to std::make_unique
Now that we've moved to C++14, we no longer need the llvm::make_unique
implementation from STLExtras.h. This patch is a mechanical replacement
of (hopefully) all the llvm::make_unique instances across the monorepo.

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

llvm-svn: 368933
2019-08-14 22:19:23 +00:00
Raphael Isemann 19351b24ca [lldb][NFC] Assert on invalid cursors positions when creating CompletionRequest
Before we just triggered undefined behavior on invalid positions.

llvm-svn: 368444
2019-08-09 14:32:50 +00:00
Jonas Devlieghere b78c8a0a35 [Utility] Remove unused function 'GetMatchSpanningIndices'
llvm-svn: 368243
2019-08-08 01:44:03 +00:00
Jonas Devlieghere 78dfc945b0 Remove unused function 'SetMangledCounterparts' (NFC)
This function is not referenced.

llvm-svn: 367975
2019-08-06 04:01:58 +00:00
Fangrui Song d9b948b6eb Rename F_{None,Text,Append} to OF_{None,Text,Append}. NFC
F_{None,Text,Append} are kept for compatibility since r334221.

llvm-svn: 367800
2019-08-05 05:43:48 +00:00
Jonas Devlieghere b22860da61 [CompletionRequest] Remove unimplemented members.
Completion requests have two fields that are essentially unimplemented:
`m_match_start_point` and `m_max_return_elements`. This would've been
okay, if it wasn't for the fact that this caused a bunch of useless
parameters to be passed around. Occasionally there would be a comment or
assert saying that they are not supported. This patch removes them.

llvm-svn: 367385
2019-07-31 03:48:29 +00:00
Jonas Devlieghere 175f093090 [StringList] Change LongestCommonPrefix API
When investigating a completion bug I got confused by the API.
LongestCommonPrefix finds the longest common prefix of the strings in
the string list. Instead of returning that string through an output
argument, just return it by value.

llvm-svn: 367384
2019-07-31 03:26:10 +00:00
Alex Lorenz 86814bf658 [Support] move FileCollector from LLDB to llvm/Support
The file collector class is useful for creating reproducers,
not just for LLDB, but for other tools as well in LLVM/Clang.

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

llvm-svn: 366956
2019-07-24 22:59:20 +00:00
Jonas Devlieghere 63e5fb76ec [Logging] Replace Log::Printf with LLDB_LOG macro (NFC)
This patch replaces explicit calls to log::Printf with the new LLDB_LOGF
macro. The macro is similar to LLDB_LOG but supports printf-style format
strings, instead of formatv-style format strings.

So instead of writing:

  if (log)
    log->Printf("%s\n", str);

You'd write:

  LLDB_LOG(log, "%s\n", str);

This change was done mechanically with the command below. I replaced the
spurious if-checks with vim, since I know how to do multi-line
replacements with it.

  find . -type f -name '*.cpp' -exec \
  sed -i '' -E 's/log->Printf\(/LLDB_LOGF\(log, /g' "{}" +

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

llvm-svn: 366936
2019-07-24 17:56:10 +00:00