Commit Graph

1084 Commits

Author SHA1 Message Date
Pavel Labath c9e6b7010c [lldb/Host] Modernize some socket functions
return Expected<Socket> instead of a Status object plus a Socket*&
argument.
2020-04-23 14:20:26 +02:00
Muhammad Omair Javaid 478619cf9a Revert "get rid of PythonInteger::GetInteger()"
This reverts commit 7375212172.

This causes multiple test failures on LLDB AArch64 Linux buildbot.
http://lab.llvm.org:8011/builders/lldb-aarch64-ubuntu/builds/3695

Differential Revision: https://reviews.llvm.org/D78462
2020-04-23 04:38:32 +05:00
Jonas Devlieghere e57361c055 [lldb/Host] Remove TaskPool and replace its uses with llvm::ThreadPool
Remove LLDB's TaskPool and replace its uses with LLVM's ThreadPool.

Differential revision: https://reviews.llvm.org/D78337
2020-04-22 09:17:49 -07:00
Lawrence D'Anna 7375212172 get rid of PythonInteger::GetInteger()
Summary:
One small step in my long running quest to improve python exception handling in
LLDB.  Replace GetInteger() which just returns an int with As<long long> and
friends, which return Expected types that can track python exceptions

Reviewers: labath, jasonmolenda, JDevlieghere, vadimcn

Reviewed By: labath

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D78462
2020-04-21 16:55:51 -07:00
Jonas Devlieghere e687aa8282 [lldb/Reproducers] Fix passive replay for (char*, size_t) functions.
Several SB API functions return strings using (char*, size_t) output
arguments. During capture, we serialize an empty string for the char*
because the memory can be uninitialized.

During active replay, we have custom replay redirects that ensure that
we don't override the buffer from which we're reading, but rather write
to a buffer on the heap with the given length. This is sufficient for
the active reproducer use case, where we only care about the side
effects of the API calls, not the values actually returned.

This approach does not not work for passive replay because here we
ignore all the incoming arguments, and re-execute the current function
with the arguments deserialized from the reproducer. This means that
these function will update the deserialized copy of the arguments,
rather than whatever was passed in by the SWIG wrapper.

To solve this problem, this patch extends the reproducer instrumentation
to handle this special case for passive replay. We nog ignore the
replayer in the registry and the incoming char pointer, and instead
reinvoke the current method on the deserialized class, and populate the
output argument.

Differential revision: https://reviews.llvm.org/D77759
2020-04-20 13:26:11 -07:00
Jonas Devlieghere e128d53895 [lldb/Test] Don't friend std::make_unique
This wasn't a great idea to begin with, as you can't really rely on the
implementation, but since it also doesn't work with MSVC I've just made
the ctors public.
2020-04-20 11:48:52 -07:00
Jonas Devlieghere 950a8aa165 [lldb/Reproducers] Support new replay mode: passive replay
Support passive replay as proposed in the RFC [1] on lldb-dev and
described in more detail on the lldb website [2].

This patch extends the LLDB_RECORD macros to re-invoke the current
function with arguments deserialized from the reproducer. This relies on
the function being called in the exact same order as during replay. It
uses the same mechanism to toggle the API boundary as during recording,
which guarantees that only boundary crossing calls are replayed.

Another major change is that before this patch we could ignore the
result of an API call, because we only cared about the observable
behavior. Now we need to be able to return the replayed result to the
SWIG bindings.

We reuse a lot of the recording infrastructure, which can be a little
confusing. We kept the existing naming to limit the amount of churn, but
might revisit that in a future patch.

[1] http://lists.llvm.org/pipermail/lldb-dev/2020-April/016100.html
[2] https://lldb.llvm.org/resources/reproducers.html

Differential revision: https://reviews.llvm.org/D77602
2020-04-20 09:41:40 -07:00
Emre Kultursay 1f820fa4fe [lldb] Fix SourceManager::SourceFileCache insertion
Summary:
Lookup and subsequent insert was done using uninitialized
FileSpec object, which caused the cache to be a no-op.

Bug: llvm.org/PR45310

Depends on D76804.

Reviewers: labath, JDevlieghere

Reviewed By: labath

Subscribers: mgorny, jingham, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D76805
2020-04-20 16:25:54 +02:00
Pavel Labath d5c26f871b [lldb/unittests] Better error messages when creating sockets fails
We get failures in SocketTestUtilities on the pre-merge bots. This
might give us a clue as to what's wrong.
2020-04-16 11:59:37 +02:00
Jason Molenda 1cd92e480c Bug where insn-based unwind plans on arm64 could be wrong
Fix a bug where UnwindAssemblyInstEmulation would confuse which
register is used to compute the Canonical Frame Address after it
had branched over a mid-function epilogue (where the CFA reg changes
from $fp to $sp in the process of epiloguing).  Reinstate the
correct CFA register after we forward the unwind rule for branch
targets.  The failure mode was that UnwindAssemblyInstEmulation
would think CFA was set in terms of $sp after one of these epilogues,
and if it sees modifications to $sp after the branch target, it would
change the CFA offset in the unwind rule -- even though the CFA is
defined in terms of $fp and the $sp changes are irrelevant to correct
calculation.

<rdar://problem/60300528>

Differential Revision: https://reviews.llvm.org/D78077
2020-04-14 16:57:25 -07:00
Jonas Devlieghere cc220d4031 [lldb/Test] Use RAII for reproducer instrumentation data in unittest.
Use a RAII object to manage the lifetime of the reproducer
instrumentation data.
2020-04-14 14:46:39 -07:00
Walter Erquinigo cea112f422 [lldb] Fix a typo in a test name
Summary:
Removing the Test prefix from the file name and its usages. The standard is using only Test as a suffix.
This was correctly pointed out in https://reviews.llvm.org/D77444.

Reviewers: labath, clayborg

Subscribers: mgorny, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D77878
2020-04-14 12:18:58 -07:00
Jonas Devlieghere f78fcd6906 [lldb/Test] Rewrite ReproducerInstrumentationTest
The instrumentation unit tests' current implementation uses global
variables to track constructor calls for the instrumented classes during
replay. This is suboptimal because it indirectly relies on how the
reproducer instrumentation is implemented. I found out when adding
support for passive replay and the test broke because we made an extra
(temporary) copy of the instrumented objects.

Additionally, the old approach wasn't very self-explanatory. It took me
a bit of time to understand why we were expecting the number of objects
in the test.

This patch rewrites the test and uses the index-to-object-mapping to
verify the objects created during replay. You can now specify the
expected objects, in order, and whether they should be valid or not. I
find that it makes the tests much easier to understand. More
importantly, this approach is resilient to implementation detail changes
in the instrumentation.
2020-04-10 16:50:44 -07:00
Adrian Prantl 143d507c9f Preserve the owning module information from DWARF in the synthesized AST
Types that came from a Clang module are nested in DW_TAG_module tags
in DWARF. This patch recreates the Clang module hierarchy in LLDB and
1;95;0csets the owning module information accordingly. My primary motivation
is to facilitate looking up per-module APINotes for individual
declarations, but this likely also has other applications.

This reapplies the previously reverted commit, but without support for
ClassTemplateSpecializations, which I'm going to look into separately.

rdar://problem/59634380

Differential Revision: https://reviews.llvm.org/D75488
2020-04-09 11:09:44 -07:00
Pavel Labath 9aa5fbb3af [lldb] Disable the new Communication test on windows
The ConnectionFileDescriptor class on windows does not support
interruption (see the BytesAvailable method). Therefore this test makes
no sense there.
2020-04-09 15:19:24 +02:00
Pavel Labath 769d7041cc Recommit "[lldb/Core] Fix a race in the Communication class"
The synchronization logic in the previous had a subtle bug. Moving of
the "m_read_thread_did_exit = true" into the critical section made it
possible for some threads calling SynchronizeWithReadThread call to get
stuck. This could happen if there were already past the point where they
checked this variable. In that case, they would block on waiting for the
eBroadcastBitNoMorePendingInput event, which would never come as the
read thread was blocked on getting the synchronization mutex.

The new version moves that line out of the critical section and before
the sending of the eBroadcastBitNoMorePendingInput event, and also adds
some comments to explain why the things need to be in this sequence:
- m_read_thread_did_exit = true: prevents new threads for waiting on
  events
- eBroadcastBitNoMorePendingInput: unblock any current thread waiting
  for the event
- Disconnect(): close the connection. This is the only bit that needs to
  be in the critical section, and this is to ensure that we don't close
  the connection while the synchronizing thread is mucking with it.

Original commit message follows:

Communication::SynchronizeWithReadThread is called whenever a process
stops to ensure that we process all of its stdout before we report the
stop. If the process exits, we first call this method, and then close
the connection.

However, when the child process exits, the thread reading its stdout
will usually (but not always) read an EOF because the other end of the
pty has been closed. In response to an EOF, the Communication read
thread closes it's end of the connection too.

This can result in a race where the read thread is closing the
connection while the synchronizing thread is attempting to get its
attention via Connection::InterruptRead.

The fix is to hold the synchronization mutex while closing the
connection.

I've found this issue while tracking down a rare flake in some of the
vscode tests. I am not sure this is the cause of those failures (as I
would have expected this issue to manifest itself differently), but it
is an issue nonetheless.

The attached test demonstrates the steps needed to reproduce the race.
It will fail under tsan without this patch.

Reviewers: clayborg, JDevlieghere

Subscribers: mgorny, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D77295
2020-04-09 13:39:00 +02:00
Pavel Labath 76975c744d Revert "[lldb/Core] Fix a race in the Communication class"
This reverts commit ebb071345c -- it seems
to introduce a deadlock in some circumstances.
2020-04-09 12:49:56 +02:00
Pavel Labath ebb071345c [lldb/Core] Fix a race in the Communication class
Summary:
Communication::SynchronizeWithReadThread is called whenever a process
stops to ensure that we process all of its stdout before we report the
stop. If the process exits, we first call this method, and then close
the connection.

However, when the child process exits, the thread reading its stdout
will usually (but not always) read an EOF because the other end of the
pty has been closed. In response to an EOF, the Communication read
thread closes it's end of the connection too.

This can result in a race where the read thread is closing the
connection while the synchronizing thread is attempting to get its
attention via Connection::InterruptRead.

The fix is to hold the synchronization mutex while closing the
connection.

I've found this issue while tracking down a rare flake in some of the
vscode tests. I am not sure this is the cause of those failures (as I
would have expected this issue to manifest itself differently), but it
is an issue nonetheless.

The attached test demonstrates the steps needed to reproduce the race.
It will fail under tsan without this patch.

Reviewers: clayborg, JDevlieghere

Subscribers: mgorny, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D77295
2020-04-09 12:06:47 +02:00
Walter Erquinigo be3f8a8e1b [commands] Support autorepeat in SBCommands
Summary:
This adds support for commands created through the API to support autorepeat.
This covers the case of single word and multiword commands.

Comprehensive tests are included as well.

Reviewers: labath, clayborg

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D77444
2020-04-08 10:54:14 -07:00
Adrian Prantl 1e05d7b3d3 Remap the target (Xcode) SDK directory to the host SDK directory.
This is mostly useful for Swift support; it allows LLDB to substitute
a matching SDK it shipped with instead of the sysroot path that was
used at compile time.

The goal of this is to make the Xcode SDK something that behaves more
like the compiler's resource directory, as in that it ships with LLDB
rather than with the debugged program. This important primarily for
importing Swift and Clang modules in the expression evaluator, and
getting at the APINotes from the SDK in Swift.

For a cross-debugging scenario, this means you have to have an SDK for
your target installed alongside LLDB. In Xcode this will always be the
case.

rdar://problem/60640017

Differential Revision: https://reviews.llvm.org/D76471
2020-04-06 15:51:30 -07:00
Kazuaki Ishizaki e9264b746b [lldb] NFC: Fix trivial typo in comments, documents, and messages
Differential Revision: https://reviews.llvm.org/D77460
2020-04-07 01:06:16 +09:00
Jonas Devlieghere d144087c96 [lldb/Support] Treat empty FileSpec as an invalid file.
LLDB relies on empty FileSpecs being invalid files, for example, they
don't exists. Currently this assumption does not always hold during
reproducer replay, because we pass the result of GetPath to the VFS.
This is an empty string, which the VFS converts to an absolute directory
by prepending the current working directory, before looking it up in the
YAML mapping. This means that an empty FileSpec will exist when the
current working directory does. This breaks at least one test
(TestAddDsymCommand.py) when ran from replay.

This patch special cases empty FileSpecs and returns a sensible result
before calling GetPath and forwarding the call.

Differential revision: https://reviews.llvm.org/D77351
2020-04-03 09:29:22 -07:00
Pavel Labath 451741a9d7 [lldb] Change Communication::SetConnection to take a unique_ptr
The function takes ownership of the object. This makes that explicit,
and avoids unowned pointers floating around.
2020-04-02 14:42:25 +02:00
Adrian Prantl 32672b877d Revert "Preserve the owning module information from DWARF in the synthesized AST"
This reverts commit 4354dfbdf5 while investigating bot fallout.
2020-04-01 18:58:11 -07:00
Adrian Prantl 4354dfbdf5 Preserve the owning module information from DWARF in the synthesized AST
Types that came from a Clang module are nested in DW_TAG_module tags
in DWARF. This patch recreates the Clang module hierarchy in LLDB and
sets the owning module information accordingly. My primary motivation
is to facilitate looking up per-module APINotes for individual
declarations, but this likely also has other applications.

rdar://problem/59634380

Differential Revision: https://reviews.llvm.org/D75488
2020-04-01 17:46:02 -07:00
Med Ismail Bennani f3a7d790df
[lldb/DWARF] Fix evaluator crash when accessing empty stack.
This patch fixes a crash that happens on the DWARF expression evaluator
when trying to access the top of the stack while it's empty.

rdar://60512489

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-03-31 17:44:57 +02:00
Med Ismail Bennani e4a778052e Revert "[lldb/DWARF] Fix evaluator crash when accessing empty stack."
This reverts commit e26eece1e2.
2020-03-31 17:44:17 +02:00
Med Ismail Bennani e26eece1e2 [lldb/DWARF] Fix evaluator crash when accessing empty stack.
This patch fixes a crash that happens on the DWARF expression evaluator
when trying to access the top of the stack while it's empty.

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-03-31 17:28:15 +02:00
shafik 8016d61e3c [LLDB] CPlusPlusNameParser does not handles templated operator< properly
CPlusPlusNameParser is used in several places on of them is during IR execution and setting breakpoints to pull information C++ like the basename, the context and arguments.

Currently it does not handle templated operator< properly, because of idiosyncrasy is how clang generates debug info for these cases.

It uses clang::Lexer which will tokenize operator<<A::B> into:

tok::kw_operator
tok::lessless
tok::raw_identifier

Later on the parser in ConsumeOperator() does not handle this case properly and we end up failing to parse.

Differential Revision: https://reviews.llvm.org/D76168
2020-03-27 14:46:39 -07:00
Emre Kultursay 57be22fa17 [LLDB] Fix parsing of IPv6 host:port inside brackets
Summary:
When using IPv6 host:port pairs, typically the host is put inside
brackets, such as [2601🔢...:0213]:5555, and the UriParser
can handle this format.

However, the Android infrastructure in LLDB assumes an additional
brackets around the host:port pair, such that the entire host:port
string can be treated as the host (which is used as an Android Serial
Number), and UriParser cannot handle multiple brackets. Parsing
inputs with such extra backets requires searching the closing bracket
from the right.

Test: BracketedHostnameWithPortIPv6 covers the case mentioned above

Reviewers: #lldb, labath

Reviewed By: labath

Subscribers: kwk, shafik, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D76736
2020-03-26 11:35:54 +01:00
Jonas Devlieghere 5ffb30fd6c [lldb/PlatformDarwin] Expose current toolchain and CL tools directory
Expose two methods to find the current toolchain and the current command
line tools directory. These are used by Swift to find the resource
directory.
2020-03-18 15:08:24 -07:00
Jonas Devlieghere 14970669dd [lldb/Test] Add unittest for FileSpec::operator bool() 2020-03-18 15:08:23 -07:00
Med Ismail Bennani db31e2e1e6
[lldb/Target] Support more than 2 symbols in StackFrameRecognizer
This patch changes the way the StackFrame Recognizers match a certain
frame.

Until now, recognizers could be registered with a function
name but also an alternate symbol.
This change is motivated by a test failure for the Assert frame
recognizer on Linux. Depending the version of the libc, the abort
function (triggered by an assertion), could have more than two
signatures (i.e. `raise`, `__GI_raise` and `gsignal`).

Instead of only checking the default symbol name and the alternate one,
lldb will iterate over a list of symbols to match against.

rdar://60386577

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-03-18 14:15:58 +01:00
Jonas Devlieghere 7aa28995e8 [lldb/PlatformDarwin] Be more robust in computing the SDK path with xcrun
The current implementation isn't very resilient when it comes to the
output of xcrun. Currently it cannot deal with:

 - Trailing newlines.
 - Leading newlines and errors/warnings before the Xcode path.
 - Xcode not being named Xcode.app.

This extract the logic into a helper in PlatformDarwin and fixes those
issues. It's also the first step towards removing code duplication
between the different platforms and downstream Swift.

Differential revision: https://reviews.llvm.org/D76261
2020-03-17 14:41:45 -07:00
Jonas Devlieghere 0ce3b710b4 [lldb] Add YAML traits for ArchSpec and ProcessInstanceInfo
Add YAML traits for ArchSpec and ProcessInstanceInfo so they can be
serialized for the reproducers.

Differential revision: https://reviews.llvm.org/D76004
2020-03-12 14:38:37 -07:00
Jonas Devlieghere bc9b6b33a0 [lldb/Utility] Add YAML traits for ConstString and FileSpec.
Add YAML traits for the ConstString and FileSpec classes so they can be
serialized as part of ProcessInfo. The latter needs to be serializable
for the reproducers.

Differential revision: https://reviews.llvm.org/D76002
2020-03-12 10:28:21 -07:00
Raphael Isemann e3fc6b3c34 [lldb][NFC] Fix unsigned/signed comparison warning in SymbolFileDWARFTest.cpp
offset_t is unsigned, so if the RHS is signed we get a warning from clang:
    warning: comparison of integers of different signs: 'const unsigned long long' and 'const int'
2020-03-12 15:30:11 +01:00
Luke Drummond 0fa3320931 [lldb] reject `.debug_arange` sections with nonzero segment size
If a producer emits a nonzero segment size, `lldb` will silently read
incorrect values and crash, or do something worse later as the tuple
size is expected to be 2, rather than 3.

Neither LLVM, nor GCC produce segmented aranges, but this dangerous case
should still be checked and handled.

Reviewed by: clayborg, labath
Differential Revision: https://reviews.llvm.org/D75925
Subscribers: lldb-commits
Tags: #lldb
2020-03-12 12:22:50 +00:00
Adrian Prantl cd4c1adabe Add newly-missing include 2020-03-11 19:30:53 -07:00
Unnar Freyr Erlendsson 594130db0a Add unit tests for RangeDataVector::FindEntryIndexesThatContain
Summary: This adds unit tests for FindEntryIndexesThatContain, this is done in preparation for changing the logic of the function.

Reviewers: labath, teemperor

Reviewed By: labath

Subscribers: arphaman, JDevlieghere, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D75180
2020-02-26 16:47:42 +01:00
Pavel Labath d4eca120ac [lldb/gdb-remote] Add support for the qOffsets packet
Summary:
This packet is necessary to make lldb work with the remote-gdb stub in
user mode qemu when running position-independent binaries. It reports
the relative position (load bias) of the loaded executable wrt. the
addresses in the file itself.

Lldb needs to know this information in order to correctly set the load
address of the executable. Normally, lldb would be able to find this out
on its own by following the breadcrumbs in the process auxiliary vector,
but we can't do this here because qemu does not support the
qXfer:auxv:read packet.

This patch does not implement full scope of the qOffsets packet (it only
supports packets with identical code, data and bss offsets), because it
is not fully clear how should the different offsets be handled and I am
not aware of a producer which would make use of this feature (qemu will
always
<https://github.com/qemu/qemu/blob/master/linux-user/elfload.c#L2436>
return the same value for code and data offsets). In fact, even gdb
ignores the offset for the bss sections, and uses the "data" offset
instead.  So, until the we need more of this packet, I think it's best
to stick to the simplest solution possible. This patch simply rejects
replies with non-uniform offsets.

Reviewers: clayborg, jasonmolenda

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D74598
2020-02-26 10:18:58 +01:00
Ayke van Laethem ec1efe7113
[LLDB] Let DataExtractor deal with two-byte addresses
AVR usually uses two byte addresses. By making DataExtractor deal with
this, it is possible to load AVR binaries that don't have debug info
associated with them.

Differential Revision: https://reviews.llvm.org/D73969
2020-02-25 16:27:38 +01:00
Raphael Isemann defd0e24aa [lldb][NFC] Move NameSearchContext to own header/source files
The class is large enough to be in its own file. This patch also removes the cyclic
dependency between ClangASTSource <-> NameSearchContext.
2020-02-25 12:25:36 +01:00
Raphael Isemann 3f0661b5e7 [lldb][NFC] Fix compilation of SymbolFilePDBTests.cpp after FindNamespace API change
Since f9568a9549 this function takes a
CompilerDeclContext reference instead of a pointer. It overlooked this function
when I fixed the compilation for FindTypes.
2020-02-18 11:25:12 +01:00
Raphael Isemann 7d13812329 [lldb] Fix compilation of SymbolFilePDBTests.cpp after FindTypes API change
Since f9568a9549 this function takes a
CompilerDeclContext reference instead of a pointer.
2020-02-18 10:52:02 +01:00
Raphael Isemann 8ffea27ae4 [lldb] Refactor and test TypeSystemClang::GetEnumerationIntegerType 2020-02-18 09:52:49 +01:00
Jonas Devlieghere cdc514e4c6 [lldb] Update header guards to be consistent and compliant with LLVM (NFC)
LLDB has a few different styles of header guards and they're not very
consistent because things get moved around or copy/pasted. This patch
unifies the header guards across LLDB and converts everything to match
LLVM's style.

Differential revision: https://reviews.llvm.org/D74743
2020-02-17 23:15:40 -08:00
Jonas Devlieghere 478c9cc4f5 [lldb/Plugins] Rename lldbPluginDisassemblerLLVM (NFC) 2020-02-17 19:14:01 -08:00
Jonas Devlieghere 50c9cd9526 Revert "[lldb/CMake] Auto-generate the Initialize and Terminate calls for plugin"
This is still failing spectacularly on the Windows bot and I still have
no clue what's going on.
2020-02-17 19:04:50 -08:00
Jonas Devlieghere 9b12dc98fd Re-land "[lldb/CMake] Auto-generate the Initialize and Terminate calls for plugin"
This patch changes the way we initialize and terminate the plugins in
the system initializer. It uses an approach similar to LLVM's
TARGETS_TO_BUILD with a def file that enumerates the plugins.

The previously landed patch got reverted because it was lacking:

 (1) A plugin definition for the Objective-C language runtime,
 (2) The dependency between the Static and WASM dynamic loader,
 (3) Explicit initialization of ScriptInterpreterNone for lldb-test.

All issues have been addressed in this patch.

Differential revision: https://reviews.llvm.org/D73067
2020-02-17 14:43:05 -08:00
Jonas Devlieghere 058cb1b47f Revert "[lldb/CMake] Auto-generate the Initialize and Terminate calls for plugin"
This temporarily reverts commit 7d6da329de
because it's causing test failures on the bots.
2020-02-17 12:34:21 -08:00
Jonas Devlieghere 7d6da329de [lldb/CMake] Auto-generate the Initialize and Terminate calls for plugin
This patch changes the way we initialize and terminate the plugins in
the system initializer. It uses an approach similar to LLVM's
TARGETS_TO_BUILD with a def file that enumerates the plugins.

Differential revision: https://reviews.llvm.org/D73067
2020-02-17 09:07:00 -08:00
Pavel Labath 67f63f3f7c [lldb/DWARF] Re-enable basic dwp support
Summary:
This patch removes the bitrotted SymbolFileDWARF(Dwo)Dwp classes, and
replaces them with dwp support implemented directly inside
SymbolFileDWARFDwo, in a manner mirroring the implementation in llvm.
This patch does:
- add support for the .debug_cu_index section to our DWARFContext
- adds a llvm::DWARFUnitIndex argument to the DWARFUnit constructors.
  This argument is used to look up the offsets of the debug_info and
  debug_abbrev contributions in the sections of the dwp file.
- makes sure the creation of the DebugInfo object as well as the initial
  discovery of DWARFUnits is thread-safe, as we can now call this
  concurrently when doing parallel indexing.

This patch does not:
- use the DWARFUnitIndex to search for other kinds of contributions
  (debug_loc, debug_ranges, etc.). This means that units which reference
  these sections will not work correctly. These will be handled by
  follow-up patches, but even the present level of support is sufficient
  to enable basic functionality.
- Make the llvm::DWARFContext thread-safe. Right now, it just avoids this
  problem by ensuring everything is initialized ahead of time. However,
  this is something we will run into more often as we try to use more of
  llvm, and so I plan to start looking into our options here.

Reviewers: JDevlieghere, aprantl, clayborg

Subscribers: mgorny, mgrang, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D73783
2020-02-17 14:10:36 +01:00
Pavel Labath 07355c1c08 [lldb] Delete register info definitions in the x86_64 ABI classes
Summary:
These definitions are used to "augment" information received from the remote
target with eh/debug frame and "generic" register numbers.

Besides being verbose, this information was also incomplete (new registers like
xmm16-31 were missing) and sometimes even downright wrong (ymm register
numbers).

Most of this information is available via llvm's MCRegisterInfo. This patch
creates a new class, MCBasedABI, which retrieves the eh and debug frame register
numbers this way. The tricky part here is that the llvm class uses all-caps
register names, whereas lldb register are lowercase, and sometimes called
slightly differently. Therefore this class introduces some hooks to allow a
subclass to customize the MC lookup. The subclass also needs to suply the
"generic" register numbers, as this is an lldb invention.

This patch ports the x86_64 ABI classes to use the new register info mechanism.
It also creates a new "ABIx86_64" class which can be used to house code common
to x86_64 both ABIs. Right now, this just consists of a single function, but
there are plenty of other things that could be moved here too.

Reviewers: JDevlieghere, jasonmolenda

Subscribers: mgorny, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D74244
2020-02-17 14:01:36 +01:00
Raphael Isemann 651936e5b6 [lldb][NFC] Remove Stream::Indent(const char *) overload in favor of the StringRef version 2020-02-11 13:29:32 +01:00
Pavel Labath 363f05b83d [lldb] Delete the SharingPtr class
Summary:
The only use of this class was to implement the SharedCluster of ValueObjects.
However, the same functionality can be implemented using a regular
std::shared_ptr, and its little-known "sub-object pointer" feature, where the
pointer can point to one thing, but actually delete something else when it goes
out of scope.

This patch reimplements SharedCluster using this feature --
SharedClusterPointer::GetObject now returns a std::shared_pointer which points
to the ValueObject, but actually owns the whole cluster. The only change I
needed to make here is that now the SharedCluster object needs to be created
before the root ValueObject. This means that all private ValueObject
constructors get a ClusterManager argument, and their static Create functions do
the create-a-manager-and-pass-it-to-value-object dance.

Reviewers: teemperor, JDevlieghere, jingham

Subscribers: mgorny, jfb, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D74153
2020-02-11 13:23:18 +01:00
Med Ismail Bennani cb0c4ee3eb [lldb/test] Add alternate symbol to StackFrame Recognizer
This reimplements commit 6b2979c123 and updates
the tests to reflect the addition of the alternate symbol attribute.

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-02-11 11:44:37 +01:00
Raphael Isemann 5b61f78ad5 [lldb] Add test for lldb_private::Stream's indentation functionality 2020-02-11 11:12:54 +01:00
Davide Italiano 6b2979c123 Revert "[lldb] Fix+re-enable Assert StackFrame Recognizer on Linux"
This reverts commit 1a39f1b966 as
it breaks macOS.
2020-02-10 13:27:35 -08:00
Jan Kratochvil 1a39f1b966 [lldb] Fix+re-enable Assert StackFrame Recognizer on Linux
D73303 was failing on Fedora Linux and so it was disabled by Skip the
AssertFrameRecognizer test for Linux.

I find no easy way how to find out if it gets recognized as
`__assert_fail` or `__GI___assert_fail` as during `Process` ctor
libc.so.6 is not yet loaded by the debuggee.

DWARF symbol `__GI___assert_fail` overrides the ELF symbol `__assert_fail`.
While external debug info (=DWARF) gets disabled for testsuite (D55859)
that sure does not apply for real world usage.

Differential Revision: https://reviews.llvm.org/D74252
2020-02-10 10:29:32 +01:00
Med Ismail Bennani 047c4b0369 [lldb/Target] Fix `frame recognizer list` crash when registered with nullptr
One way to register a recognizer is to use RegularExpressionSP for the
module and symbol.

In order to match a symbol regardless of the module, the recognizer can
be registered with a nullptr for the module. However, this cause the
frame recognizer list command to crash because it calls
RegularExpression::GetText without checking if the shared pointer is valid.

This patch adds checks for the symbol and module RegularExpressionSP.

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-02-07 17:35:29 +01:00
Alex Langford 7c9ebdd3d6 [lldb] Remove clang classes from lldb-forward.h
Summary:
lldb-forward.h is convenient in many ways, but having clang-based
class forward declarations in there makes it easy to proliferate uses of clang
outside of plugins. Removing them makes you much more conscious of when
you're using something from clang and marks where we're using things
from clang in non-plugins.

Differential Revision: https://reviews.llvm.org/D73935
2020-02-04 14:23:58 -08:00
Jonas Devlieghere c21b71c1ba [lldb/Unittest] Fix the modules build by including TypeSystemClang.h
This should fix the modules build on the GreenDragon bot.
2020-02-04 14:05:15 -08:00
Jonas Devlieghere f37b62ecce Re-land "[lldb] [testsuite] generalize `DWARFASTParserClangTests` based on `DWARFExpressionTest`'s YAML" 2020-02-04 13:59:29 -08:00
Jan Kratochvil b73f8c53d8 Revert: [lldb] [testsuite] generalize `DWARFASTParserClangTests` based on `DWARFExpressionTest`'s YAML
It is causing a failure on OSX, to be investigated more.

Differential Revision: https://reviews.llvm.org/D73279
2020-02-04 22:48:27 +01:00
Jan Kratochvil 104800084f [lldb] [testsuite] Fixup: generalize `DWARFASTParserClangTests` based on `DWARFExpressionTest`'s YAML
The testcase did not compile now because of an upstream change in the
meantime.

For: https://reviews.llvm.org/D73279
2020-02-04 15:03:09 +01:00
Jan Kratochvil 2926a651ba [lldb] [testsuite] generalize `DWARFASTParserClangTests` based on `DWARFExpressionTest`'s YAML
YAMLModuleTester from DWARFExpressionTest can be reused for more
testcases.

Differential Revision: https://reviews.llvm.org/D73279
2020-02-04 14:33:29 +01:00
Vedant Kumar 7b90cdedd1 [lldb/DataExtractor] Fix UB shift in GetMaxS64Bitfield
DataExtractor::GetMaxS64Bitfield performs a shift with UB in order to
construct a bitmask when bitfield_bit_size is 64. The current
implementation actually does “work” in this case, because the assumption
that the shift result is 0 holds, and 0 minus 1 gives the all-ones value
(the correct mask). However, the more readable/maintainable approach
might be to use an off-the-shelf UB-free helper.

Fixes a UBSan issue:

  "col" : 37,
  "description" : "invalid-shift-exponent",
  "filename" : "/Users/vsk/src/llvm-project-master/lldb/source/Utility/DataExtractor.cpp",
  "instrumentation_class" : "UndefinedBehaviorSanitizer",
  "line" : 615,
  "memory_address" : 0,
  "summary" : "Shift exponent 64 is too large for 64-bit type 'uint64_t' (aka 'unsigned long long')",

rdar://59117758

Differential Revision: https://reviews.llvm.org/D73913
2020-02-03 15:57:32 -08:00
Jonas Devlieghere c62ffb1b19 [lldb/Reproducers] Include string length in string (de)serialization.
This allows us to differentiate between an empty string and a nullptr.

(cherry picked from commit 53e206284fa715886020d6a5553bf791582850a3)
2020-01-31 17:40:49 -08:00
Alex Langford 8be30215fe [lldb] Move clang-based files out of Symbol
Summary:
This change represents the move of ClangASTImporter, ClangASTMetadata,
ClangExternalASTSourceCallbacks, ClangUtil, CxxModuleHandler, and
TypeSystemClang from lldbSource to lldbPluginExpressionParserClang.h

This explicitly removes knowledge of clang internals from lldbSymbol,
moving towards a more generic core implementation of lldb.

Reviewers: JDevlieghere, davide, aprantl, teemperor, clayborg, labath, jingham, shafik

Subscribers: emaste, mgorny, arphaman, jfb, usaxena95, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D73661
2020-01-31 12:20:10 -08:00
Pavel Labath 33f65f393f [lldb] Add a basic unit test for the SharedCluster class 2020-01-31 15:46:41 +01:00
Alex Langford 22b044877d [lldb][NFCI] Remove unused LanguageType parameters
These parameters are unused in these methods, and some of them only had a
LanguageType parameter to pipe to other methods that don't use it
either.
2020-01-30 21:57:23 -08:00
Jonas Devlieghere e28d8f9069 [lldb] Replace SmallStr.str().str() with std::string conversion operator.
Use the std::string conversion operator introduced in
d7049213d0. The SmallString in the log
statement doesn't require conversion at all when using the variadic log
macro.
2020-01-29 21:34:19 -08:00
Jonas Devlieghere 91f863be4f [lldb/Reproducers] Add unittest for char** (de)serializer 2020-01-29 17:16:31 -08:00
Raphael Isemann ab8b22d1c2 [lldb] Don't create duplicate declarations when completing a forward declaration with a definition from another source
Summary:
I noticed this strange line in `ASTImporterDelegate::ImportDefinitionTo` which doesn't make a lot of sense:
```
to_tag->setCompleteDefinition(from_tag->isCompleteDefinition());
```

It forcibly sets the imported TagDecl to be defined if the source TagDecl was defined. This doesn't make any
sense as in this code we already forced the ASTImporter to import the definition so this should always be
a no-op.

Turns out this is hiding two bugs:
1. The way we handle forward declarations in the debug info that might be completed later is that we
  import them and then mark them as having external lexical storage. This makes Clang ask for the definition
  later when it needs it (at which point we hopefully have the definition around and can complete it). However,
  this is currently not completing the forward decls with external storage but instead creates a duplicated decl
  in the target AST which is then defined. The forward decl is kept incomplete after the import and we just
  forcibly make it a definition of the record without any content with our workaround. The TestSharedLib* tests
  is only passing because of this.
2. Minimal import of lambdas is broken and never imports the definition it seems. That appears to be a bug
  in the ASTImporter which gives the definition of lambda's some special treatment. TestLambdas.py is actually
  broken but is passing because of this workaround.

This patch fixes the first bug by forcing the ASTImporter to import to the target forward declaration. We can't
delete the workaround as the second bug is still around but that will be a follow up review for the ASTImporter.
However it will get rid of all the duplicated RecordDecls that are in our expression AST that are strangely defined
but don't have any of the fields they are supposed to have.

Reviewers: shafik, labath

Reviewed By: shafik

Subscribers: aprantl, abidh, JDevlieghere, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D73345
2020-01-29 09:20:47 +01:00
Benjamin Kramer 777180a32b [ADT] Make StringRef's std::string conversion operator explicit
This has the same behavior as converting std::string_view to
std::string. This is an expensive conversion, so explicit conversions
are helpful for avoiding unneccessary string copies.
2020-01-28 23:47:07 +01:00
Benjamin Kramer adcd026838 Make llvm::StringRef to std::string conversions explicit.
This is how it should've been and brings it more in line with
std::string_view. There should be no functional change here.

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

This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-28 23:25:25 +01:00
Raphael Isemann 243f52b58b [lldb] Cut off unused suffix in CompletionRequest::GetRawLine
The GetRawLine currently returns the full command line used
to create the CompletionRequest. So for example for "foo b[tab] --arg"
it would return the whole string instead of "foo b". Usually
completion code makes the wrong assumption that the cursor is at
the end of the line and handing out the complete line will cause
that people implement completions that also make this assumption.

This patch makes GetRawLine() return only the string until the
cursor and hides the suffix (so that the cursor is always at the
end of this string) and adds another function GetRawLineWithUnusedSuffix
that is specifically the line with the suffix that isn't used by
the CompletionRequest for argument parsing etc.

There is only one user of this new function that actually needs the
suffix and that is the expression command which needs the suffix to
detect if it is in the raw or argument part of the command (by looking
at the "--" separator).
2020-01-28 11:12:22 +01:00
Raphael Isemann 808142876c [lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).

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

Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere

Reviewed By: JDevlieghere

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

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 08:52:55 +01:00
Raphael Isemann 6e3b0cc2fb [lldb][NFC] Rename ClangASTContext to TypeSystemClang
Summary:
This commit renames ClangASTContext to TypeSystemClang to better reflect what this class is actually supposed to do
(implement the TypeSystem interface for Clang). It also gets rid of the very confusing situation that we have both a
`clang::ASTContext` and a `ClangASTContext` in clang (which sometimes causes Clang people to think I'm fiddling
with Clang's ASTContext when I'm actually just doing LLDB work).

I also have plans to potentially have multiple clang::ASTContext instances associated with one ClangASTContext so
the ASTContext naming will then become even more confusing to people.

Reviewers: #lldb, aprantl, shafik, clayborg, labath, JDevlieghere, davide, espindola, jdoerfert, xiaobai

Reviewed By: clayborg, labath, xiaobai

Subscribers: wuzish, emaste, nemanjai, mgorny, kbarton, MaskRay, arphaman, jfb, usaxena95, jingham, xiaobai, abidh, JDevlieghere, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D72684
2020-01-23 10:09:14 +01:00
Raphael Isemann c9a39a896c [lldb] Add a display name to ClangASTContext instances
Summary:
I often struggle to understand what exactly LLDB is doing by looking at our expression evaluation logging as our messages look like this:
```
CompleteTagDecl[2] on (ASTContext*)0x7ff31f01d240 Completing (TagDecl*)0x7ff31f01d568 named DeclName1
```

From the log messages it's unclear what this ASTContext is. Is it the scratch context, the expression context, some decl vendor context or a context from a module?
The pointer value isn't helpful for anyone unless I'm in a debugger where I could inspect the memory at the address. But even with a debugger it's not easy to
figure out what this ASTContext is without having deeper understanding about all the different ASTContext instances in LLDB (e.g., valid SourceLocation
from the file system usually means that this is the Objective-C decl vendor, a file name from multiple expressions is probably the scratch context, etc.).

This patch adds a name field to ClangASTContext instances that we can use to store a name which can be used for logging and debugging. With this
our log messages now look like this:
```
CompleteTagDecl[2] on scratch ASTContext. Completing (TagDecl*)0x7ff31f01d568 named Foo
```
We can now also just print a ClangASTContext from the debugger and see a useful name in the `m_display_name` field, e.g.
```
  m_display_name = "AST for /Users/user/test/main.o";
```

Reviewers: shafik, labath, JDevlieghere, mib

Reviewed By: shafik

Subscribers: clayborg, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D72391
2020-01-22 08:54:10 +01:00
Jonas Devlieghere be9604247e [lldb/Plugin] Move DisassemblerLLVMC for consistency with plugin (NFC)
Rename the DisassemblerLLVMC directory from llvm to LLVMC to match the
plugin name.
2020-01-21 15:17:29 -08:00
Raphael Isemann 22447a61d4 [lldb] Mark the implicit copy constructor as deleted when a move constructor is provided.
Summary:
CXXRecordDecls that have a move constructor but no copy constructor need to
have their implicit copy constructor marked as deleted (see C++11 [class.copy]p7, p18)
Currently we don't do that when building an AST with ClangASTContext which causes
Sema to realise that the AST is malformed and asserting when trying to create an implicit
copy constructor for us in the expression:
```
Assertion failed: ((data().DefaultedCopyConstructorIsDeleted || needsOverloadResolutionForCopyConstructor())
    && "Copy constructor should not be deleted"), function setImplicitCopyConstructorIsDeleted, file include/clang/AST/DeclCXX.h, line 828.
```

In the test case there is a class `NoCopyCstr` that should have its copy constructor marked as
deleted (as it has a move constructor). When we end up trying to tab complete in the
`IndirectlyDeletedCopyCstr` constructor, Sema realises that the `IndirectlyDeletedCopyCstr`
has no implicit copy constructor and tries to create one for us. It then realises that
`NoCopyCstr` also has no copy constructor it could find via lookup. However because we
haven't marked the FieldDecl as having a deleted copy constructor the
`needsOverloadResolutionForCopyConstructor()` returns false and the assert fails.
`needsOverloadResolutionForCopyConstructor()` would return true if during the time we
added the `NoCopyCstr` FieldDecl to `IndirectlyDeletedCopyCstr` we would have actually marked
it as having a deleted copy constructor (which would then mark the copy constructor of
`IndirectlyDeletedCopyCstr ` as needing overload resolution and Sema is happy).

This patch sets the correct mark when we complete our CXXRecordDecls (which is the time when
we know whether a copy constructor has been declared). In theory we don't have to do this if
we had a Sema around when building our debug info AST but at the moment we don't have this
so this has to do the job for now.

Reviewers: shafik

Reviewed By: shafik

Subscribers: aprantl, JDevlieghere, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D72694
2020-01-20 14:34:07 +01:00
Adrian Prantl f55ab6f90b Fix a buffer-size bug when the first DW_OP_piece is undefined
and document the shortcomings of LLDB's partially defined DW_OP_piece
handling.

This would manifest as "DW_OP_piece for offset foo but top of stack is
of size bar".

rdar://problem/46262998

Differential Revision: https://reviews.llvm.org/D72880
2020-01-16 16:47:59 -08:00
Adrian Prantl 7b0d58e339 Add testing for DW_OP_piece and fix a bug with small Scalar values.
By switching to Scalars that are backed by explicitly-sized APInts we
can avoid a bug that increases the buffer reserved for a small piece
to the next-largest host integer type.

This manifests as "DW_OP_piece for offset foo but top of stack is of size bar".

Differential Revision: https://reviews.llvm.org/D72879
2020-01-16 16:47:36 -08:00
Raphael Isemann 9e13cff44d [lldb] Fix TestClangASTContext.TestFunctionTemplateInRecordConstruction in Debug builds
Summary:
In Debug builds we call VerifyDecl in ClangASTContext::CreateFunctionDeclaration which in turn
calls `getAccess` on the created FunctionDecl. As we passed in a RecordDecl as the DeclContext
for the FunctionDecl, we end up hitting the assert in `getAccess` that checks that we never have
a Decl inside a Record without a valid AccessSpecifier. FunctionDecls are never in RecordDecls
(that would be a CXXMethodDecl) so setting a access specifier would not be the correct way to
fix this.

Instead this patch does the same thing that DWARFASTParserClang::ParseSubroutine is doing:
We pass in the FunctionDecl with the TranslationUnit as the DeclContext. That's not ideal but
it is how we currently do it when creating our debug info AST, so the unit test should do
the same.

Reviewers: shafik

Reviewed By: shafik

Subscribers: aprantl, JDevlieghere, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D72359
2020-01-10 21:34:07 +01:00
Jan Kratochvil 2f2f41e12c RangeDataVector: Support custom sorting for D63540
As suggested by @labath extended RangeDataVector so that user can provide
custom sorting of the Entry's `data' field for D63540.
        https://reviews.llvm.org/D63540

RangeData functions were used just by RangeDataVector (=after I removed them
LLDB still builds fine) which no longer uses them so I removed them.

Differential revision: https://reviews.llvm.org/D72460
2020-01-10 15:14:38 +01:00
Raphael Isemann 518597c173 [lldb] Remove default llvm::Triple argument from ClangASTContext constructor
Creating an ASTContext with an unknown triple is rarely a good idea (as usually
all our ASTs have a valid triple that is either from the host or the target) and the
default argument makes it far to easy to implicitly create such an AST. Let's
remove it and force people to pass a triple.

The only place where we don't pass a triple is a DWARFASTParserClangTests
where we now just pass the host triple instead (the test doesn't depend on any
triple so this shouldn't change anything).
2020-01-08 12:05:51 +01:00
Raphael Isemann d364815351 [lldb][NFC] Take a llvm::Triple in ClangASTContext constructor
This constructor is supposed to take a string representing an llvm::Triple.
We might as well take a llvm::Triple here which saves us all the string
conversions in the call sites and we make this more type safe.
2020-01-07 10:50:59 +01:00
Raphael Isemann 7ead008729 [lldb] Fix crash in AccessDeclContextSanity when copying FunctionTemplateDecl inside a record.
Summary:
We currently don't set access specifiers for function template declarations. This seems to be fine
as long as the function template is not declared inside any record in which case Clang asserts
with the following once we try to query it's access:
```
Assertion failed: (Access != AS_none && "Access specifier is AS_none inside a record decl"), function AccessDeclContextSanity,
```

This patch just marks these function template declarations as public to make Clang happy.

Reviewers: shafik, teemperor

Reviewed By: teemperor

Subscribers: JDevlieghere, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D71909
2020-01-02 14:47:04 +01:00
Raphael Isemann 73951a11c6 [lldb] Add sanity check to CreateDeclContext and fixed illformed CompilerContext in ClangExpressionDeclMap.
This adds a check that the ClangASTContext actually fits to the
DeclContext that we want to create a CompilerDeclContext for. If
the ClangASTContext (and its associated ASTContext) does not fit
to the DeclContext (that is, the DeclContext wasn't created by the
ASTContext), all computations using this malformed CompilerDeclContext
will yield unpredictable results.

Also fixes the only place that actually hits this assert which is the
construction of a CompilerDeclContext in ClangExpressionDeclMap
where we pass an unrelated ASTContext instead of the ASTContext
of the current expression.

I had to revert my previous change to DWARFASTParserClangTests.cpp
back to using the unsafe direct construction of CompilerDeclContext
as this assert won't work if the DeclContext we pass isn't a valid
DeclContext in the first place.
2019-12-23 11:48:02 +01:00
Raphael Isemann 5dca0596a9 [lldb] Add a SubsystemRAII that takes care of calling Initialize and Terminate in the unit tests
Summary:
Many of our tests need to initialize certain subsystems/plugins of LLDB such as
`FileSystem` or `HostInfo` by calling their static `Initialize` functions before the
test starts and then calling `::Terminate` after the test is done (in reverse order).
This adds a lot of error-prone boilerplate code to our testing code.

This patch adds a RAII called SubsystemRAII that ensures that we always call
::Initialize and then call ::Terminate after the test is done (and that the Terminate
calls are always in the reverse order of the ::Initialize calls). It also gets rid of
all of the boilerplate that we had for these calls.

Per-fixture initialization is still not very nice with this approach as it would
require some kind of static unique_ptr that gets manually assigned/reseted
from the gtest SetUpTestCase/TearDownTestCase functions. Because of that
I changed all per-fixture setup to now do per-test setup which can be done
by just having the SubsystemRAII as a member of the test fixture. This change doesn't
influence our normal test runtime as LIT anyway runs each test case separately
(and the Initialize/Terminate calls are anyway not very expensive). It will however
make running all tests in a single executable slightly slower.

Reviewers: labath, JDevlieghere, martong, espindola, shafik

Reviewed By: labath

Subscribers: mgorny, rnkovacs, emaste, MaskRay, abidh, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D71630
2019-12-23 10:38:25 +01:00
Raphael Isemann 42ec584a8b [lldb][NFC] Make CompilerDeclContext construction type safe
The CompilerDeclContext constructor takes a void* pointer which
means that all callers of this constructor need to first explicitly
convert all pointers to clang::DeclContext*. This causes that we
for example can't just pass a TranslationUnitDecl* to the constructor without
first casting it to its parent class (as it inherits from both
Decl and DeclContext so the void* pointer is actually a Decl*).

This patch introduces a utility function in the ClangASTContext
which gets rid of the requirement to cast all pointers to
clang::DeclContext. Also moves all constructor calls to use this
function instead which is NFC (beside the change in
DWARFASTParserClangTests.cpp).
2019-12-23 09:56:54 +01:00
Raphael Isemann ceb433ad16 [lldb] Fix windows build after getASTContext() change 2019-12-21 23:27:27 +01:00
Raphael Isemann f9f49d3594 [lldb][NFC] Return a reference from ClangASTContext::getASTContext and remove dead nullptr checks
ClangASTContext::getASTContext() currently returns a ptr but we have an assert there since a
while that the ASTContext is not a nullptr. This causes that we still have a lot of code
that is doing nullptr checks on the result of getASTContext() which is all unreachable code.

This patch changes the return value to a reference to make it clear this can't be a nullptr
and deletes all the nullptr checks.
2019-12-21 22:51:35 +01:00
Jonas Devlieghere bf03e17c57 [Lldb/Lua] Generate Lua Bindings
This patch uses SWIG to generate the Lua bindings for the SB API. It
covers most of the API, but some methods require a type map similar to
Python.

Discussion on the mailing list:
http://lists.llvm.org/pipermail/lldb-dev/2019-December/015812.html

Differential revision: https://reviews.llvm.org/D71235
2019-12-21 11:28:41 -08:00
Raphael Isemann 49b206f958 [lldb][NFC] Remove all ASTContext getter wrappers from ClangASTContext
Their naming is misleading as they only return the
ClangASTContext-owned variables. For ClangASTContext instances constructed
for a given clang::ASTContext they silently generated duplicated instances
(e.g., a second IdentifierTable) that were essentially unusable.

This removes all these getters as they are anyway not very useful in comparison
to just calling the clang::ASTContext getters. The initialization
code has been moved to the CreateASTContext initialization method so that all
code for making our own clang::ASTContext is in one place.
2019-12-21 15:41:18 +01:00
Jonas Devlieghere 2861324208 [lldb/Lua] Implement a Simple Lua Script Interpreter Prototype
This implements a very elementary Lua script interpreter. It supports
running a single command as well as running interactively. It uses
editline if available. It's still missing a bunch of stuff though. Some
things that I intentionally ingored for now are that I/O isn't properly
hooked up (so every print goes to stdout) and the non-editline support
which is not handling a bunch of corner cases. The latter is a matter of
reusing existing code in the Python interpreter.

Discussion on the mailing list:
http://lists.llvm.org/pipermail/lldb-dev/2019-December/015812.html

Differential revision: https://reviews.llvm.org/D71234
2019-12-20 11:19:47 -08:00
Raphael Isemann a805e0fb18 [lldb][NFC] Remove utility methods in TestClangASTImporter
We have a central header for all these methods so we can
just use those for creating ClangASTContexts.
2019-12-20 19:39:49 +01:00
Raphael Isemann 6be76f491f [lldb][NFC] Remove redundant ASTContext args to CopyDecl/DeportDecl
We already pass a Decl here and the additional ASTContext needs to
match the Decl. We might as well just pass the Decl and then extract
the ASTContext from that.
2019-12-20 18:45:14 +01:00
Raphael Isemann aaa34bc0bd [lldb][NFC] Move utility functions from ClangASTImporter and ClangExpressionDeclMap to own header 2019-12-20 16:13:24 +01:00
Raphael Isemann a9c845395f [lldb] Put the headers in unittests/TestingSupport/ into modules 2019-12-20 15:43:53 +01:00
Raphael Isemann 5f78b1d648 [lldb] Add tests for ClangASTImporter's DeportType and DeportDecl methods 2019-12-20 14:47:15 +01:00
Raphael Isemann d8a3194987 [lldb][NFC] Add unit test for persistent variable lookup with ClangExpressionDeclMap
This adds a unit test for looking up persistent declarations in the scratch AST
context. Also adds the `GetPersistentDecl` hook to the ClangExpressionDeclMap
that this unit test can emulate looking up persistent variables without having
a lldb_private::Target.
2019-12-18 13:50:05 +01:00
Raphael Isemann 268f37df6e [lldb][NFC] Use StringRef in CreateRecordType and CreateObjCClass 2019-12-17 16:10:34 +01:00
Raphael Isemann b852b3c982 [lldb][NFC] Rename ClangASTImporter::InsertRecordDecl to SetRecordLayout and document it
This function is just setting the layout for the given RecordDecl so
the current name is not very descriptive. Also add some documentation for it.
2019-12-17 15:56:07 +01:00
Raphael Isemann 4aee81c4f7 [lldb][NFC] Allow creating ClangExpressionDeclMap and ClangASTSource without a Target and add basic unit test
The ClangExpressionDeclMap should be testable from a unit test. This is currently
impossible as they have both dependencies on Target/ExecutionContext from their
constructor. This patch allows constructing these classes without an active Target
and adds the missing tests for running without a target that we can do at least
a basic lookup test without crashing.
2019-12-17 14:04:12 +01:00
Raphael Isemann 22caa3cfbc [lldb] Add unit test for ClangASTImporter 2019-12-16 12:43:55 +01:00
Pavel Labath ea2805a04b [lldb] Centralize desugaring of decltype-like types in ClangASTContext
Summary:
These types were handled in some places, but not others. This resulted
in (for example) not being able to display members of structs whose
types were defined using these constructs.

Using getLocallyUnqualifiedSingleStepDesugaredType for these types is
not fully equivalent, as it will only desugar them if the types are not
instantiation-dependent, whereas previously we did that unconditionally.

It's not clear to me which behavior is correct here, but the test suite
does not seem to care either way.

Reviewers: teemperor, shafik

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D71405
2019-12-16 12:02:32 +01:00
Raphael Isemann 959ed0e294 [lldb][NFC] Fix file header of TestClangASTContext.cpp 2019-12-16 09:34:16 +01:00
Jonas Devlieghere 4e26cf2cfb [lldb/CMake] Rename LLDB_DISABLE_PYTHON to LLDB_ENABLE_PYTHON
This matches the naming scheme used by LLVM and all the other optional
dependencies in LLDB.

Differential revision: https://reviews.llvm.org/D71482
2019-12-13 13:41:11 -08:00
Jonas Devlieghere 3011d55f72 [lldb/Host] Use cmakedefine01 for LLDB_ENABLE_POSIX
Rename LLDB_DISABLE_POSIX to LLDB_ENABLE_POSIX and use cmakedefine01 for
consistency.
2019-12-13 10:00:59 -08:00
Jonas Devlieghere 62456e579e [lldb/CMake] Rename LLDB_DISABLE_LIBEDIT to LLDB_ENABLE_LIBEDIT
This matches the naming scheme used by LLVM.

Differential revision: https://reviews.llvm.org/D71380
2019-12-12 09:23:06 -08:00
Raphael Isemann 987e7323fb [lldb][NFC] Cleanup includes in FormatManagerTests.cpp 2019-12-11 11:33:19 +01:00
Davide Italiano e8d955f29d [FormatManager] Add a unittest for GetCandidateLanguages()
Reviewers: teemperor, JDevlieghere, aprantl, jingham

Subscribers: mgorny, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D71299
2019-12-10 13:42:59 -08:00
Jonas Devlieghere 59998b7b7f [lldb/Host] Use Host/Config.h entries instead of a global define.
As suggested by Pavel in a code review:

> Can we replace this (and maybe python too, while at it) with a
> Host/Config.h entry? A global definition means that one has to
> recompile everything when these change in any way, whereas in
> practice only a handful of files need this..

Differential revision: https://reviews.llvm.org/D71280
2019-12-10 11:16:52 -08:00
shafik fffd70291e [LLDB] Replacing use of ul suffix in GetMaxU64Bitfield since it not guarenteed to be 64 bit
GetMaxU64Bitfield(...) uses the ul suffix but we require a 64 bit unsigned integer and ul could be 32 bit. So this replacing it with a explicit cast and refactors the code around it to use an early exit.

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

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

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

Reviewers: labath

Reviewed By: labath

Subscribers: JDevlieghere, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D71052
2019-12-05 14:41:33 +01:00
Pavel Labath c16f0b18c1 [lldb/cpluspluslanguage] Add constructor substitutor
Summary:
This patch adds code which will substitute references to the full object
constructors/destructors with their base object versions.

Like all substitutions in this category, this operation is not really
sound, but doing this in a more precise way allows us to get rid of a
much larger hack -- matching function according to their demangled
names, which effectively does the same thing, but also much more.

This is a (very late) follow-up to D54074.

Background: clang has an optimization which can eliminate full object
structors completely, if they are found to be equivalent to their base
object versions. It does this because it assumes they can be regenerated
on demand in the compile unit that needs them (e.g., because they are
declared inline). However, this doesn't work for the debugging scenario,
where we don't have the structor bodies available -- we pretend all
constructors are defined out-of-line as far as clang is concerned. This
causes clang to emit references to the (nonexisting) full object
structors during expression evaluation.

Fun fact: This is not a problem on darwin, because the relevant
optimization is disabled to work around a linker bug.

Reviewers: teemperor, JDevlieghere

Subscribers: lldb-commits

Tags: #lldb

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

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

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

Reviewers: labath, jasonmolenda, clayborg

Reviewed By: jasonmolenda

Subscribers: jankratochvil, kristof.beyls, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D70155
2019-12-05 13:10:04 +05:00
Pavel Labath 150c8dd13b [lldb] Remove some (almost) unused Stream::operator<<'s
llvm::raw_ostream provides equivalent functionality.
2019-12-04 11:07:46 +01:00
Raphael Isemann 16d2013044 [lldb] Add test for Stream::Address and Stream::AddressRange
I'm refactoring those functions, so we should have some tests for
them before doing that.
2019-12-04 10:45:30 +01:00
Pavel Labath 532290e69f [lldb] s/FileSpec::Equal/FileSpec::Match
Summary:
The FileSpec class is often used as a sort of a pattern -- one specifies
a bare file name to search, and we check if in matches the full file
name of an existing module (for example).

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

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

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

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

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

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

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

Reviewers: teemperor, JDevlieghere, jdoerfert

Subscribers: emaste, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D70851
2019-12-04 10:42:32 +01:00
Alexandre Ganea 1cc0ba4cbd [LLDB] Disable MSVC warning C4190: 'LLDBSwigPythonBreakpointCallbackFunction' has C-linkage specified, but returns UDT 'llvm::Expected<bool>' which is incompatible with C
Differential Revision: https://reviews.llvm.org/D70830
2019-12-03 09:53:26 -05:00
Raphael Isemann c214c92f3b [lldb][NFC] Remove ClangASTContext::GetBuiltinTypeForEncodingAndBitSize overload 2019-11-29 13:57:02 +01:00
Pavel Labath 656a8123de [lldb] Fix windows build for 38870af 2019-11-29 12:48:25 +01:00
Pavel Labath bf716eb807 [lldb] Add FileSpec::Equal unit tests
this is in preparation of a refactor of this method.
2019-11-28 14:31:52 +01:00
Pavel Labath d1a561d446 [lldb] Simplify and improve FileSpecTest
Summary:
A most of these tests create FileSpecs with a hardcoded style. Add
utility functions which create a file spec of a given style to simplify
things.

While in there add SCOPED_TRACE messages to tests which loop over
multiple inputs to ensure it's clear which of the inputs failed.

Reviewers: teemperor

Subscribers: lldb-commits

Tags: #lldb

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

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

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

Reviewers: teemperor, JDevlieghere, jdoerfert

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D70241
2019-11-26 14:24:28 +01:00
Raphael Isemann c502bae524 [lldb][NFC] Simplify ClangASTContext::GetBasicTypes
static convenience methods that do the clang::ASTContext -> ClangASTContext
conversion and handle errors by simply ignoring them are not a good idea.
2019-11-20 12:47:14 +01:00
Michał Górny b59af82805 [lldb] [unittest] Skip TestStopReplyContainsThreadPcs on NetBSD 2019-11-18 22:36:02 +01:00
Michał Górny d82dd6ac9a [lldb] [unittest] Reenable MainLoopTest.DetectsEOF on NetBSD
The underlying issue is already fixed in the NetBSD kernel for some
time, so we can finally reenable the test.
2019-11-18 22:36:01 +01:00
Alex Cameron 10b8514343 [lldb] Fix JSON parser to allow empty arrays
Summary:
Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=39405
```
alexc@kitty:~/work/wiredtiger/build_posix$ cat breakpoint.json
[{"Breakpoint" : {"BKPTOptions" : {"AutoContinue" : false,"ConditionText" : "","EnabledState" : true,"IgnoreCount" : 0,"OneShotState" : false},"BKPTResolver" : {"Options" : {"NameMask" : [56],"Offset" : 0,"SkipPrologue" : true,"SymbolNames" : ["__wt_btcur_search"]},"Type" : "SymbolName"},"Hardware" : false,"SearchFilter" : {"Options" : {},"Type" : "Unconstrained","Foo" : []}}}]
```
**Before**
```
(lldb) breakpoint read --file breakpoint.json
error: Invalid JSON from input file: /home/alexc/work/wiredtiger/build_posix/breakpoint.json.
```
**After**
```
(lldb) breakpoint read --file breakpoint.json
New breakpoints:
Breakpoint 1: where = libwiredtiger-3.2.2.so`__wt_btcur_search + 15 at bt_cursor.c:522:5, address = 0x00007ffff576ab2f
```

Reviewers: xbolva00, davide, labath

Reviewed By: davide, labath

Subscribers: mgorny, jingham, labath, davide, JDevlieghere, lldb-commits

Tags: #llvm, #lldb

Differential Revision: https://reviews.llvm.org/D68179
2019-11-18 15:12:55 +01:00
Raphael Isemann 8715ffdf1a [lldb] Fix that trailing backslashes in source lines break the Clang highlighter
Summary:
Clang's raw Lexer doesn't produce any tokens for trailing backslashes in a line. This doesn't work with
LLDB's Clang highlighter which builds the source code to display from the list of tokens the Lexer returns.
This causes that lines with trailing backslashes are lacking the backslash and the following newline when
rendering source code in LLDB.

This patch removes the trailing newline from the current line we are highlighting. This way Clang doesn't
drop the backslash token and we just restore the newline after tokenising.

Fixes rdar://57091487

Reviewers: JDevlieghere, labath

Reviewed By: JDevlieghere, labath

Subscribers: labath, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D70177
2019-11-14 11:11:20 +01:00
Jonas Devlieghere 33c3e0b96c [LLDB] Implement pure virtual method in MockConnection
I made GetReadObject pure virtual in the base class and forgot to add
the method to the mock class.
2019-11-13 15:37:57 -08:00
shafik 83393d27af [LLDB] Fix handling for the clang name mangling extension for block invocations
Add support for clangs  mangling extension for block invocations.

Differential Revision: https://reviews.llvm.org/D69738
2019-11-06 14:20:00 -08:00
Lawrence D'Anna adbf64ccc9 [LLDB][Python] remove ArgInfo::count
Summary:
This patch updates the last user of ArgInfo::count and deletes
it.   I also delete `GetNumInitArguments()` and `GetInitArgInfo()`.
Classess are callables and `GetArgInfo()` should work on them.

On python 3 it already works, of course. `inspect` is good.

On python 2 we have to add yet another special case.   But hey if
python 2 wasn't crufty we wouln't need python 3.

I also delete `is_bound_method` becuase it is unused.

This path is tested in `TestStepScripted.py`

Reviewers: labath, mgorny, JDevlieghere

Reviewed By: labath, JDevlieghere

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D69742
2019-11-04 12:48:49 -08:00
Lawrence D'Anna fb01c01bf3 [LLDB][Python] warning fix for LLDBSwigPythonBreakpointCallbackFunction
This is a quick followup to this commit:

https://reviews.llvm.org/rGa69bbe02a2352271e8b14542073f177e24c499c1

In that, I #pragma-squelch this warning in `ScriptInterpreterPython.cpp`
but we get the same warning in `PythonTestSuite.cpp`.

This patch squelches the same warning in the same way as the
reviweed commit.   I'm submitting it without review under the
"obviously correct" rule.

At least if this is incorrect the main commit was also incorrect.

By the way, as far as I can tell, these functions are extern "C" because
SWIG does that to everything, not because they particularly need to be.
2019-10-30 09:47:27 -07:00
Lawrence D'Anna a69bbe02a2 [LLDB][breakpoints] ArgInfo::count -> ArgInfo::max_positional_args
Summary:
Move breakpoints from the old, bad ArgInfo::count to the new, better
ArgInfo::max_positional_args.   Soon ArgInfo::count will be no more.

It looks like this functionality is already well tested by
`TestBreakpointCommandsFromPython.py`, so there's no need to write
additional tests for it.

Reviewers: labath, jingham, JDevlieghere

Reviewed By: labath

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D69468
2019-10-29 15:03:02 -07:00
Pavel Labath 7c603a41e2 lldb/minidump: Refactor memory region computation code
The goal of this refactor is to enable ProcessMinidump to take into
account the loaded modules and their sections when computing the
permissions of various ranges of memory, as discussed in D66638.

This patch moves some of the responsibility for computing the ranges
from MinidumpParser into ProcessMinidump. MinidumpParser still does the
parsing, but ProcessMinidump becomes responsible for answering the
actual queries about memory ranges. This will enable it (in a follow-up
patch) to augment the information obtained from the parser with data
obtained from actual object files.

The changes in the actual code are fairly straight-forward and just
involve moving code around. MinidumpParser::GetMemoryRegions is renamed
to BuildMemoryRegions to emphasize that it does no caching. The only new
thing is the additional bool flag returned from this function. This
indicates whether the returned regions describe all memory mapped into
the target process. Data obtained from /proc/maps and the MemoryInfoList
stream is considered to be exhaustive. Data obtained from Memory(64)List
is not. This will be used to determine whether we need to augment the
data or not.

This reshuffle means that it is no longer possible/easy to test some of
this code via unit tests, as constructing a ProcessMinidump instance is
hard. Instead, I update the unit tests to only test the parsing of the
actual data, and test the answering of queries through a lit test using
the "memory region" command. The patch also includes some tweaks to the
MemoryRegion class to make the unit tests easier to write.

Reviewers: amccarth, clayborg

Subscribers: lldb-commits

Differential Revision: https://reviews.llvm.org/D69035
2019-10-25 22:33:32 +00:00
Jim Ingham 738af7a624 Add the ability to pass extra args to a Python breakpoint callback.
For example, it is pretty easy to write a breakpoint command that implements "stop when my caller is Foo", and
    it is pretty easy to write a breakpoint command that implements "stop when my caller is Bar". But there's no
    way to write a generic "stop when my caller is..." function, and then specify the caller when you add the
    command to a breakpoint.

    With this patch, you can pass this data in a SBStructuredData dictionary. That will get stored in
    the PythonCommandBaton for the breakpoint, and passed to the implementation function (if it has the right
    signature) when the breakpoint is hit. Then in lldb, you can say:

    (lldb) break com add -F caller_is -k caller_name -v Foo

    More generally this will allow us to write reusable Python breakpoint commands.

    Differential Revision: https://reviews.llvm.org/D68671
2019-10-25 14:05:07 -07:00
Lawrence D'Anna d602e0d0ca fix PythonDataObjectsTest.TestExceptions on windows
Looks like on windows googlemock regexes treat newlines differently
from on darwin.    This patch fixes the regex in this test so it
will work on both.

Fixes: https://reviews.llvm.org/D69214
llvm-svn: 375477
2019-10-22 04:00:37 +00:00
Lawrence D'Anna 04edd1893c remove multi-argument form of PythonObject::Reset()
Summary:
With this patch, only the no-argument form of `Reset()` remains in
PythonDataObjects.   It also deletes PythonExceptionState in favor of
PythonException, because the only call-site of PythonExceptionState was
also using Reset, so I cleaned up both while I was there.

Reviewers: JDevlieghere, clayborg, labath, jingham

Reviewed By: labath

Subscribers: mgorny, lldb-commits

Tags: #lldb

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

llvm-svn: 375475
2019-10-22 02:32:37 +00:00
Adrian Prantl e57fe85a59 whitespace cleanup
llvm-svn: 375465
2019-10-21 22:48:27 +00:00
Adrian Prantl 667c2eb08b Factor out common test functionality into a helper class. (NFC)
llvm-svn: 375464
2019-10-21 22:46:53 +00:00
Lawrence D'Anna 722b618924 eliminate nontrivial Reset(...) from TypedPythonObject
Summary:
This deletes `Reset(...)`, except for the no-argument form `Reset()`
from `TypedPythonObject`, and therefore from `PythonString`, `PythonList`,
etc.

It updates the various callers to use assignment, `As<>`, `Take<>`,
and `Retain<>`, as appropriate.

followon to https://reviews.llvm.org/D69080

Reviewers: JDevlieghere, clayborg, labath, jingham

Reviewed By: labath

Subscribers: lldb-commits

Tags: #lldb

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

llvm-svn: 375350
2019-10-19 18:43:49 +00:00
Lawrence D'Anna 2386537c24 [LLDB] bugfix: command script add -f doesn't work for some callables
Summary:
When users define a debugger command from python, they provide a callable
object.   Because the signature of the function has been extended, LLDB
needs to inspect the number of parameters the callable can take.

The rule it was using to decide was weird, apparently not tested, and
giving wrong results for some kinds of python callables.

This patch replaces the weird rule with a simple one: if the callable can
take 5 arguments, it gets the 5 argument version of the signature.
Otherwise it gets the old 4 argument version.

It also adds tests with a bunch of different kinds of python callables
with both 4 and 5 arguments.

Reviewers: JDevlieghere, clayborg, labath, jingham

Reviewed By: labath

Subscribers: lldb-commits

Tags: #lldb

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

llvm-svn: 375333
2019-10-19 07:05:33 +00:00
Joseph Tremoulet d094d97d02 LLDB: Use LLVM's type for minidump ExceptionStream [NFC]
Summary: The types defined for it in LLDB are now redundant with core types.

Reviewers: labath, clayborg

Reviewed By: clayborg

Subscribers: lldb-commits

Tags: #lldb

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

llvm-svn: 375243
2019-10-18 14:59:10 +00:00
Lawrence D'Anna 03819d1c80 eliminate one form of PythonObject::Reset()
Summary:
I'd like to eliminate all forms of Reset() and all public constructors
on these objects, so the only way to make them is with Take<> and Retain<>
and the only way to copy or move them is with actual c++ copy, move, or
assignment.

This is a simple place to start.

Reviewers: JDevlieghere, clayborg, labath, jingham

Reviewed By: labath

Subscribers: lldb-commits

Tags: #lldb

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

llvm-svn: 375182
2019-10-17 22:22:09 +00:00
Lawrence D'Anna c86a6acaee clean up the implementation of PythonCallable::GetNumArguments
Summary:
The current implementation of PythonCallable::GetNumArguments
is not exception safe, has weird semantics, and is just plain
incorrect for some kinds of functions.

Python 3.3 introduces inspect.signature, which lets us easily
query for function signatures in a sane and documented way.

This patch leaves the old implementation in place for < 3.3,
but uses inspect.signature for modern pythons.   It also leaves
the old weird semantics in place, but with FIXMEs grousing about
it.   We should update the callers and fix the semantics in a
subsequent patch.    It also adds some tests.

Reviewers: JDevlieghere, clayborg, labath, jingham

Reviewed By: labath

Subscribers: lldb-commits

Tags: #lldb

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

llvm-svn: 375181
2019-10-17 22:22:06 +00:00
Adrian Prantl 3ebbda0f08 Adapt Windows test to API change.
llvm-svn: 375170
2019-10-17 20:51:55 +00:00
Adrian Prantl 1ad655e255 Modernize the rest of the Find.* API (NFC)
This patch removes the size_t return value and the append parameter
from the remainder of the Find.* functions in LLDB's internal API. As
in the previous patches, this is motivated by the fact that these
parameters aren't really used, and in the case of the append parameter
were frequently implemented incorrectly.

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

llvm-svn: 375160
2019-10-17 19:56:40 +00:00
Lawrence D'Anna 0f783599a4 delete SWIG typemaps for FILE*
Summary:
The SWIG typemaps for FILE* are no longer used, so
this patch deletes them.

Reviewers: JDevlieghere, jasonmolenda, labath

Reviewed By: labath

Subscribers: lldb-commits

Tags: #lldb

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

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


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

llvm-svn: 375032
2019-10-16 19:14:49 +00:00
Pavel Labath 458680ac78 minidump: Use yaml for memory info tests
Also, delete some minidump binary files that are no longer used in any
test.

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

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

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

Reviewers: JDevlieghere, teemperor, jingham

Subscribers: wallace, lldb-commits

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

llvm-svn: 374529
2019-10-11 10:56:54 +00:00
Aleksandr Urakov 30c2441a32 [Windows] Use information from the PE32 exceptions directory to construct unwind plans
This patch adds an implementation of unwinding using PE EH info. It allows to
get almost ideal call stacks on 64-bit Windows systems (except some epilogue
cases, but I believe that they can be fixed with unwind plan disassembly
augmentation in the future).

To achieve the goal the CallFrameInfo abstraction was made. It is based on the
DWARFCallFrameInfo class interface with a few changes to make it less
DWARF-specific.

To implement the new interface for PECOFF object files the class PECallFrameInfo
was written. It uses the next helper classes:

- UnwindCodesIterator helps to iterate through UnwindCode structures (and
  processes chained infos transparently);
- EHProgramBuilder with the use of UnwindCodesIterator constructs EHProgram;
- EHProgram is, by fact, a vector of EHInstructions. It creates an abstraction
  over the low-level unwind codes and simplifies work with them. It contains
  only the information that is relevant to unwinding in the unified form. Also
  the required unwind codes are read from the object file only once with it;
- EHProgramRange allows to take a range of EHProgram and to build an unwind row
  for it.

So, PECallFrameInfo builds the EHProgram with EHProgramBuilder, takes the ranges
corresponding to every offset in prologue and builds the rows of the resulted
unwind plan. The resulted plan covers the whole range of the function except the
epilogue.

Reviewers: jasonmolenda, asmith, amccarth, clayborg, JDevlieghere, stella.stamenova, labath, espindola

Reviewed By: jasonmolenda

Subscribers: leonid.mashinskiy, emaste, mgorny, aprantl, arichardson, MaskRay, lldb-commits, llvm-commits

Tags: #lldb

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

llvm-svn: 374528
2019-10-11 09:03:29 +00:00
Pavel Labath 5070322332 Fix the unwinding plan augmentation from x86 assembly
Unwind plan augmentation should compute the plan row at offset x from
the instruction before offset x, but currently we compute it from the
instruction at offset x. Note that this behavior is a regression
introduced when moving the x86 assembly inspection engine to its own
file
(1c9858b298 (diff-375a2be066db6f34bb9a71442c9b71fcL913));
the original version handled this properly by copying the previous
instruction out before advancing the instruction pointer.

The relevant bug with more info is here: https://bugs.llvm.org/show_bug.cgi?id=43561

Differential Revision: https://reviews.llvm.org/D68454
Patch by Jaroslav Sevcik <jarin@google.com>.

llvm-svn: 374342
2019-10-10 13:23:09 +00:00
Pavel Labath c8c71e6f76 Fix some dangling else warnings
EXPECT_EQ contains an if-else statement. It also contains some magic to
suppress the dangling else warnings, but it seems that some new
compilers can see through that...

llvm-svn: 374341
2019-10-10 13:23:02 +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
Raphael Isemann 7c47b4a113 [lldb][NFC] Use unique_ptr in DiagnosticManager to express ownership
llvm-svn: 374289
2019-10-10 08:30:10 +00:00
Greg Clayton dc9276b7d7 Set eRegisterKindEHFrame register numbers for 32 bit ARM register contexts in minidumps
Stack unwinding was sometimes failing when trying to unwind stacks in 32 bit ARM. I discovered this was because the EH frame register numbers were not set. This patch fixes this issue and adds a unit test to verify this doesn't regress.

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

llvm-svn: 374246
2019-10-09 22:16:12 +00:00
Adrian Prantl 939411c1aa Remove the is_mangled flag from Mangled and Symbol
Testing whether a name is mangled or not is extremely cheap and can be
done by looking at the first two characters. Mangled knows how to do
it. On the flip side, many call sites that currently pass in an
is_mangled determination do not know how to correctly do it (for
example, they leave out Swift mangling prefixes).

This patch removes this entry point and just forced Mangled to
determine the mangledness of a string itself.

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

llvm-svn: 374180
2019-10-09 16:22:14 +00:00
Antonio Afonso ad6690afa3 Explicitly set entry point arch when it's thumb [Second Try]
Summary:
This is a redo of D68069 because I reverted it due to some concerns that were now addressed along with the new comments that @labath added.

I found a case where the main android binary (app_process32) had thumb code at its entry point but no entry in the symbol table indicating this. This made lldb set a 4 byte breakpoint at that address (we default to arm code) instead of a 2 byte one (like we should for thumb).
The big deal with this is that the expression evaluator uses the entry point as a way to know when a JITed expression has finished executing by putting a breakpoint there. Because of this, evaluating expressions on certain android devices (Google Pixel something) made the process crash.
This was fixed by checking this specific situation when we parse the symbol table and add an artificial symbol for this 2 byte range and indicating that it's arm thumb.

I created 2 unit tests for this, one to check that now we know that the entry point is arm thumb, and the other to make sure we didn't change the behaviour for arm code.

I also run the following on the command line with the `app_process32` where I found the issue:
**Before:**
```
(lldb) dis -s 0x1640 -e 0x1644
app_process32[0x1640]: .long  0xf0004668                ; unknown opcode
```
**After:**
```
(lldb) dis -s 0x1640 -e 0x1644
app_process32`:
app_process32[0x1640] <+0>: mov    r0, sp
app_process32[0x1642]:      andeq  r0, r0, r0
```

Reviewers: clayborg, labath, wallace, espindola

Reviewed By: labath

Subscribers: labath, lldb-commits, MaskRay, kristof.beyls, arichardson, emaste, srhines

Tags: #lldb

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

llvm-svn: 374132
2019-10-08 23:44:49 +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
Jonas Devlieghere 37cf39df20 [CMake] Track test dependencies with add_lldb_test_dependency
I often use `ninja lldb-test-deps` to build all the test dependencies
before running a subset of the tests with `lit --filter`. This
functionality seems to break relatively often because test dependencies
are tracked in an ad-hoc way acrooss cmake files. This patch adds a
helper function `add_lldb_test_dependency` to unify test dependency
tracking by adding dependencies to lldb-test-deps.

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

llvm-svn: 373996
2019-10-08 00:21:34 +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
Antonio Afonso ae08e479aa Revert "Explicitly set entry point arch when it's thumb"
Backing out because SymbolFile/Breakpad/symtab.test is failing and it seems to be a legit issue. Will investigate.

This reverts commit 72153f95ee4c1b52d2f4f483f0ea4f650ec863be.

llvm-svn: 373687
2019-10-04 01:45:58 +00:00
Antonio Afonso ac14695804 Explicitly set entry point arch when it's thumb
Summary:
I found a case where the main android binary (app_process32) had thumb code at its entry point but no entry in the symbol table indicating this. This made lldb set a 4 byte breakpoint at that address (we default to arm code) instead of a 2 byte one (like we should for thumb).
The big deal with this is that the expression evaluator uses the entry point as a way to know when a JITed expression has finished executing by putting a breakpoint there. Because of this, evaluating expressions on certain android devices (Google Pixel something) made the process crash.
This was fixed by checking this specific situation when we parse the symbol table and add an artificial symbol for this 2 byte range and indicating that it's arm thumb.

I created 2 unit tests for this, one to check that now we know that the entry point is arm thumb, and the other to make sure we didn't change the behaviour for arm code.

I also run the following on the command line with the `app_process32` where I found the issue:
**Before:**
```
(lldb) dis -s 0x1640 -e 0x1644
app_process32[0x1640]: .long  0xf0004668                ; unknown opcode
```
**After:**
```
(lldb) dis -s 0x1640 -e 0x1644
app_process32`:
app_process32[0x1640] <+0>: mov    r0, sp
app_process32[0x1642]:      andeq  r0, r0, r0
```

Reviewers: clayborg, labath, wallace, espindola

Subscribers: srhines, emaste, arichardson, kristof.beyls, MaskRay, lldb-commits

Tags: #lldb

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

llvm-svn: 373680
2019-10-04 00:11:22 +00:00
Jim Ingham 27a14f19c8 Pass an SBStructuredData to scripted ThreadPlans on use.
This will allow us to write reusable scripted ThreadPlans, since
you can use key/value pairs with known keys in the plan to parametrize
its behavior.

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

llvm-svn: 373675
2019-10-03 22:50:18 +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
Lawrence D'Anna f913fd6eb0 factor out an abstract base class for File
Summary:
This patch factors out File as an abstract base
class and moves most of its actual functionality into
a subclass called NativeFile.   In the next patch,
I'm going to be adding subclasses of File that
don't necessarily have any connection to actual OS files,
so they will not inherit from NativeFile.

This patch was split out as a prerequisite for
https://reviews.llvm.org/D68188

Reviewers: JDevlieghere, jasonmolenda, labath

Reviewed By: labath

Subscribers: lldb-commits

Tags: #lldb

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

llvm-svn: 373564
2019-10-03 04:31:46 +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
Raphael Isemann 2eb963abff [lldb][NFC] Create the ASTContext in ClangASTContext exactly once.
Reason for this patch is the Ssame reason as for the previous patches:
Having a ClangASTContext and being able to switch the associated ASTContext isn't
a use case we have (or should have), so let's simplify all this code.
This way it becomes clearer in what order we initialize data structures.

The DWARFASTParserClangTests changes are necessary as the test is using
a ClangASTContext but relied on the fact that no called function ever calls
getASTContext() on our ClangASTContext (as that would create the ASTContext).
As we now always create the ASTContext the fact that we had an uninitialized
FileSystem made the test crash.

llvm-svn: 373457
2019-10-02 12:26:08 +00:00
Adrian Prantl e2385e089d Make yet another attempt in restoring SymbolFilePDBTests
The original test was passing false to the append argument of
FindTypes (the only use of this feature!). This patch now replicates
that by passing a fresh TypeMap into the function where applicable.

llvm-svn: 373409
2019-10-02 00:06:27 +00:00
Adrian Prantl f3d2158616 Make another attempt at fixing SymbolFilePDBTests.
llvm-svn: 373373
2019-10-01 18:15:22 +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
Adrian Prantl dffe5dfa5c Fix a syntax error.
llvm-svn: 373355
2019-10-01 17:10:25 +00:00
Adrian Prantl bf9d84c014 Remove size_t return parameter from FindTypes
In r368345 I accidentally introduced a regression that would
over-report the number of matches found by FindTypes if the
DeclContext Filter was hit.

This patch simply removes the size_t return parameter altogether —
it's not that useful.

rdar://problem/55500457

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

llvm-svn: 373344
2019-10-01 15:40:41 +00:00
Adrian Prantl b0ccef143a Try to update Windows unit test for API change.
llvm-svn: 373250
2019-09-30 19:38:52 +00:00
Pavel Labath 6f23a68a84 Use llvm for dumping DWARF expressions
Summary:
It uses the new ability of ABI plugins to vend llvm::MCRegisterInfo
structs (which is what is needed to turn dwarf register numbers into
strings).

Reviewers: JDevlieghere, aprantl, jasonmolenda

Subscribers: tatyana-krasnukha, lldb-commits

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

llvm-svn: 373208
2019-09-30 13:44:17 +00:00
Jim Ingham 93c98346e9 Give an error when StepUsingScriptedThreadPlan is passed a bad classname.
Differential Revision: https://reviews.llvm.org/D68173

llvm-svn: 373135
2019-09-28 00:53:45 +00:00
Jonas Devlieghere b0921daf02 [Reproducer] Use // in the unit tests
This should be a valid absolute path on both POSIX and Windows.

llvm-svn: 373124
2019-09-27 20:35:55 +00:00
Jonas Devlieghere 097ba75984 [Reproducer] Update the unit tests to specify the path style.
The unit tests started failing on Windows after my recent patch that
ensured we always deal with absolute paths. This should fix that.

llvm-svn: 373114
2019-09-27 19:12:18 +00:00
Lawrence D'Anna 2fce1137c7 Convert FileSystem::Open() to return Expected<FileUP>
Summary:
This patch converts FileSystem::Open from this prototype:

Status
Open(File &File, const FileSpec &file_spec, ...);

to this one:

llvm::Expected<std::unique_ptr<File>>
Open(const FileSpec &file_spec, ...);

This is beneficial on its own, as llvm::Expected is a more modern
and recommended error type than Status.  It is also a necessary step
towards https://reviews.llvm.org/D67891, and further developments
for lldb_private::File.

Reviewers: JDevlieghere, jasonmolenda, labath

Reviewed By: labath

Subscribers: mgorny, lldb-commits

Tags: #lldb

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

llvm-svn: 373003
2019-09-26 17:54:59 +00:00
Jonas Devlieghere 2660e55858 [CMake] Run the lldb-server tests with system debugserver.
Now that we no longer build debugserver when LLDB_USE_SYSTEM_DEBUGSERVER
is set, we have to change the logic for testing lldb-server.

llvm-svn: 372900
2019-09-25 17:12:59 +00:00
Raphael Isemann 823fd9508a [lldb][NFC] Add CompletionRequest::AppendEmptyArgument
This is the only legitimate use we currently have for modifying
a CompletionRequest. Add a utility function for this purpose
and remove the remaining setters which go against the idea of
having an immutable CompletionRequest.

llvm-svn: 372858
2019-09-25 12:40:01 +00:00
Jonas Devlieghere 7de14dc3c6 [unittest] Skip the socket tests if we $TMPDIR is too long.
Adrian added a sanity check to the socket tests to ensure the $TMPDIR is
not too long for a socket. While this is great for diagnosing the
problem it doesn't really solve the problem for environment where you
have no control over that variable such as in CI. I propose to just skip
the test in that case similar to what we do for tests that rely on
targets that are not currently build, etc.

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

llvm-svn: 372774
2019-09-24 19:34:50 +00:00
Pavel Labath 13a4e8f3ef Enhance SymbolFileDWARF::ParseDeclsForContext performance
This implements
DWARFASTParserClang::EnsureAllDIEsInDeclContextHaveBeenParsed so as to
provide a faster way to ensure all DIEs linked to a certain declaration
context have been parsed.

Currently, we rely on SymbolFileDWARF::ParseDeclsForContext calling
DWARFASTParserClang::GetDIEForDeclContext, and only then
DWARFASTParserClang::GetDeclForUIDFromDWARF. This change shortcuts that
logic and removes redundant calls to DWARFASTParserClang::
GetClangDeclForDIE by deleting DIEs from the m_decl_ctx_to_die map once
they have been parsed.

Differential Revision: https://reviews.llvm.org/D67760
Patch by Guilherme Andrade <guiandrade@google.com>.

llvm-svn: 372744
2019-09-24 12:36:54 +00:00
Raphael Isemann 1a2805b887 [lldb] Also force posix paths in CppModuleConfigurationTest
llvm-svn: 372737
2019-09-24 12:13:35 +00:00
Raphael Isemann 9379d19ff8 [lldb] Decouple importing the std C++ module from the way the program is compiled
Summary:
At the moment, when trying to import the `std` module in LLDB, we look at the imported modules used in the compiled program
and try to infer the Clang configuration we need from the DWARF module-import. That was the initial idea but turned out to
cause a few problems or inconveniences:

* It requires that users compile their programs with C++ modules. Given how experimental C++ modules are makes this feature inaccessible
for many users. Also it means that people can't just get the benefits of this feature for free when we activate it by default
(and we can't just close all the associated bug reports).
* Relying on DWARF's imported module tags (that are only emitted by default on macOS) means this can only be used when using DWARF (and with -glldb on Linux).
* We essentially hardcoded the C standard library paths on some platforms (Linux) or just couldn't support this feature on other platforms (macOS).

This patch drops the whole idea of looking at the imported module DWARF tags and instead just uses the support files of the compilation unit.
If we look at the support files and see file paths that indicate where the C standard library and libc++ are, we can just create the module
configuration this information. This fixes all the problems above which means we can enable all the tests now on Linux, macOS and with other debug information
than what we currently had. The only debug information specific code is now the iteration over external type module when -gmodules is used (as `std` and also the
`Darwin` module are their own external type module with their own files).

The meat of this patch is the CppModuleConfiguration which looks at the file paths from the compilation unit and then figures out the include paths
based on those paths. It's quite conservative in that it only enables modules if we find a single C library and single libc++ library. It's still missing some
test mode where we try to compile an expression before we actually activate the config for the user (which probably also needs some caching mechanism),
but for now it works and makes the feature usable.

Reviewers: aprantl, shafik, jdoerfert

Reviewed By: aprantl

Subscribers: mgorny, abidh, JDevlieghere, lldb-commits

Tags: #c_modules_in_lldb, #lldb

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

llvm-svn: 372716
2019-09-24 10:08:18 +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
Jonas Devlieghere 948786c929 File::SetDescriptor() should require options
lvm_private::File::GetStream() can fail if m_options == 0

It's not clear from the header a File created with a descriptor will be
not be usable by many parts of LLDB unless SetOptions is also called,
but it is.

This is because those parts of LLDB rely on GetStream() to use the
file, and that in turn relies on calling fdopen on the descriptor. When
calling fdopen, GetStream relies on m_options to determine the access
mode. If m_options has never been set, GetStream() will fail.

This patch adds options as a required argument to File::SetDescriptor
and the corresponding constructor.

Patch by: Lawrence D'Anna

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

llvm-svn: 372652
2019-09-23 20:36:46 +00:00
Jonas Devlieghere a7d186c796 [Host] File::GetWaitableHandle() should call fileno()
If the file has m_stream, it may not have a m_descriptor.
GetWaitableHandle() should call GetDescriptor(), which will call
fileno(), so it will get waitable descriptor whenever one is available.

Patch by: Lawrence D'Anna

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

llvm-svn: 372644
2019-09-23 19:34:26 +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
Raphael Isemann a2d81a375b [lldb][NFC] Make cursor char position unsigned in CompletionRequest
This was only an 'int' because to fit into the old API which is
gone by now.

llvm-svn: 372568
2019-09-23 09:51:36 +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
Raphael Isemann f8e733f149 [lldb] Reduce some dangerous boilerplate with CompletionRequest::ShiftArguments
We should in general not allow external code to fiddle with the internals of
CompletionRequest, but until this is gone let's at least provide a utility
function that makes this less dangerous.

This also now correct updates the partially parsed argument list,
but it doesn't seem to be used by anything that is behind one of
the current shift/SetCursorIndex calls, so this doesn't seeem to
fix any currently used completion.

llvm-svn: 372556
2019-09-23 08:16:19 +00:00
Raphael Isemann 7335197147 [lldb][NFC] Remove unused include in TestLineEntry.cpp
llvm-svn: 372381
2019-09-20 10:30:38 +00:00
Raphael Isemann 0d8a008611 [lldb] Remove SetCount/ClearCount from Flags
Summary:
These functions are only used in tests where we should test the actual flag values instead of counting all bits for an approximate check.
Also these popcount implementation aren't very efficient and doesn't seem to be optimised to anything fast.

Reviewers: davide, JDevlieghere

Reviewed By: davide, JDevlieghere

Subscribers: abidh, JDevlieghere, lldb-commits

Tags: #lldb

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

llvm-svn: 372018
2019-09-16 18:02:49 +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
George Rimar 69ba3defaf [lldb] - Update unit tests after lib/ObjectYAML change.
An update after r371865

llvm-svn: 371866
2019-09-13 16:00:28 +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 9703f46fc1 [lldb][NFC] Sort files in unittests/Expression/CMakeLists.txt
llvm-svn: 371614
2019-09-11 12:57:49 +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
Jonas Devlieghere e0ea8d87eb [Utility] Replace `lldb_private::CleanUp` by `llvm::scope_exit`
This removes the CleanUp class and replaces its usages with llvm's
ScopeExit, which has similar semantics.

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

llvm-svn: 371474
2019-09-10 00:20:50 +00:00
Raphael Isemann 0d50c4e060 [lldb][NFC] Extend ArgsTest
llvm-svn: 371180
2019-09-06 08:39:53 +00:00
Pavel Labath f07b4aff06 Fix GetDIEForDeclContext so it only returns entries matching the provided context
Currently, we return all the entries such that their decl_ctx pointer >= decl_ctx provided.
Instead, we should return only the ones that decl_ctx pointer == decl_ctx provided.

Differential Revision: https://reviews.llvm.org/D66357
Patch by Guilherme Andrade <guiandrade@google.com>.

llvm-svn: 370374
2019-08-29 15:30:52 +00:00
Pavel Labath e588b8b664 DWARFExpression: Simplify class interface
Summary:
The DWARFExpression methods have a lot of arguments. This removes two of
them by removing the ability to slice the expression via two offset+size
parameters. This is a functionality that it is not always needed, and
when it is, we already have a different handy way of slicing a data
extractor which we can use instead.

Reviewers: JDevlieghere, clayborg

Subscribers: aprantl, lldb-commits

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

llvm-svn: 370027
2019-08-27 07:49:41 +00:00
Pavel Labath b54efd28c4 Move ProcessInstanceInfoTest to Utility
The class under test was moved in r355342. This moves the test code too.

llvm-svn: 369907
2019-08-26 13:07:02 +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
Pavel Labath f899bf135f Fix windows build after r369894
Constructing a std::vector from a llvm::map_range fails on windows,
apparently because std::vector expects the input iterator to have a
const operator* (map_range iterator has a non-const one).

This avoids the cleverness and unrolls the map-loop manually (which is
also slightly shorter).

llvm-svn: 369905
2019-08-26 12:42:32 +00:00
Pavel Labath c7deb7f808 Postfix: move more code out of the PDB plugin
Summary:
Previously we moved the code which parses a single expression out of the PDB
plugin, because that was useful for DWARF expressions in breakpad. However, FPO
programs are used in breakpad files too (when unwinding on windows), so this
completes the job, and moves the rest of the FPO parser too.

Reviewers: amccarth, aleksandr.urakov

Subscribers: aprantl, markmentovai, rnk, lldb-commits

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

llvm-svn: 369894
2019-08-26 11:44:14 +00:00
Pavel Labath 0a9f47d7cc Breakpad: Add support for parsing STACK WIN records
Summary: The fields that aren't useful for us right now are simply ignored.

Reviewers: amccarth, markmentovai

Subscribers: rnk, lldb-commits

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

llvm-svn: 369892
2019-08-26 11:25:28 +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
Adrian Prantl 330ae19a1a Generalize FindTypes with CompilerContext to support fuzzy lookup
This patch generalizes the FindTypes with CompilerContext interface to
support looking up a type of unknown kind by name, as well as looking
up a type inside an unspecified submodule. These features are
motivated by the Swift branch, but are fully tested via unit tests and
lldb-test on llvm.org.  Specifically, this patch adds an AnyModule and
an AnyType CompilerContext kind.

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

rdar://problem/54471165

llvm-svn: 369555
2019-08-21 18:06:56 +00:00
Pavel Labath dc5403d2dc Properly EXCLUDE_FROM_ALL the testing support library
The EXCLUDE_FROM_ALL variable is used by add_llvm_library, but lldb does
not use that function (it uses llvm_add_library :P). Instead, set the directory
property with the same name directly.

This should fix standalone builds against an llvm install tree.

llvm-svn: 369502
2019-08-21 08:21:51 +00:00
Jonas Devlieghere d35b42f20a [NFC] Return llvm::StringRef from StringExtractor::GetStringRef.
This patch removes the two variant of StringExtractor::GetStringRef that
return (non-)const references to std::string. The non-const one was
being abused to reinitialize the StringExtractor and its uses are
replaced by calls to the copy asignment operator. The const variant was
refactored to return an actual llvm::StringRef.

llvm-svn: 369493
2019-08-21 04:55:56 +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
Pavel Labath 028fe5af60 Fix build for r369374
This patch added some gtest code to the TestingSupport library. As this
is not a unit test, but a unit test library, gtest does not get added to
the include path automatically, but we have to do that ourselves. (It
was working for me without this because the compiler picked up the
system gtest instead.)

llvm-svn: 369381
2019-08-20 13:17:20 +00:00
Pavel Labath 5877fb7cd7 Convert minidump unittests to use llvm::yaml::convertYAML
previously they used a minidump-specific function for this purpose, but
this is no longer needed now that whole of yaml2obj is available as a
library.

llvm-svn: 369379
2019-08-20 12:53:42 +00:00
Pavel Labath a2e270fa70 unittests: Use yaml2obj as a library instead of an external process
Summary:
Recently, yaml2obj has been turned into a library. This means we can use
it from our unit tests directly, instead of shelling out to an external
process. This patch does just that.

Reviewers: JDevlieghere, aadsm, espindola, jdoerfert

Subscribers: emaste, mgorny, arichardson, MaskRay, jhenderson, abrachet, lldb-commits

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

llvm-svn: 369374
2019-08-20 12:28:36 +00:00
Raphael Isemann 6632ad5851 [lldb][NFC] Stop using GetNumberOfMatches in CompletionRequest test
This function is just a wrapper for GetNumberOfResults and will
be removed soon. This patch just changes all calls to GetNumberOfResults
where possible (which is currently just the unit test).

llvm-svn: 369267
2019-08-19 14:52:48 +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
Aaron Smith 5032c6ea08 [lldb-server] Disable a test on Windows until it can be fixed
llvm-svn: 369083
2019-08-16 03:49:41 +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
Aaron Smith 5146a9ea5d Initial support for native debugging of x86/x64 Windows processes
Summary: Thanks to Hui Huang and the reviewers for all the help with this patch.

Reviewers: labath, Hui, jfb, clayborg, amccarth

Reviewed By: labath

Subscribers: amccarth, compnerd, dexonsmith, mgorny, jfb, teemperor, lldb-commits

Tags: #lldb

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

llvm-svn: 368759
2019-08-13 22:18:01 +00:00
Alex Langford bddab07d4a [Symbol] Decouple clang from CompilerType
Summary:
Ideally CompilerType would have no knowledge of clang or any individual
TypeSystem. Decoupling clang is relatively straightforward.

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

llvm-svn: 368741
2019-08-13 19:40:36 +00:00
Raphael Isemann 5028654214 [lldb][NFC] Add unit test for lldb_private::DiagnosticManager
llvm-svn: 368567
2019-08-12 13:31:45 +00:00
Pavel Labath 88c77d6752 ObjectFileELF: Convert a unit test to a lit test
It is much easier to test this functionality via lldb-test.

llvm-svn: 368289
2019-08-08 12:57:46 +00:00
Pavel Labath 6db975b7b8 Add a missing include to SymbolFilePDBTests.cpp
This should _really_ fix the pdb unit tests.

llvm-svn: 368271
2019-08-08 09:43:20 +00:00
Pavel Labath 959e603456 Fix PDB unit tests for the GetSymbolVendor deletion
llvm-svn: 368265
2019-08-08 08:22:26 +00:00
Jonas Devlieghere af0c828a1e [ExecutionContext] Return the target/process byte order.
Currently ExecutionContext::GetByteOrder() always returns the host byte
order. This seems like a simple mistake: the return keyword appears to
have been omitted by accident. This patch fixes that and adds a unit
test.

Bugreport: https://llvm.org/PR37950

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

llvm-svn: 368181
2019-08-07 16:09:35 +00:00
Pavel Labath 465eae3669 SymbolVendor: Remove passthrough methods
After the recent refactorings the SymbolVendor passthrough no longer
serve any purpose. This patch removes those methods, and updates all
callsites to go to the symbol file directly -- in most cases that just
means calling GetSymbolFile()->foo() instead of
GetSymbolVendor()->foo().

llvm-svn: 368001
2019-08-06 09:12:42 +00:00
Pavel Labath 3a3ca963be Add missing includes to SymbolFilePDBTests
These became needed after r367368.

llvm-svn: 367410
2019-07-31 11:31:05 +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 Langford c1210c7e96 [SymbolFilePDB] Fix windows bots after rL367360
SymbolFilePDB tests were using GetTypeSystemForLanguage but weren't
changed to accomodate the use of an llvm::Expected. I adjusted them
accordingly.

llvm-svn: 367368
2019-07-30 23:48:03 +00:00
Pavel Labath 84a6856928 SymbolVendor: Move Symtab construction into the SymbolFile
Summary:
Instead of having SymbolVendor coordinate Symtab construction between
Symbol and Object files, make the SymbolVendor function a passthrough,
and put all of the logic into the SymbolFile.

Reviewers: clayborg, JDevlieghere, jingham, espindola

Subscribers: emaste, mgorny, arichardson, MaskRay, lldb-commits

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

llvm-svn: 367086
2019-07-26 07:03:28 +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
Antonio Afonso 70795c1e3a Revert "Revert "Add ReadCStringFromMemory for faster string reads""
This reverts commit 9c10b620c0.

llvm-svn: 366848
2019-07-23 20:40:37 +00:00
Stefan Granitz fc0d766511 [CMake] Align debugserver with lldb-server on Darwin
Summary: Make debugserver a tool like lldb-server, so it can be included/excluded via `LLDB_TOOL_DEBUGSERVER_BUILD`. This replaces the old `LLDB_NO_DEBUGSERVER` flag. Doing the same for darwin-debug while I am here.

Reviewers: xiaobai, JDevlieghere, davide

Reviewed By: xiaobai, JDevlieghere

Subscribers: mgorny, lldb-commits, #lldb

Tags: #lldb

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

llvm-svn: 366631
2019-07-20 11:18:31 +00:00
Jonas Devlieghere 37fed66402 [LLDB] Remove lldb-mi
As discussed on the mailing list [1], this patch removes the lldb-mi
tool and its tests from the LLDB repository. We moved lldb-mi into a
separate repository on GitHub [2] for downstream users or maintainers to
build and package.

[1] http://lists.llvm.org/pipermail/lldb-dev/2019-July/015103.html
[2] https://github.com/lldb-tools/lldb-mi

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

llvm-svn: 366465
2019-07-18 17:06:06 +00:00
Stefan Granitz 0c4948455d [CMake] Always build debugserver on Darwin and allow tests to use the system's one
Summary:
We can always build debugserver, but we can't always sign it to be useable for testing. `LLDB_USE_SYSTEM_DEBUGSERVER` should only tell whether or not the system debugserver should be used for testing.
The old behavior complicated the logic around debugserver a lot. The new logic sorts out most of it.

Please note that this patch is in early stage and needs some more testing. It should not affect platfroms other than Darwin. It builds on Davide's approach to validate the code-signing identity at configuration time.

What do you think?

Reviewers: xiaobai, JDevlieghere, davide, compnerd, friss, labath, mgorny, jasonmolenda

Reviewed By: JDevlieghere

Subscribers: lldb-commits, #lldb

Tags: #lldb

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

llvm-svn: 366433
2019-07-18 13:30:37 +00:00
Adrian Prantl 3b4a667854 Add a sanity check to the domain socket tests.
rdar://problem/52062631

llvm-svn: 364562
2019-06-27 16:45:23 +00:00