Commit Graph

1084 Commits

Author SHA1 Message Date
Xing GUO 0431e4bcb2 Recommit "[DWARFYAML][debug_line] Replace `InitialLength` with `Format` and `Length`."
This recommits fcc0c186e9
2020-06-13 23:39:11 +08:00
Jonas Devlieghere 8f9eb70353 [lldb/Test] Fix unit test suffixes and add a CMake error.
Lit will only look for unittest targets ending in `Tests`. Add an error
when the target doesn't have the `Tests` suffix.
2020-06-12 14:18:27 -07:00
Jonas Devlieghere bfea1df9f0 [lldb/Test] Fix unittest name
Lit looks for the Tests prefix in the unit test name.
2020-06-12 14:01:14 -07:00
Ilya Bukonkin 3b43f00629 [lldb] Check if thread was suspended during previous stop added.
Encountered the following situation: Let we started thread T1 and it hit
breakpoint on B1 location. We suspended T1 and continued the process.
Then we started thread T2 which hit for example the same location B1.
This time in a breakpoint callback we decided not to stop returning
false.

Expected result: process continues (as if T2 did not hit breakpoint) its
workflow with T1 still suspended. Actual result: process do stops (as if
T2 callback returned true).

Solution: We need invalidate StopInfo for threads that was previously
suspended just because something that is already inactive can not be the
reason of stop. Thread::GetPrivateStopInfo() may be appropriate place to
do it, because it gets called (through Thread::GetStopInfo()) every time
before process reports stop and user gets chance to change
m_resume_state again i.e if we see m_resume_state == eStateSuspended
it definitely means it was set during previous stop and it also means
this thread can not be stopped again (cos' it was frozen during
previous stop).

Differential revision: https://reviews.llvm.org/D80112
2020-06-11 15:02:46 -07:00
Jonas Devlieghere de019b88dd [lldb/Interpreter] Support color in CommandReturnObject
Color the error: and warning: part of the CommandReturnObject output,
similar to how an error is printed from the driver when colors are
enabled.

Differential revision: https://reviews.llvm.org/D81058
2020-06-09 10:45:45 -07:00
Pavel Labath 731fee8b42 [lldb] Fail evaluation of DWARF expressions with unknown opcodes
Previously, we were simply ignoring them and continuing the evaluation.
This behavior does not seem useful, because the resulting value will
most likely be completely bogus.
2020-06-08 15:52:28 +02:00
Pavel Labath 4c50cf9197 [lldb] Fix YAMLModuleTester for the rename in 67b4afc4 2020-06-08 13:34:03 +02:00
Jaroslav Sevcik 1beffc1888 Support build-ids of other sizes than 16 in UUID::SetFromStringRef
SBTarget::AddModule currently handles the UUID parameter in a very
weird way: UUIDs with more than 16 bytes are trimmed to 16 bytes. On
the other hand, shorter-than-16-bytes UUIDs are completely ignored. In
this patch, we change the parsing code to handle UUIDs of arbitrary
size.

To support arbitrary size UUIDs in SBTarget::AddModule, this patch
changes UUID::SetFromStringRef to parse UUIDs of arbitrary length. We
subtly change the semantics of SetFromStringRef - SetFromStringRef now
only succeeds if the entire input is consumed to prevent some
prefix-parsing confusion. This is up for discussion, but I believe
this is more consistent - we always return false for invalid UUIDs
rather than sometimes truncating to a valid prefix. Also, all the
call-sites except the API and interpreter seem to expect to consume
the entire input.

This also adds tests for adding existing modules 4-, 16-, and 20-byte
build-ids. Finally, we took the liberty of testing the minidump
scenario we care about - removing placeholder module from minidump and
replacing it with the real module.

Reviewed By: labath, friss

Differential Revision: https://reviews.llvm.org/D80755
2020-06-07 10:03:41 +00:00
Adrian Prantl 3d7b926dd1 Move GetXcode*Directory into HostInfo (NFC)
These functions really don't belong into PlatformDarwin, since they
actualy query state of the Host and not of the remote platform.
2020-06-05 11:59:22 -07:00
Jan Kratochvil 476f520a0b [lldb] Fix SLEB128 decoding
Bug 46181 shows SLEB128 0xED9A924C00011151 decoded as 0xffffffff80011151.
        LLDB show a wrong value for function argument
        https://bugs.llvm.org/show_bug.cgi?id=46181

Differential Revision: https://reviews.llvm.org/D81119
2020-06-04 19:41:24 +02:00
Vedant Kumar 4699a7e230 [lldb/StringPrinter] Support strings with invalid utf8 sub-sequences
Support printing strings which contain invalid utf8 sub-sequences, e.g.
strings like "hello world \xfe", instead of bailing out with "Summary
Unavailable".

I took the opportunity here to delete some hand-rolled utf8 -> utf32
conversion code and replace it with calls into llvm's Support library.

rdar://61554346
2020-06-03 12:24:23 -07:00
Andy Yankovsky 798644e0a4 [Scalar] Fix assignment operator for long long.
Summary:
Assignment operator `operator=(long long)` currently allocates `sizeof(long)`.
On some platforms it works as they have `sizeof(long) == sizeof(long long)`,
but on others (e.g. Windows) it's not the case.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D80995
2020-06-03 13:26:25 +02:00
Adrian Prantl a0b674fd7f Fix UB in EmulateInstructionARM64.cpp
This fixes an unhandled signed integer overflow in AddWithCarry() by
using the llvm::checkedAdd() function. Thats to Vedant Kumar for the
suggestion!

<rdar://problem/60926115>

Differential Revision: https://reviews.llvm.org/D80955
2020-06-01 18:11:50 -07:00
Emre Kultursay 7ff2de4f0c Do not list adb devices when a device id is given
Summary:
On Android, this method gets called twice: first when establishing
a host-server connection, then when attaching to a process id.

Each call takes several seconds to finish (especially slower on Windows)
and eliminating the call for the typical case improves latency significantly.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D79586
2020-05-29 11:36:11 +02:00
Raphael Isemann 019bd6485c [lldb] Don't complete ObjCInterfaceDecls in ClangExternalASTSourceCallbacks::FindExternalVisibleDeclsByName
Summary:
For ObjCInterfaceDecls, LLDB iterates over the `methods` of the interface in FindExternalVisibleDeclsByName
since commit ef423a3ba5 .
However, when LLDB calls `oid->methods()` in that function, Clang will pull in all declarations in the current
DeclContext from the current ExternalASTSource (which is again, `ClangExternalASTSourceCallbacks`). The
reason for that is that `methods()` is just a wrapper for `decls()` which is supposed to provide a list of *all*
(both currently loaded and external) decls in the DeclContext.

However, `ClangExternalASTSourceCallbacks::FindExternalLexicalDecls` doesn't implement support for ObjCInterfaceDecl,
so we don't actually add any declarations and just mark the ObjCInterfaceDecl as having no ExternalLexicalStorage.

As LLDB uses the ExternalLexicalStorage to see if it can complete a type with the ExternalASTSource, this causes
that LLDB thinks our class can't be completed any further by the ExternalASTSource
and will from on no longer make any CompleteType/FindExternalLexicalDecls calls to that decl. This essentially
renders those types unusable in the expression parser as they will always be considered incomplete.

This patch just changes the call to `methods` (which is just a `decls()` wrapper), to some ad-hoc `noload_methods`
call which is wrapping `noload_decls()`. `noload_decls()` won't trigger any calls to the ExternalASTSource, so
this prevents that ExternalLexicalStorage will be set to false.

The test for this is just adding a method to an ObjC interface. Before this patch, this unset the ExternalLexicalStorage
flag and put the interface into the state described above.

In a normal user session this situation was triggered by setting a breakpoint in a method of some ObjC class. This
caused LLDB to create the MethodDecl for that specific method and put it into the the ObjCInterfaceDecl.
Also `ObjCLanguageRuntime::LookupInCompleteClassCache` needs to be unable to resolve the type do
an actual definition when the breakpoint is set (I'm not sure how exactly this can happen, but we just
found no Type instance that had the `TypePayloadClang::IsCompleteObjCClass` flag set in its payload in
the situation where this happens. This however doesn't seem to be a regression as logic wasn't changed
from what I can see).

The module-ownership.mm test had to be changed as the only reason why the ObjC interface in that test had
it's ExternalLexicalStorage flag set to false was because of this unintended side effect. What actually happens
in the test is that ExternalLexicalStorage is first set to false in `DWARFASTParserClang::CompleteTypeFromDWARF`
when we try to complete the `SomeClass` interface, but is then the flag is set back to true once we add
the last ivar of `SomeClass` (see `SetMemberOwningModule` in `TypeSystemClang.cpp` which is called
when we add the ivar). I'll fix the code for that in a follow-up patch.

I think some of the code here needs some rethinking. LLDB and Clang shouldn't infer anything about the ExternalASTSource
and its ability to complete the current type form the `ExternalLexicalStorage` flag. We probably should
also actually provide any declarations when we get asked for the lexical decls of an ObjCInterfaceDecl. But both of those
changes are bigger (and most likely would cause us to eagerly complete more types), so those will be follow up patches
and this patch just brings us back to the state before commit ef423a3ba5 .

Fixes rdar://63584164

Reviewers: aprantl, friss, shafik

Reviewed By: aprantl, shafik

Subscribers: arphaman, abidh, JDevlieghere

Differential Revision: https://reviews.llvm.org/D80556
2020-05-27 12:39:24 +02:00
Pavel Labath ba03bcbc4a [lldb] Remove custom DWARF expression printing code
The llvm DWARFExpression dump is nearly identical, but better -- for
example it does print a spurious space after zero-argument expressions.

Some parts of our code (variable locations) have been already switched
to llvm-based expression dumping. This switches the remainder: unwind
plans and some unit tests.
2020-05-25 16:09:25 +02:00
Jonas Devlieghere a67b2faa7c [lldb/Test] Disable APITests.exe on Windows
The generated binary (APITests.exe) is not a valid googletest binary. I
suspect it has something to do with us linking against liblldb.
2020-05-22 13:07:10 -07:00
Dmitri Gribenko 8214eff467 Revert "[lldb/DataFormatter] Check for overflow when finding NSDate epoch"
This reverts commit b783f70a42. This
change had multiple issues which required post-commit fixups, and not
all issues are fixed yet. In particular, the LLDB build bot for ARM is
still broken. There is also an ongoing conversation in the original
phabricator review about whether there is undefined behavior in the
code.
2020-05-20 12:44:19 +02:00
Dmitri Gribenko 0f1195a586 Revert "[lldb/test] Relax NSDate mock test for non-Apple platforms"
This reverts commit fff3a8464d. It is a
follow-up to b783f70a42, which I'm
reverting -- see the explanation in that revert.
2020-05-20 12:44:19 +02:00
Dmitri Gribenko f67f9e86e8 Revert "[lldb/test] Disable NSDate format check under _WIN32"
This reverts commit e3aa4cd9db. It is a
follow-up to b783f70a42, which I'm
reverting -- see the explanation in that revert.
2020-05-20 12:44:19 +02:00
Dmitri Gribenko 23f29b2fcc Revert "Silence warnings around int/float conversions."
This reverts commit 15ee8a3a58. It is a
follow-up to b783f70a42, which I'm
reverting -- see the explanation in that revert.
2020-05-20 12:44:19 +02:00
Dmitri Gribenko 79fcd35c68 Revert "[lldb/test] Move "DataFormatters/Mock.h" to "Plugins/Language/ObjC/Utilities.h""
This reverts commit 82dbf4aca8. It is a
follow-up to b783f70a42, which I'm
reverting -- see the explanation in that revert.
2020-05-20 12:44:18 +02:00
Vedant Kumar 82dbf4aca8 [lldb/test] Move "DataFormatters/Mock.h" to "Plugins/Language/ObjC/Utilities.h"
This addresses some post-commit review feedback from
https://reviews.llvm.org/D80150 by renaming "Mock.h" to something less
misleading, and keeping logic related to the ObjC plugin separate from
the generic DataFormatters library.
2020-05-19 16:09:42 -07:00
Eric Christopher 15ee8a3a58 Silence warnings around int/float conversions. 2020-05-19 10:56:18 -07:00
Vedant Kumar e3aa4cd9db [lldb/test] Disable NSDate format check under _WIN32
Disable the test which attempts to format an NSDate with a date_value of
0 on _WIN32.

When _WIN32 is defined, GetOSXEpoch returns a date that should be in
2001, but after this is passed through timegm (which, afaict isn't
portable?) the result is a date in 1970:

```
lldb-x64-windows-ninja\llvm-project\lldb\unittests\DataFormatter\MockTests.cpp(39): error:       Expected: *formatDateValue(0)
      Which is: "1970-01-01 00:00:00 Pacific Standard Time"
      To be equal to: "2001-01-01 00:00:00 UTC"
```

http://lab.llvm.org:8011/builders/lldb-aarch64-ubuntu/builds/4520/steps/test/logs/stdio
2020-05-18 16:51:47 -07:00
Vedant Kumar fff3a8464d [lldb/test] Relax NSDate mock test for non-Apple platforms
On Ubuntu, a formatted date prints as "GMT" instead of "UTC", which is
ok.

http://lab.llvm.org:8011/builders/lldb-aarch64-ubuntu/builds/4520/steps/test/logs/stdio
2020-05-18 16:00:10 -07:00
Vedant Kumar b783f70a42 [lldb/DataFormatter] Check for overflow when finding NSDate epoch
Summary:
Fixes UBSan-reported issues where the date value inside of an
uninitialized NSDate overflows the 64-bit epoch.

rdar://61774575

Reviewers: JDevlieghere, mib, teemperor

Subscribers: mgorny, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D80150
2020-05-18 13:12:00 -07:00
Levon Ter-Grigoryan 631048e811 Moving executable module symbols parsing to target creation method.
Summary:
In our project we are using remote client-server LLDB configuration.
We want to parse as much debugging symbols as we can before debugger starts attachment to the remote process.
To do that we are passing the path of the local executable module to CreateTarget method at the client.
But, it seems that this method are not parsing the executable module symbols.
To fix this I added PreloadSymbols call for executable module to target creation method.

This patch also fixes a problem where the DynamicLoader would reset a
module when launching the target. We fix it by making sure
Platform::ResolveExecutable returns the module object obtained from the
remote platform.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D78654
2020-05-14 16:54:14 +02:00
Jonas Devlieghere bad61548b2 [Reproducers] Serialize process arguments in ProcessInfo
While debugging why TestProcessList.py failed during passive replay, I
remembered that we don't serialize the arguments for ProcessInfo. This
is necessary to make the test pass and to make platform process list -v
behave the same during capture and replay.

Differential revision: https://reviews.llvm.org/D79646
2020-05-12 11:12:37 -07:00
Lawrence D'Anna 52712d3ff7 Re-land "get rid of PythonInteger::GetInteger()"
This was reverted due to a python2-specific bug.  Re-landing with a fix
for python2.

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, omjavaid

Reviewed By: labath, omjavaid

Subscribers: omjavaid, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D78462
2020-05-08 10:57:10 -07:00
Adrian Prantl ae920a81ff Add an API to construct an XcodeSDK from an SDK type.
Also, this moves numSDKs out of the actual enum, as to not mess with
the switch-cases-covered warning.

Differential Revision: https://reviews.llvm.org/D79603
2020-05-08 10:47:13 -07:00
Adrian Prantl dec1c94e80 Add a function to detect whether an Xcode SDK supports Swift
Differential Revision: https://reviews.llvm.org/D79535
2020-05-07 11:29:31 -07:00
Adrian Prantl 6e95d51ecf Add an XcodeSDK::GetSDKTypeForTriple function
This is something used in swift-lldb, but of general usefulness.

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

<rdar://problem/62684906>
2020-05-07 11:12:42 -07:00
Adrian Prantl 01fc85dc96 ParseXcodeSDK: Register both the CU module and the SymbolFile module.
For Swift LLDB (but potentially also for module support in Clang-land)
we need a way to accumulate the path remappings produced by
Module::RegisterXcodeSDK(). In order to make this work for
SymbolFileDebugMaps, registering the search path remapping with both
modules is necessary.

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

<rdar://problem/62750529>
2020-05-06 16:46:22 -07:00
Adrian Prantl f0c08b7eac Move the Xcode SDK path caching to HostInfo
When debugging a remote platform, the platform you get from
GetPlatformForArchitecture doesn't inherit from PlatformDarwin.
HostInfoMacOSX seems like the right place to have a global store of
local paths.

Differential Revision: https://reviews.llvm.org/D79364
2020-05-06 13:43:50 -07:00
Adrian Prantl 5935227e11 Add an explicit API to read the Xcode SDK DWARF attribute from compile units
When debugging from a SymbolMap the creation of CompileUnits for the
individual object files is so lazy that RegisterXcodeSDK() is not
invoked at all before the Swift TypeSystem wants to read it. This
patch fixes this by introducing an explicit
SymbolFile::ParseXcodeSDK() call that can be invoked deterministically
before the result is required.

<rdar://problem/62532151+62326862>

https://reviews.llvm.org/D79273
2020-05-06 13:16:16 -07:00
Vedant Kumar c05f35443c [lldb/unittest] Avoid relying on compiler character encoding in unicode test
This is a speculative fix for a unit test failure on a Win/MSVC2017 bot
(http://lab.llvm.org:8011/builders/lldb-x64-windows-ninja/builds/16106/steps/test/logs/stdio).
2020-05-05 09:18:35 -07:00
Reid Kleckner 58c7bf246e Update LLDB filespec tests for remove_dots change
It looks like the new implementation is correct, since there were TODOs
here about getting the new behavior.

I am not sure if "C:..\.." should become "C:" or "C:\", though. The new
output doesn't precisely match the TODO message, but it seems
appropriate given the specification of remove_dots and how .. traversals
work at the root directory.
2020-05-04 17:27:16 -07:00
Vedant Kumar a37caebc2d [lldb/DataFormatters] Delete GetStringPrinterEscapingHelper
Summary:
Languages can have different ways of formatting special characters.
E.g. when debugging C++ code a string might look like "\b", but when
debugging Swift code the same string would look like "\u{8}".

To make this work, plugins override GetStringPrinterEscapingHelper.
However, because there's a large amount of subtly divergent work done in
each override, we end up with large amounts of duplicated code. And all
the memory smashers fixed in one copy of the logic (see D73860) don't
get fixed in the others.

IMO the GetStringPrinterEscapingHelper is overly general and hard to
use. I propose deleting it and replacing it with an EscapeStyle enum,
which can be set as needed by each plugin.

A fix for some swift-lldb memory smashers falls out fairly naturally
from this deletion (https://github.com/apple/llvm-project/pull/1046). As
the swift logic becomes really tiny, I propose moving it upstream as
part of this change. I've added unit tests to cover it.

rdar://61419673

Reviewers: JDevlieghere, davide

Subscribers: mgorny, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D77843
2020-05-04 14:06:55 -07:00
Jonas Devlieghere 8539588783 [lldb/CMake] Set the PYTHON_RPATH for the unit tests
The API and Python script interpreter unit tests also link against
Python and therefore need to set the RPATH when applicable.
2020-04-30 11:05:50 -07:00
Pavel Labath f07f2cee9b [lldb/unittest] Adjust CheckIPSupport function to avoid double-consume of llvm::Error
The problem caught by clang-tidy and reported by Tobias Bosch.
2020-04-28 13:35:07 +02:00
Pavel Labath 18e96a31fe [lldb/unittests] Skip IPv6 test on systems which don't have IPv6 configured
Sadly IPv6 is still not present anywhere. The test was attempting to
detect&skip such hosts, but the way it did that (essentially, by calling
getaddrinfo) meant that it only detected hosts which have IPv6 support
completely compiled out. It did not do anything about hosts which have
it compiled in, but lack runtime configuration even for the ::1 loopback
address.

This patch changes the detection logic to use a new method. It does it
by attempting to bind a socket to the appropriate loopback address. That
should ensure the hosts loopback interface is fully set up. In an effort
to avoid silently skipping the test on too many hosts, the test is
fairly strict about the kind of error it expects in these cases -- it
will only skip the test when receiving EADDRNOTAVAIL. If we find other
error codes that can be reasonably returned in these situations, we can
add more of them.

The (small) change in TCPSocket.cpp is to ensure that the code correctly
propagates the error received from the OS.
2020-04-27 17:33:20 +02:00
Adrian Prantl a0919ac080 Invert an #ifdef in XcodeSDKModuleTests.cpp and actually make the test work. 2020-04-24 18:39:40 -07:00
Adrian Prantl 06e4f69b22 Add a getter to retrieve the XcodeSDK from Module and unit-test it. (NFC)
This API is used by swift-lldb.

(Recommit with missing file git-added)
2020-04-24 17:00:34 -07:00
Adrian Prantl af015c1a33 Revert "Add a getter to retrieve the XcodeSDK from Module and unit-test it. (NFC)"
This reverts commit 345df863ce.

(Forgot to git-add the new file)
2020-04-24 16:59:48 -07:00
Adrian Prantl 345df863ce Add a getter to retrieve the XcodeSDK from Module and unit-test it. (NFC)
This API is used by swift-lldb.
2020-04-24 16:51:54 -07:00
Adrian Prantl b9c7e276bd Disable path-sensitive test on Windows. 2020-04-24 15:21:54 -07:00
Adrian Prantl 79feafa514 Add an internal bit to the XcodeSDK class.
For developing the OS itself there exists an "internal" variant of
each SDK. This patch adds support for these SDK directories to the
XcodeSDK class.

Differential Revision: https://reviews.llvm.org/D78675
2020-04-24 12:55:53 -07:00
Raphael Isemann c2fec2fb17 [lldb] Make RNBSocketTest compile again after socket modernization
Commit c9e6b7010c changed the API but didn't update this
macOS-specific test.
2020-04-23 17:00:02 +02:00
Pavel Labath f512b978b0 [lldb/Utility] Improve error_code->Status conversion
Both entities have the notion of error "namespaces". Map the errno
namespace correctly.
2020-04-23 16:12:41 +02:00
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