Commit Graph

396 Commits

Author SHA1 Message Date
Raphael Isemann 3914833099 Added unit tests for Flags
Reviewers: labath

Reviewed By: labath

Subscribers: labath, mgorny, lldb-commits

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

llvm-svn: 337475
2018-07-19 17:45:51 +00:00
Pavel Labath a274452924 ELF: Replace the header-extension unit test with a lit one
The new test checks that we are actually able to read data from these
kinds of elf headers correctly instead of just that we read the section
number correctly. It is also easier to figure out what's going on in the
test.

llvm-svn: 337459
2018-07-19 14:38:30 +00:00
Raphael Isemann 2d42579886 Fix some crashes and deadlocks in FormatAnsiTerminalCodes
Summary:
This patch fixes a few problems with the FormatAnsiTerminalCodes function:

* It does an infinite loop on an unknown color value.
* It crashes when the color value is at the end of the string.
* It deletes the first character behind the color token.

Also added a few tests that reproduce those problems (and test some other corner cases).

Reviewers: davide, labath

Reviewed By: labath

Subscribers: labath, lldb-commits, mgorny

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

llvm-svn: 337189
2018-07-16 16:38:30 +00:00
Raphael Isemann a2e76c0bfc Replaced more boilerplate code with CompletionRequest (NFC)
Summary:
As suggested in D48796, this patch replaces even more internal calls that were using the old
completion API style with a single CompletionRequest. In some cases we also pass an option
vector/index, but as we don't always have this information, it currently is not part of the
CompletionRequest class.

The constructor of the CompletionRequest is now also more sensible. You only pass the
user input, cursor position and your list of matches to the request and the rest will be
inferred (using the same code we used before to calculate this). You also have to pass these
match window parameters to it, even though they are unused right now.

The patch shouldn't change any behavior.

Reviewers: jingham

Reviewed By: jingham

Subscribers: lldb-commits

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

llvm-svn: 337031
2018-07-13 18:28:14 +00:00
Leonard Mosescu 2ae3ec3b81 Restructure the minidump loading path and add early & explicit consistency checks
Corrupted minidumps was leading to unpredictable behavior.

This change adds explicit consistency checks for the minidump early on. The
checks are not comprehensive but they should catch obvious structural violations:

streams with type == 0
duplicate streams (same type)
overlapping streams
truncated minidumps

Another early check is to make sure we actually support the minidump architecture
instead of crashing at a random place deep inside LLDB.

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

llvm-svn: 336918
2018-07-12 17:27:18 +00:00
Eric Christopher b860318198 Remove the unused m_signal member variable, but leave the code that gets it out of the json.
llvm-svn: 336885
2018-07-12 03:52:46 +00:00
Raphael Isemann 3a0e12700b Refactor parsing of option lists with a raw string suffix.
Summary:
A subset of the LLDB commands follows this command line interface style:
   <command name> [arguments] -- <string suffix>
The parsing code for this interface has been so far been duplicated into the different
command objects which makes it hard to maintain and reuse elsewhere.

This patches improves the situation by adding a OptionsWithRaw class that centralizes
the parsing logic and allows easier testing. The different commands now just call this class to
extract the arguments and the raw suffix from the provided user input.

Reviewers: jingham

Reviewed By: jingham

Subscribers: mgorny, lldb-commits

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

llvm-svn: 336723
2018-07-10 20:17:38 +00:00
Raphael Isemann 2443bbd4aa Refactoring for for the internal command line completion API (NFC)
Summary:
This patch refactors the internal completion API. It now takes (as far as possible) a single
CompletionRequest object instead o half a dozen in/out/in-out parameters. The CompletionRequest
contains a common superset of the different parameters as far as it makes sense. This includes
the raw command line string and raw cursor position, which should make the `expr` command
possible to implement (at least without hacks that reconstruct the command line from the args).

This patch is not intended to change the observable behavior of lldb in any way. It's also as
minimal as possible and doesn't attempt to fix all the problems the API has.

Some Q&A:

Q: Why is this not fixing all the problems in the completion API?
A: Because is a blocker for the expr command completion which I want to get in ASAP. This is the
smallest patch that unblocks the expr completion patch and which allows trivial refactoring in the future.
The patch also doesn't really change the internal information flow in the API, so that hopefully
saves us from ever having to revert and resubmit this humongous patch.

Q: Can we merge all the copy-pasted code in the completion methods
(like computing the current incomplete arg) into CompletionRequest class?
A: Yes, but it's out of scope for this patch.

Q: Why the `word_complete = request.GetWordComplete(); ... ` pattern?
A: I don't want to add a getter that returns a reference to the internal integer. So we have
to use a temporary variable and the Getter/Setter instead. We don't throw exceptions
from what I can tell, so the behavior doesn't change.

Q: Why are we not owning the list of matches?
A: Because that's how the previous API works. But that should be fixed too (in another patch).

Q: Can we make the constructor simpler and compute some of the values from the plain command?
A: I think this works, but I rather want to have this in a follow up commit. Especially when making nested
request it's a bit awkward that the parsed arguments behave as both input/output (as we should in theory
propagate the changes on the nested request back to the parent request if we don't want to change the
behavior too much).

Q: Can't we pass one const request object and then just return another result object instead of mixing
them together in one in/out parameter?
A: It's hard to get keep the same behavior with that pattern, but I think we can also get a nice API with just
a single request object. If we make all input parameters read-only, we have a clear separation between what
is actually an input and what an output parameter (and hopefully we get rid of the in-out parameters).

Q: Can we throw out the 'match' variables that are not implemented according to the comment?
A: We currently just forward them as in the old code to the different methods, even though I think
they are really not used. We can easily remove and readd them once every single completion method just
takes a CompletionRequest, but for now I prefer NFC behavior from the perspective of the API user.

Reviewers: davide, jingham, labath

Reviewed By: jingham

Subscribers: mgorny, friss, lldb-commits

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

llvm-svn: 336146
2018-07-02 21:29:56 +00:00
Pavel Labath 77c397f465 UUID: Add support for arbitrary-sized module IDs
Summary:
The data structure is optimized for the case where the UUID size is <=
20 bytes (standard length emitted by the GNU linkers), but larger sizes
are also possible.

I've modified the string conversion function to support the new sizes as
well. For standard UUIDs it maintains the traditional formatting
(4-2-2-2-6). If a UUID is shorter, we just cut this sequence short, and
for longer UUIDs it will just repeat the last 6-byte block as long as
necessary.

I've also modified ObjectFileELF to take advantage of the new UUIDs and
avoid manually padding the UUID to 16 bytes. While there, I also made
sure the computed UUID does not depend on host endianness.

Reviewers: clayborg, lemo, sas, davide, espindola

Subscribers: emaste, arichardson, lldb-commits

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

llvm-svn: 335963
2018-06-29 11:20:29 +00:00
Pavel Labath e17e9579eb Modernize completion tests
Now that we have gmock, we can use its matchers to better express the
test assertions. The main advantage of this is that when things fail,
the test will now print the expected and actual lists of completed
strings instead of just a not-very-helpful "false is not true" message.

llvm-svn: 335955
2018-06-29 09:06:42 +00:00
Raphael Isemann 517c22041e Fix path completion test case added in rL335905 on Windows
Summary:
The test fails because we don't rewrite the slash behind `foo` to the OS specific
separator (as the completion API doesn't support this kind of rewriting). However,
we assume that this part of the string is rewritten in the test case, which broke
on Windows.

Reviewers: stella.stamenova

Reviewed By: stella.stamenova

Subscribers: lldb-commits

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

llvm-svn: 335934
2018-06-28 22:40:10 +00:00
Raphael Isemann 2476374c61 Added test case for: r334978 - Fixed file completion for paths that start with '~'
Reviewers: labath

Reviewed By: labath

Subscribers: lldb-commits

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

llvm-svn: 335905
2018-06-28 19:34:49 +00:00
Pavel Labath 2f93fd1f50 Represent invalid UUIDs as UUIDs with length zero
Summary:
During the previous attempt to generalize the UUID class, it was
suggested that we represent invalid UUIDs as length zero (previously, we
used an all-zero UUID for that). This meant that some valid build-ids
could not be represented (it's possible however unlikely that a checksum of
some file would be zero) and complicated adding support for variable
length build-ids (should a 16-byte empty UUID compare equal to a 20-byte
empty UUID?).

This patch resolves these issues by introducing a canonical
representation for an invalid UUID. The slight complication here is that
some clients (MachO) actually use the all-zero notation to mean "no UUID
has been set". To keep this use case working (while making it very
explicit about which construction semantices are wanted), replaced the
UUID constructors and the SetBytes functions with named factory methods.
- "fromData" creates a UUID from the given data, and it treats all bytes
  equally.
- "fromOptionalData" first checks the data contents - if all bytes are
  zero, it treats this as an invalid/empty UUID.

Reviewers: clayborg, sas, lemo, davide, espindola

Subscribers: emaste, lldb-commits, arichardson

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

llvm-svn: 335612
2018-06-26 15:12:20 +00:00
Pavel Labath a174bcbf03 Remove UUID::SetFromCString
Replace uses with SetFromStringRef. NFC.

llvm-svn: 335246
2018-06-21 15:24:39 +00:00
Pavel Labath 470b286ee5 Modernize UUID class
Instead of a separate GetBytes + GetByteSize methods I introduce a
single GetBytes method returning an ArrayRef.

This is NFC cleanup now, but it should make handling arbitrarily-sized
UUIDs cleaner, should we choose to go that way. I also took the
opportunity to add some unit tests for this class.

llvm-svn: 335244
2018-06-21 15:07:43 +00:00
Pavel Labath 61547259de Scalar: Use llvm integer conversion functions
StringConvert was the only non-Utility dependency of this class. Getting
rid of it means it will be easy to move this class to a lower layer.

While I was in there, I also added a couple of unit tests for the Scalar
string conversion function.

llvm-svn: 335060
2018-06-19 17:24:03 +00:00
Pavel Labath 60f028ff03 Replace HostInfo::GetLLDBPath with specific functions
Summary:
Instead of a function taking an enum value determining which path to
return, we now have a suite of functions, each returning a single path
kind. This makes it easy to move the python-path function into a
specific plugin in a follow-up commit.

All the users of GetLLDBPath were converted to call specific functions
instead. Most of them were hard-coding the enum value anyway, so this
conversion was simple. The only exception was SBHostOS, which I've
changed to use a switch on the incoming enum value.

Reviewers: clayborg, zturner

Subscribers: lldb-commits

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

llvm-svn: 335052
2018-06-19 15:09:07 +00:00
Pavel Labath 2272c4811f Use llvm::VersionTuple instead of manual version marshalling
Summary:
This has multiple advantages:
- we need only one function argument/instance variable instead of three
- no need to default initialize variables
- no custom parsing code
- VersionTuple has comparison operators, which makes version comparisons much
  simpler

Reviewers: zturner, friss, clayborg, jingham

Subscribers: emaste, lldb-commits

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

llvm-svn: 334950
2018-06-18 15:02:23 +00:00
Pavel Labath 2e6384038c Fix PathMappingListTest on windows
r334615 changed the the value of FileSpec.IsRelative("/") for windows
path syntax. We previously considered it absolute but now it is
considered relative (I guess because it's interpretation depends on the
current drive).

This cause a failure in PathMappingList test, which assumed that "/"
will not get remapped as it is an absolute path. As this is no longer
true on windows, I replace "/" with a really absolute path.

llvm-svn: 334702
2018-06-14 10:31:06 +00:00
Jonas Devlieghere 87fb24dd4b [FileSpec] Make style argument mandatory for SetFile. NFC
Update SetFile uses in the unittests.

llvm-svn: 334668
2018-06-13 22:54:52 +00:00
Jonas Devlieghere ad8d48f903 [FileSpec] Delegate common operations to llvm::sys::path
With the recent changes in FileSpec to use LLVM's path style, it is
possible to delegate a bunch of common path operations to LLVM's path
helpers. This means we only have to maintain a single implementation and
at the same time can benefit from the efforts made by the rest of the
LLVM community.

This is part one of a set of patches. There was no obvious way to split
this so I just worked from top to bottom.

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

llvm-svn: 334615
2018-06-13 16:23:21 +00:00
Zachary Turner 08426e1f9f Refactor ExecuteAndWait to take StringRefs.
This simplifies some code which had StringRefs to begin with, and
makes other code more complicated which had const char* to begin
with.

In the end, I think this makes for a more idiomatic and platform
agnostic API.  Not all platforms launch process with null terminated
c-string arrays for the environment pointer and argv, but the api
was designed that way because it allowed easy pass-through for
posix-based platforms.  There's a little additional overhead now
since on posix based platforms we'll be takign StringRefs which
were constructed from null terminated strings and then copying
them to null terminate them again, but from a readability and
usability standpoint of the API user, I think this API signature
is strictly better.

llvm-svn: 334518
2018-06-12 17:43:52 +00:00
David Carlier 58d05a4d5f [LLDB] Unit tests / typo fix
removing unnecessary comma.

llvm-svn: 334177
2018-06-07 08:58:34 +00:00
Pavel Labath 5583ec4218 Revert "PDB support of function-level linking and splitted functions"
This reverts commit r334030 because it adds a broken test.

llvm-svn: 334076
2018-06-06 09:16:00 +00:00
Aaron Smith a642f8f343 PDB support of function-level linking and splitted functions
Summary:
The patch adds support of splitted functions (when MSVC is used with PGO) and function-level linking feature.

SymbolFilePDB::ParseCompileUnitLineTable function relies on fact that ranges of compiled source files in the binary are continuous and don't intersect each other. The function creates LineSequence for each file and inserts it into LineTable, and implementation of last one relies on continuity of the sequence. But it's not always true when function-level linking enabled, e.g. in added input test file test-pdb-function-level-linking.exe there is xstring's std__basic_string_char_std__char_traits_char__std__allocator_char_____max_size (.00454820) between test-pdb-function-level-linking.cpp's foo (.00454770) and main (.004548F0).

To fix the problem this patch renews the sequence on each address gap.

Reviewers: asmith, zturner

Reviewed By: asmith

Subscribers: mgorny, lldb-commits

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

llvm-svn: 334030
2018-06-05 17:19:21 +00:00
Pavel Labath 4e34bfcbeb Really fix ClangParserTest
It turns out the test needs a fixture after all (to initialize HostInfo), so
provide one that does that.

llvm-svn: 334003
2018-06-05 10:29:48 +00:00
Pavel Labath 8d1421d317 Fix ClangParserTest.cpp
The test does not use a test fixture, so it needs to be declared with
the TEST macro.

llvm-svn: 333992
2018-06-05 09:33:26 +00:00
Jonas Devlieghere a54df26ace Fix Expression unittests on Darwin
Fixes the Expression unittests on Darwin after r333933 was landed.

llvm-svn: 333974
2018-06-05 00:32:41 +00:00
Zachary Turner bdf089246e Remove dependency from Host to clang.
Host depended on clang because HostInfo had a function to get
the directory where clang was installed.  We move this over to
the clang expression parser plugin where it's more at home.

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

llvm-svn: 333933
2018-06-04 17:41:00 +00:00
Jonas Devlieghere df8e291ef9 [FileSpec] Re-implmenet removeLastPathComponent
When reading DBGSourcePathRemapping from a dSYM, we remove the last two
path components to make the source lookup more general. However, when
dealing with a relative path that has less than 2 components, we ended
up with an invalid (empty) FileSpec.

This patch changes the behavior of removeLastPathComponent to remove the
last path component, if possible. It does this by checking whether a
parent path exists, and if so using that as the new path. We rely
entirely on LLVM's path implementation to do the heavy lifting.

We now also return a boolean which indicates whether the operator was
successful or not.

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

rdar://37791687

llvm-svn: 333540
2018-05-30 13:03:16 +00:00
Adrian Prantl b90f1dfe00 HostInfoMacOSX: Support finding the clang resource directory within CLTools.
rdar://problem/40537961

llvm-svn: 333248
2018-05-25 00:29:01 +00:00
James Y Knight 1a05affa80 Remove spurious dependency on Process/elf-core from Process/Utility.
These checks do absolutely nothing other than cause a library layering
violation in the code.

llvm-svn: 333134
2018-05-23 22:04:20 +00:00
Pavel Labath fe547e0447 Fix PathMappingList tests on windows
The tests added in r332842 don't work on windows, because they do path
comparisons on strings, and on windows, the paths coming out of the
mappings had backslashes in them.

This switches comparisons to FileSpecs, so the results come out right.

llvm-svn: 333074
2018-05-23 10:32:05 +00:00
James Y Knight 8fc06c7ab7 Avoid using header from Host/macosx when not testing an apple build.
llvm-svn: 333032
2018-05-22 21:49:41 +00:00
Greg Clayton 86188d8a40 Fix PathMappingList for relative and empty paths after recent FileSpec normalization changes
PathMappingList was broken for relative and empty paths after normalization changes in FileSpec. There were also no tests for PathMappingList so I added those.

Changes include:

Change PathMappingList::ReverseRemapPath() to take FileSpec objects instead of ConstString. The only client of this was doing work to convert to and from ConstString objects for no reason.
Normalize all paths prefix and replacements that are added to the PathMappingList vector so they match the paths that have been already normalized in the debug info
Unify code in the two forms of PathMappingList::RemapPath() so only one contains the actual functionality. Prior to this, there were two versions of this code.
Use FileSpec::AppendPathComponent() and remove a long standing TODO so paths are correctly appended to each other.
Added tests for absolute, relative and empty paths.

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

llvm-svn: 332842
2018-05-21 14:14:36 +00:00
Greg Clayton 6dcea6d28f Fix buildbots after it 332618
llvm-svn: 332633
2018-05-17 17:18:11 +00:00
Greg Clayton 39d50b72ea FileSpec objects that resolve to "." should have "." in m_filename and m_directory empty.
After switching to LLVM normalization, if we init FileSpec with "." we would end up with m_directory being NULL and m_filename being "".

This patch fixes this by allowing the path to be normalized and if it normalized to nothing, set it to m_filename.

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

llvm-svn: 332618
2018-05-17 16:12:38 +00:00
Greg Clayton a8da1f8ee4 Revert 332511 after reverting llvm revision 332508.
llvm-svn: 332556
2018-05-16 23:32:45 +00:00
Greg Clayton 4de94930c3 Fix FileSpecTest after LLVM changes to remove_dots (https://reviews.llvm.org/D46887)
llvm-svn: 332511
2018-05-16 18:37:00 +00:00
Pavel Labath 245dd2e0c7 Reapply "Remove Process references from the Host module"
This re-lands r332250/D46395, after fixing Mac build errors.

llvm-svn: 332353
2018-05-15 13:42:26 +00:00
Stella Stamenova ad9b697898 [lit] Fix several tests that fail when using Python 3 or on Windows
Summary:
1) In logtest.cpp, the name of the file that is reported is not always capitalized, so split the comparison to validate the file (case insensitive) and function (case sensitive) separately
2) Update the gdb remote client tests to work with Python 3. In Python 3, socket sends/receives data as bytes rather than byte strings. This also updates the usage of .hex() - this is no longer available in Python 3, so use hexlify instead

Reviewers: asmith, labath, zturner

Reviewed By: labath

Subscribers: llvm-commits

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

llvm-svn: 332293
2018-05-14 21:04:24 +00:00
Pavel Labath 4f107ba20e Revert "Remove Process references from the Host module"
The first fix wasn't enough, there is still a missing
ProcessInstanceInfo include in Host.mm. I won't be able to test a fix
before leaving work, so I am reverting both commits.

This reverts commit r332250 and the subsequent fix attempt.

llvm-svn: 332261
2018-05-14 16:54:53 +00:00
Pavel Labath 58b54894c7 Remove Process references from the Host module
The Process class was only being referenced because of the last-ditch
effort in the process launchers to set a process death callback in case
one isn't set already.

Although launching a process for debugging is the most important kind of
"launch" we are doing, it is by far not the only one, so assuming this
particular callback is the one to be used is not a good idea (besides
breaking layering). Instead of assuming a particular exit callback, I
change the launcher code to require the callback to be set by the user (and fix
up the two call sites which did not set the callback already).

Reviewers: jingham, davide

Subscribers: lldb-commits

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

llvm-svn: 332250
2018-05-14 15:13:13 +00:00
Pavel Labath 2cb7cf8e87 FileSpec: Remove PathSyntax enum and use llvm version instead
Summary:
The llvm version of the enum has the same enumerators, with stlightly
different names, so this is mostly just a search&replace exercise. One
concrete benefit of this is that we can remove the function for
converting between the two enums.

To avoid typing llvm::sys::path::Style::windows everywhere I import the
enum into the FileSpec class, so it can be referenced as
FileSpec::Style::windows.

Reviewers: zturner, clayborg

Subscribers: lldb-commits

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

llvm-svn: 332247
2018-05-14 14:52:47 +00:00
Adrian Prantl 66a0b77493 Conditionally compile a Darwin-only test.
llvm-svn: 332140
2018-05-11 21:05:32 +00:00
Adrian Prantl 3a380fb2ff Yet another follow-up to r332111. This also handles the case where an
LLDB.framework is built inside the LLDB build directory (but not
inside an Xcode installation).

llvm-svn: 332126
2018-05-11 19:29:25 +00:00
Adrian Prantl 5103e48bad Fix a regression in r332111. The LLDB.framework path component is not
usually the last component.

llvm-svn: 332120
2018-05-11 19:00:58 +00:00
Adrian Prantl 7d46f0e4c2 HostInfoMacOSX: Share the clang resource directory with Swift.
Inside Xcode and in Xcode toolchains LLDB is always in lockstep
with the Swift compiler, so it can reuse its Clang resource
directory. This allows LLDB and the Swift compiler to share the
same Clang module cache.

rdar://problem/40039633

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

llvm-svn: 332111
2018-05-11 17:54:09 +00:00
Pavel Labath e7306b105e Remove custom path manipulation functions from FileSpec
Summary:
now that llvm supports host-agnostic path manipulation functions (and
most of their kinks have been ironed out), we can remove our copies of
the path parsing functions in favour of the llvm ones.

This should be NFC except for the slight difference in handling of the
"//" path, which is now normalized to "/" (this only applies to the
literal "//" path; "//net" and friends still get to keep the two
slashes).

Reviewers: zturner, clayborg

Subscribers: lldb-commits

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

llvm-svn: 332088
2018-05-11 11:55:34 +00:00
Pavel Labath 4865ff1e18 CPlusPlusLanguage: Add unit tests for the FindAlternateFunctionManglings method
I was considering modifying this function, so I wrote some tests to make
sure I don't regress its behavior. I am not sure if I will actually
proceed with the modifications, but the tests seem useful nonetheless.

llvm-svn: 331966
2018-05-10 08:59:17 +00:00