Commit Graph

575 Commits

Author SHA1 Message Date
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
Jonas Devlieghere b2a9cf7764 [Logging] Replace LogIfAnyCategoriesSet with LLDB_LOG.
This patch removes any remaining instances of LogIfAnyCategoriesSet and
replaces them with the LLDB_LOG macro. This in turn made it possible to
make Log::VAPrintf and Log::VAError private.

llvm-svn: 366768
2019-07-22 23:48:01 +00:00
Jonas Devlieghere abd1561f15 [LLDBAssert] Use unreachable instead of assert(0)
As per Davide's suggestion offline.

llvm-svn: 365250
2019-07-05 21:54:20 +00:00
Jonas Devlieghere b0fc4d470f lldb_assert: abort when assertions are enabled.
We had a long discussion in D59911 about lldb_assert and what it means.
The result was the assert manifesto on lldb.llvm.org.

> LLDB provides lldb_assert() as a soft alternative to cover the middle
> ground of situations that indicate a recoverable bug in LLDB. In a
> Debug configuration lldb_assert() behaves like assert(). In a Release
> configuration it will print a warning and encourage the user to file a
> bug report, similar to LLVM’s crash handler, and then return
> execution.

However, currently lldb_assert doesn't behave they way it's being
described there: it doesn't abort in a debug/assert build. This patch
fixes that by adding a call to assert() in lldb_assert().

Differential revision: https://reviews.llvm.org/D64267#1571962

llvm-svn: 365246
2019-07-05 21:22:54 +00:00
Jonas Devlieghere 27789ce049 [Reproducers] Copy over access/modification time in the FileCollector.
Copy over access and modification time for the files included in the
reproducer. This is needed to pass tests that check the integrity of
object files based on their time stamp.

llvm-svn: 364457
2019-06-26 18:14:31 +00:00
Pavel Labath 73a28f0643 Fix a dangling StringRef in FileCollector
FileSpec::GetPath returns a temporary std::string.

llvm-svn: 363770
2019-06-19 08:09:56 +00:00
Jonas Devlieghere c470ac50a8 [Reproducers] Make reproducer relocatable
Before this patch, reproducers weren't relocatable. The reproducer
contained hard coded paths in the VFS mapping, as well in the yaml file
listing the different input files for the command interpreter. This
patch changes that:

 - Use relative paths for the DataCollector.
 - Use an overlay prefix for the FileCollector.

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

llvm-svn: 363697
2019-06-18 16:20:17 +00:00
Jonas Devlieghere 2bf2568150 [Reproducers] Remove call to lldb_private::GetVersion()
Utility doesn't link against lldbBase so we cannot call GetVersion in
keep. I already added a string member m_version to deal with that, but
the call was still there.

llvm-svn: 363228
2019-06-13 05:14:25 +00:00
Jonas Devlieghere c2e2df7f7a [Reproducers] Include lldb version in the reproducer root
Generally, reproducers are rev-locked to the version of LLDB, so it's
valuable to have the LLDB version in the reproducer. For now I just want
the information to be present, without enforcing it, but I envision
emitting a warning during replay in the future.

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

llvm-svn: 363225
2019-06-13 04:35:22 +00:00
Jonas Devlieghere ef96e985fc [Reproducers] Simplify providers with nested Info struct (NFC)
This replaces the `info` typedef with a nested struct named Info. This
means we now have FooProvider and FooProvider::Info, instead of two
related but separate classes FooProvider and FooInfo. This change is
mostly cosmetic.

llvm-svn: 363211
2019-06-12 22:17:38 +00:00
Antonio Afonso 57e2da4f32 Create a generic handler for Xfer packets
Summary:
This is the first of a few patches I have to improve the performance of dynamic module loading on Android.

In this first diff I'll describe the context of my main motivation and will then link to it in the other diffs to avoid repeating myself.

## Motivation
I have a few scenarios where opening a specific feature on an Android app takes around 40s when lldb is attached to it. The reason for that is because 40 modules are dynamicly loaded at that point in time and each one of them is taking ~1s.

## The problem
To learn about new modules we have a breakpoint on a linker function that is called twice whenever a module is loaded. One time just before it's loaded (so lldb can check which modules are loaded) and another right after it's loaded (so lldb can check again which ones are loaded and calculate the diference).
It's figuring out which modules are loaded that is taking quite some time. This is currently done by traversing the linked list of loaded shared libraries that the linker maintains in memory. Each item in the linked list requires its own `x` packet sent to the gdb server (this is android so the network also plays a part). In my scenario there are 400+ loaded libraries and even though we read 0x800 worth of bytes at a time we still make ~180 requests that end up taking 150-200ms.
We also do this twice, once before the module is loaded (state = eAdd) and another right after (state = eConsistent) which easly adds up to ~400ms per module.

## A solution

**Implement `xfer:libraries-svr4` in lldb-server:**
I noticed in the code that loads the new modules that it had support for the `xfer:libraries-svr4` packet (added ~4 years ago to support the ds2 debug server) but we didn't support it in lldb-server. This single packet returns an xml list of all the loaded modules by the process. The advantage is that there's no more need to make 180 requests to read the linked list. Additionally this new requests takes around 10ms.

**More efficient usage of the `xfer:libraries-svr4` packet in lldb:**
When `xfer:libraries-svr4` is available the Process class has a `LoadModules` function that requests this packet and then loads or unloads modules based on the current list of loaded modules by the process.
This is the function that is used by the DYLDRendezvous class to get the list of loaded modules before and after the module is loaded. However, this is really not needed since the LoadModules function already loaded or unloaded the modules accordingly. I changed this strategy to call LoadModules only once (after the process has loaded the module).

**Bugs**
I found a few issues in lldb while implementing this and have submitted independent patches for them.

I tried to devide this into multiple logical patches to make it easier to review and discuss.

## Tests

I wanted to put these set of diffs up before having all the tests up and running to start having them reviewed from a techical point of view. I'm also having some trouble making the tests running on linux so I need more time to make that happen.

# This diff

The `xfer` packages follow the same protocol, they are requested with `xfer:<object>:<read|write>:<annex>:<offset,length>` and a return that starts with `l` or `m` depending if the offset and length covers the entire data or not. Before implementing the `xfer:libraries-svr4` I refactored the `xfer:auxv` to generically handle xfer packets so we can easly add new ones.

The overall structure of the function ends up being:
* Parse the packet into its components: object, offset etc.
* Depending on the object do its own logic to generate the data.
* Return the data based on its size, the requested offset and length.

Reviewers: clayborg, xiaobai, labath

Reviewed By: labath

Subscribers: mgorny, krytarowski, lldb-commits

Tags: #lldb

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

llvm-svn: 362982
2019-06-10 20:59:58 +00:00
Adrian McCarthy 4447d15aef Fix lit tests on Windows related to CR+LF
Problem discovered in the breakpoint lit test, but probably exists in others.
lldb-test splits lines on LF.  Input files that are CR+LF separated (as is
common on Windows) then resulted in commands being sent to LLDB that ended
in CR, which confused the command interpreter.

This could be fixed at different levels:

1.  Treat '\r' like a tab or space in the argument splitter.
2.  Fix the line splitters (plural) in lldb-test.
3.  Normalize the test files to LF only.

If we did only 3, I'd expect similar problems to recur, so this patch does
1 and 2.  I may also do 3 in a separate patch later, but that's tricky
because I believe we have some input files that MUST use CR+LF.

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

llvm-svn: 362844
2019-06-07 21:13:30 +00:00
Pavel Labath f04b3635c4 [lldb-server] Support 'g' packets
Differential Revision: https://reviews.llvm.org/D62221
Patch by Guilherme Andrade <guiandrade@google.com>.

llvm-svn: 362063
2019-05-30 07:25:22 +00:00
Richard Trieu c8f2efe065 Use correct format specifier to silence -Wformat warning.
llvm-svn: 362035
2019-05-29 21:25:15 +00:00
Antonio Afonso 78337420cd Add more information to the log timer dump
Summary:
The `log timer dump` is showing the time of the function itself minus any function that is called from this one that also happens to be timed. However, this is really not obvious and it also makes it hard to understand the time spent in total and also which children are actually taking the time.
To get a better reading of the timer dump I added the total, children (which I named child) and also the hit count. I used these timers to figure out a performance issue and only after adding this things were more clear to me.

It looks like this:
```
(lldb) log timer dump
35.447713617 sec (total: 35.449s; child: 0.001s; count: 1374) for void SymbolFileDWARF::Index()
29.717921481 sec (total: 29.718s; child: 0.000s; count: 8230500) for const lldb_private::ConstString &lldb_private::Mangled::GetDemangledName(lldb::LanguageType) const
21.049508865 sec (total: 24.683s; child: 3.633s; count: 1399) for void lldb_private::Symtab::InitNameIndexes()
...
```

Reviewers: clayborg, teemperor, labath, espindola, xiaobai

Reviewed By: labath, xiaobai

Subscribers: emaste, mgorny, arichardson, eraman, MaskRay, jdoerfert, labath, davide, teemperor, aprantl, erik.pilkington, jfb, abidh, lldb-commits

Tags: #lldb

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

llvm-svn: 361987
2019-05-29 16:31:32 +00:00
Jonas Devlieghere 0ee23c958b [Utility] Small improvements to the Broadcaster class (NFC)
I touched the Broadcaster class earlier today (r361544) and noticed a
few things that could be improved. This patch includes variety of small
fixes: use early returns, use LLDB_LOG macro, use doxygen comments and
finally format the class.

llvm-svn: 361597
2019-05-24 04:41:47 +00:00
Jonas Devlieghere 09ad8c8f73 Fix integer literals which are cast to bool
This change replaces built-in types that are implicitly converted to
booleans.

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

llvm-svn: 361580
2019-05-24 00:44:33 +00:00
Jorge Gorbe Moya 56d69ef8ca [lldb] Make sure RegularExpression constructors always initialize member variables
The copy constructor of RegularExpression doesn't initialize m_comp_err. This causes an use-of-initialized-value error when a RegularExpression is copied: the copy constructor calls Compile, which calls Free to free the existing regex if needed, which in turn reads m_comp_err to check if there's any regex to be freed.

This change calls the default constructor from the other constructors to make sure members are always initialized with sensible values. This also avoids duplicating init logic, like the RegularExpression(llvm:StringRef) constructor does, which is error prone.

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

llvm-svn: 361546
2019-05-23 20:11:17 +00:00
Jonas Devlieghere 266b65f840 [Utility] Avoid a few unnecessary copies (NFC)
Avoid unnecessary copies by either passing by const-reference or moving
the argument.

llvm-svn: 361544
2019-05-23 20:05:21 +00:00
Jonas Devlieghere 202dc1291e [Reproducer] Pass FileSpec by const-ref. (NFC)
Fix two functions where we were passing FileSpecs by value, while we
could pass by const reference.

llvm-svn: 361459
2019-05-23 05:45:49 +00:00
Jonas Devlieghere 24374aef1b [Utility] Modernize C-style cats
Replaces the remaining C-style casts with explicit casts in Utility. The
motivation is that they are (1) easier to spot and (2) don't have
multiple meanings.

llvm-svn: 361458
2019-05-23 05:12:11 +00:00
Gabor Marton 37e6bf106c Add AST logging
Summary:
Log the AST of the TU associated with LLDB's `expr` command, once a declaration
is completed

Reviewers: shafik

Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, lldb-commits

Tags: #lldb

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

llvm-svn: 361362
2019-05-22 09:10:19 +00:00
Fangrui Song 1d846e1a4d Delete unnecessary copy ctors
llvm-svn: 361358
2019-05-22 08:38:23 +00:00
Fangrui Song ddb93b637e Simplify ArchSpec::IsMIPS()
llvm-svn: 360865
2019-05-16 08:37:32 +00:00
Fangrui Song 71a44224e5 Delete unnecessary copy ctors/copy assignment operators
It's the simplest and gives the cleanest semantics.

llvm-svn: 360762
2019-05-15 11:23:54 +00:00
Fangrui Song b0e54cbcdf Fix file names in file headers. NFC
llvm-svn: 360554
2019-05-13 04:42:32 +00:00
Greg Clayton 5f8e88cd69 Fix bug in ArchSpec::MergeFrom
Previous ArchSpec tests didn't catch this bug since we never tested just the OS being out of date. Fixed the bug and covered this with a test that would catch this.

This was found when trying to load a core file where the core file was an ELF file with just the e_machine for architeture and where the ELF header had no OS set in the OSABI field of the e_ident. It wasn't merging the architecture with the target architecture correctly.

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

llvm-svn: 360292
2019-05-08 22:03:22 +00:00
Pavel Labath b07a799752 DWARFExpression: Fix implementation of DW_OP_pick
Summary:
The DWARF spec states that the DWARF stack arguments are numbered from
the top. Our implementation of DW_OP_pick was counting them from the
bottom.

This bug probably wasn't noticed because nobody (except my upcoming
postfix-to-DWARF converter) uses DW_OP_pick, but I've cross-checked with
gdb to confirm that counting from the top is the expected behavior.

This patch fixes the implementation to match the spec and gdb behavior
and adds a test.

Reviewers: jasonmolenda, clayborg

Subscribers: mgorny, aprantl, lldb-commits

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

llvm-svn: 359436
2019-04-29 10:55:22 +00:00
Jonas Devlieghere db41fe166a [Reproducers] Limit logging to calls that cross the API boundary.
We recently moved API logging into the instrumentation macros. This made
that logging is now consistent and abstracted behind a macro for every
API functions, independent of the reproducers. It also means we have a
lot more output. While this is a good thing, it also meant a lot more
noise in the log, from things that aren't always equally interesting,
such as the copy constructor for example.

To improve usability, we should increase the signal-to-noise ratio. I
propose to achieve this by only logging API functions that cross the API
boundary. This is a divergence of what we had before, where a select
number of functions were logged, irregardless of the API boundary, a
concept that was introduced for the reproducers. However, I believe this
is in line with the purpose of the API log.

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

llvm-svn: 359016
2019-04-23 17:44:40 +00:00
Jonas Devlieghere 32176baee7 [Reproducers] Fix lifetime issue
Deallocating the data recorder in during the ::Keep() operation causes
problems down the line when exiting the debugger. The command
interpreter still holds a pointer to the now deallocated object and has
no way to know it no longer exists. This is exactly what the m_record
flag was meant for, although it wasn't hooked up properly either.

llvm-svn: 358916
2019-04-22 20:05:02 +00:00
Raphael Isemann 12886f04ea Prevent unnecessary conversion from StringRef to C-string [NFC]
There is an alternative method to GetConstCStringWithLength that
takes a StringRef. GetConstCStringWithLength also calls this
method in the end, so directly calling the StringRef saves
us from a unnecessary conversion to a C-string.

llvm-svn: 358357
2019-04-14 14:01:49 +00:00
Jonas Devlieghere 8b3af63b89 [NFC] Remove ASCII lines from comments
A lot of comments in LLDB are surrounded by an ASCII line to delimit the
begging and end of the comment.

Its use is not really consistent across the code base, sometimes the
lines are longer, sometimes they are shorter and sometimes they are
omitted. Furthermore, it looks kind of weird with the 80 column limit,
where the comment actually extends past the line, but not by much.
Furthermore, when /// is used for Doxygen comments, it looks
particularly odd. And when // is used, it incorrectly gives the
impression that it's actually a Doxygen comment.

I assume these lines were added to improve distinguishing between
comments and code. However, given that todays editors and IDEs do a
great job at highlighting comments, I think it's worth to drop this for
the sake of consistency. The alternative is fixing all the
inconsistencies, which would create a lot more churn.

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

llvm-svn: 358135
2019-04-10 20:48:55 +00:00
Jonas Devlieghere 306809f292 [Reproducers] Capture return values of functions returning by ptr/ref
For some reason I had convinced myself that functions returning by
pointer or reference do not require recording their result. However,
after further considering I don't see how that could work, at least not
with the current implementation. Interestingly enough, the reproducer
instrumentation already (mostly) accounts for this, though the
lldb-instr tool did not.

This patch adds the missing macros and updates the lldb-instr tool.

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

llvm-svn: 357639
2019-04-03 21:31:22 +00:00
Jonas Devlieghere 4d63d8cf75 [CMake] Move link dependencies where they are used.
The utility library shouldn't depend on curses, libedit or python. Move
curses to core, libedit to host and python to the python plugin.

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

llvm-svn: 357287
2019-03-29 17:47:26 +00:00
Jonas Devlieghere ae1cc995e3 [Cmake] Unify python variables
FindPythonInterp and FindPythonLibs do two things, they set some
variables (PYTHON_LIBRARIES, PYTHON_INCLUDE_DIRS) and update the cached
variables (PYTHON_LIBRARY, PYTHON_INCLUDE_DIR) which are also used to
specify a custom python installation.

I believe the canonical way to do this is to use the PYTHON_LIBRARIES
and PYTHON_INCLUDE_DIRS variables instead of the cached ones. However,
since the cached variables are accessible from the cache and GUI, this
is a lot less confusing when you're trying to debug why a variable did
or didn't get the value you expected. Furthermore, as far as I can tell,
the implementation uses the cached variables to set their LIBRARIES/DIRS
counterparts. This is also the reason this works today even though we
mix-and-match.

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

llvm-svn: 357282
2019-03-29 17:35:42 +00:00
Adrian Prantl 515d1306ff Don't abort() in lldb_assert and document why.
rdar://problem/49356014

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

llvm-svn: 357268
2019-03-29 16:12:27 +00:00
Jonas Devlieghere f8819bd510 [Platform] Remove Kalimba Platform
This patch removes the Kalimba platform. For more information please
refer to the corresponding thread on the mailing list.

http://lists.llvm.org/pipermail/lldb-dev/2019-March/014921.html

llvm-svn: 357086
2019-03-27 16:23:50 +00:00
Jonas Devlieghere 7d3225c4b4 [Args] Handle backticks to prevent crash.
Currently LLDB crashes when autocompleting a command that ends with a
backtick because the quote character wasn't handled. This fixes that and
adds a unit test for this function.

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

llvm-svn: 356927
2019-03-25 17:27:14 +00:00
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
Jonas Devlieghere 2c22c800a0 [FileSystem] Remove ResolveExecutableLocation() from FileSpec
This patch removes the ResolveExecutableLocation method from FileSpec
and updates its uses with calls to the FileSystem.

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

llvm-svn: 345853
2018-11-01 17:09:22 +00:00
Jonas Devlieghere 7c5310bbd3 [FileSystem] Remove GetPermissions() and Readable() from FileSpec
This patch removes the GetPermissions and GetReadable methods from
FileSpec and updates its uses with calls to the FileSystem.

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

llvm-svn: 345843
2018-11-01 15:47:33 +00:00
Jonas Devlieghere 59b78bcba2 [FileSystem] Remove GetByteSize() from FileSpec
This patch removes the GetByteSize method from FileSpec and updates its
uses with calls to the FileSystem.

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

llvm-svn: 345812
2018-11-01 04:45:28 +00:00
Jonas Devlieghere 35e4c84c1f [FileSystem] Move EnumerateDirectory from FileSpec to FileSystem.
This patch moves the EnumerateDirectory functionality and related enum
and typedef from FileSpec to FileSystem.

This is part of a set of patches that extracts file system related
convenience methods from FileSpec. The long term goal is to remove this
method altogether and use the iterators directly, but for introducing
the VFS into LLDB this change is sufficient.

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

llvm-svn: 345800
2018-11-01 00:33:27 +00:00
Saleem Abdulrasool f66cb01b44 Utility: fix cross-compilation from Linux to Windows
Only attempt to link against Backtrace if it is found.  Without this,
trying to cross-compile to Windows would try to link against
"Backtrace_LIBRARY-NOTFOUND.lib".

llvm-svn: 345569
2018-10-30 06:29:28 +00:00
Adrian Prantl 51b58d6c13 Remove accidentally committed duplicate code
llvm-svn: 345287
2018-10-25 17:36:05 +00:00
Adrian Prantl 10deee997d Fix a bug PlatformDarwin::SDKSupportsModule.
This fixes a bug PlatformDarwin::SDKSupportsModule introduced by
https://reviews.llvm.org/D47889.  VersionTuple::tryParse() can deal
with an optional third (micro) component, but the parse will fail when
there are extra characters after the version number (e.g.: trying to
parse the substring "12.0.sdk" out of "iPhoneSimulator12.0.sdk" fails
after that patch).  Fixed here by stripping the ".sdk" suffix first.

(Part of) rdar://problem/45041492

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

llvm-svn: 345274
2018-10-25 15:30:43 +00:00
Aaron Smith c3d447fe26 [lldb] Add support in Status::AsCString to retrieve win32 system error strings
Reviewers: rnk, zturner, aleksandr.urakov

Subscribers: lldb-commits

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

llvm-svn: 344798
2018-10-19 18:58:24 +00:00
Jason Molenda 32762fd29d Upstreaming the BridgeOS device support and the
LC_BUILD_VERSION load command handling - this
commit is a combination of patches by Adrian
Prantl and myself.  llvm::Triple::BridgeOS 
isn't defined yet, so all references to that
are currently commented out.  

Also update Xcode project file to build the 
NativePDB etc plugins.

<rdar://problem/43353615> 

llvm-svn: 344209
2018-10-11 00:28:35 +00:00
Raphael Isemann 7f88829cea Add support for descriptions with command completions.
Summary:
This patch adds a framework for adding descriptions to the command completions we provide.
It also adds descriptions for completed top-level commands so that we can test this code.

Completions are in general supposed to be displayed alongside the completion itself. The descriptions
can be used to provide additional information about the completion to the user. Examples for descriptions
are function signatures when completing function calls in the expression command or the binary name
when providing completion for a symbol.

There is still some boilerplate code from the old completion API left in LLDB (mostly because the respective
APIs are reused for non-completion related purposes, so the CompletionRequest doesn't make sense to be
used), so that's why I still had to change some function signatures. Also, as the old API only passes around a
list of matches, and the descriptions are for these functions just another list, I had to add some code that
essentially just ensures that both lists are always the same side (e.g. all the manual calls to
`descriptions->AddString(X)` below a `matches->AddString(Y)` call).

The initial command descriptions that come with this patch are just reusing the existing
short help that is already added in LLDB.

An example completion with descriptions looks like this:
```
(lldb) pl
Available completions:
        platform -- Commands to manage and create platforms.
        plugin   -- Commands for managing LLDB plugins.
```

Reviewers: #lldb, jingham

Reviewed By: #lldb, jingham

Subscribers: jingham, JDevlieghere, lldb-commits

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

llvm-svn: 342181
2018-09-13 21:26:00 +00:00
Raphael Isemann cad7a46a23 Remove manual byte counting from internal Stream methods.
Summary:
This patch removes the manual byte counting in all internal Stream methods.
This is now done by the automatic byte counting provided by calling `GetWrittenBytes()`
before and after writing the data (which is automatically done for us by the `ByteDelta`
utility class).

Reviewers: #lldb, JDevlieghere

Reviewed By: JDevlieghere

Subscribers: JDevlieghere, labath, lldb-commits

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

llvm-svn: 342044
2018-09-12 10:20:41 +00:00
Davide Italiano f06ffeee21 [Scalar] Commit the correct patch, forgot `git add`.
<rdar://problem/44229924>

llvm-svn: 341685
2018-09-07 18:22:27 +00:00
Davide Italiano 5ccc9df843 [Scalar] Fix undefined behaviour when converting double to long.
This showed up in an Ubsan build of lldb (inside the CFAbsoluteTime
data formatter). As we only care about the bit pattern, we just
round to the nearest double, and truncate to a size that fits
in ulonglong_t.

<rdar://problem/44229924>

llvm-svn: 341682
2018-09-07 18:03:43 +00:00