Commit Graph

13494 Commits

Author SHA1 Message Date
Pavel Labath 0081149f96 [lldb/DWARF] Fix PC value for artificial tail call frames for the "GNU" case
Summary:
The way that the support for the GNU dialect of tail call frames was
implemented in D80519 meant that the were reporting very bogus PC values
which pointed into the middle of an instruction: the -1 trick is
necessary for the address to resolve to the right function, but we
should still be reporting a more realistic PC value -- I say "realistic"
and not "real", because it's very debatable what should be the correct
PC value for frames like this.

This patch achieves that my moving the -1 from SymbolFileDWARF into the
stack frame computation code. The idea is that SymbolFileDWARF will
merely report whether it has provided an address of the instruction
after the tail call, or the address of the call instruction itself. The
StackFrameList machinery uses this information to set the "behaves like
frame zero" property of the artificial frames (the main thing this flag
does is it controls the -1 subtraction when looking up the function
address).

This required a moderate refactor of the CallEdge class, because it was
implicitly assuming that edges pointing after the call were real calls
and those pointing the the call insn were tail calls. The class now
carries this information explicitly -- it carries three mostly
independent pieces of information:
- an address of interest in the caller
- a bit saying whether this address points to the call insn or after it
- whether this is a tail call

Reviewers: vsk, dblaikie

Subscribers: aprantl, mgrang, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D81010
2020-06-08 14:44:36 +02:00
Benjamin Kramer 3badd17b69 SmallPtrSet::find -> SmallPtrSet::count
The latter is more readable and more efficient. While there clean up
some double lookups. NFCI.
2020-06-07 22:38:08 +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
Richard Smith 825e3bb580 PR46209: properly determine whether a copy assignment operator is
trivial.

We previously took a shortcut by assuming that if a subobject had a
trivial copy assignment operator (with a few side-conditions), we would
always invoke it, and could avoid going through overload resolution.
That turns out to not be correct in the presenve of ref-qualifiers (and
also won't be the case for copy-assignments with requires-clauses
either). Use the same logic for lazy declaration of copy-assignments
that we use for all other special member functions.

Previously committed as c57f8a3a20. This
now also includes an extension of LLDB's workaround for handling special
members without the help of Sema to cover copy assignments.
2020-06-05 16:05:32 -07:00
Davide Italiano c3f0d9f3d2 [IRExecutionUnit] Early returns for clarity. NFCI. 2020-06-05 14:52:36 -07:00
Adrian Prantl ad4e7b9dc8 Fix an oversight in GetXcodeContentsDirectory()
Since FindXcodeContentsDirectoryInPath expects the *.app/Contents and
DEVELOPER_DIR is supposed to point to Xcode.app, we need to append the
Contents path first.

Differential Revision: https://reviews.llvm.org/D81290
2020-06-05 13:50:37 -07:00
Adrian Prantl f28177dbe8 Factor out GetEnvDeveloperDir() (NFC)
Differential Revision: https://reviews.llvm.org/D81289
2020-06-05 13:50:37 -07:00
Adrian Prantl 79daa3d896 Teach GetXcodeSDK to look in the Xcode that contains LLDB
instead of preferring the one chosen with xcode-select.

<rdar://problem/64000666>

Differential Revision: https://reviews.llvm.org/D81210
2020-06-05 11:59:22 -07: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
Kadir Cetinkaya 2af2140983
[lldb] Handle new BFloat16 type 2020-06-05 12:25:26 +02:00
Jan Kratochvil 846909e2ab [lldb] Fix UBSan regression in GetSLEB128
It regressed recently by my: https://reviews.llvm.org/D81119
2020-06-05 12:00:44 +02:00
Jan Kratochvil 7fc6d36d48 [nfc] [lldb] clang-format #include files order 2020-06-05 08:28:06 +02: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
Raphael Isemann 2ebe30c6e4 [lldb][NFC] Address some review feedback for D80775 ('command script delete' completion)
In the similar review D81128, Jonas pointed out some style errors that also
apply to D80775 (which is already committed). Also applying the changes
suggested there to this code.
2020-06-04 10:30:27 +02:00
Gongyu Deng 2e8f304f5e [lldb] tab completion for `command script delete'
Summary: Added the tab completion for `command script delete`.

Reviewers: teemperor, JDevlieghere

Reviewed By: teemperor

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D80775
2020-06-04 10:19:03 +02:00
Davide Italiano 7c1b060c3c [IRInterpreter] Unused. Drive-by cleanup. NFCI. 2020-06-03 13:31:58 -07:00
Raphael Isemann a23d0a06d4 [lldb][NFC] Fix documentation formatting in ASTResultSynthesizer
This comment apparently didn't survive the great LLDB reformatting unharmed.
2020-06-03 21:34:23 +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
Vedant Kumar 7822b8a817 [lldb/StringPrinter] Convert DecodedCharBuffer to a class, NFC
The m_size and m_data members of DecodedCharBuffer are meant to be
private.
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
Raphael Isemann c0ccb582c3 [lldb] Pass fewer parameters by non-const reference to DWARFASTParserClang::ParseSingleMember
These parameters are only passed on by value or const reference, so we should
do the same when calling this function.
2020-06-03 12:42:09 +02:00
Jonas Devlieghere def72b9195 [lldb/Interpreter] Remove redundant argument (NFC) 2020-06-02 21:23:19 -07:00
Adrian Prantl 2d2a603d66 Remove redundant code (NFC)
This has no effect on the testsuite and was only needed in an early
prototype from before debugserver was able to report the correct
platform.
2020-06-02 16:55:50 -07:00
Konrad Kleine eaebcbc679 [lldb] NFC remove DISALLOW_COPY_AND_ASSIGN
Summary:
This is how I applied my clang-tidy check (see
https://reviews.llvm.org/D80531) in order to remove
`DISALLOW_COPY_AND_ASSIGN` and have deleted copy ctors and deleted
assignment operators instead.

```
lang=bash
grep DISALLOW_COPY_AND_ASSIGN /opt/notnfs/kkleine/llvm/lldb -r -l | sort | uniq > files

for i in $(cat files);
do
  clang-tidy \
    --checks="-*,modernize-replace-disallow-copy-and-assign-macro" \
    --format-style=LLVM \
    --header-filter=.* \
    --fix \
    -fix-errors \
    $i;
done
```

Reviewers: espindola, labath, aprantl, teemperor

Reviewed By: labath, aprantl, teemperor

Subscribers: teemperor, aprantl, labath, emaste, sbc100, aheejin, MaskRay, arphaman, usaxena95, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D80543
2020-06-02 13:23:53 -04:00
Kadir Cetinkaya df06f4ff22
[lldb] Handle a new clang built-in type 2020-06-02 15:41:33 +02:00
Pavel Labath bddd288826 [lldb/DWARF] Add support for pre-standard GNU call site attributes
Summary:
The code changes are very straight-forward -- just handle both DW_AT_GNU
and DW_AT_call versions of all tags and attributes. There is just one
small gotcha: in the GNU version, DW_AT_low_pc was used both for the
"return pc" and the "call pc" values, depending on whether the tag was
describing a tail call, while the official scheme uses different
attributes for the two things.

Reviewers: vsk, dblaikie

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D80519
2020-06-02 12:57:51 +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
Raphael Isemann 2b37c5b560 [lldb][NFC] Make ClangExpressionSourceCode's wrapping logic more consistent
Summary:
ClangExpressionSourceCode has different ways to wrap the user expression based on
which context the expression is executed in. For example, if we're in a C++ member
function we put the expression inside a fake member function of a fake class to make the
evaluation possible. Similar things are done for Objective-C instance/static methods.
There is also a default wrapping where we put the expression in a normal function
just to make it possible to execute it.

The way we currently define which kind of wrapping the expression needs is based on
the `wrapping_language` we keep passing to the ClangExpressionSourceCode
instance. We repurposed the language type enum for that variable to distinguish the
cases above with the following mapping:
* language = C_plus_plus -> member function wrapping
* language = ObjC -> instance/static method wrapping (`is_static` distinguished between those two).
* language = C -> normal function wrapping
* all other cases like C_plus_plus11, Haskell etc. make our class a no-op that does mostly nothing.

That mapping is currently not documented and just confusing as the `language`
is unrelated to the expression language (and in the ClangUserExpression we even pretend
that it *is* the actual language, but luckily never used it for anything). Some of the code
in ClangExpressionSourceCode is also obviously thinking that this is the actual language of
the expression as it checks for non-existent cases such as `ObjC_plus_plus` which is
not part of the mapping.

This patch makes a new enum to describe the four cases above (with instance/static Objective-C
methods now being their own case). It also make that enum just a member of
ClangExpressionSourceCode instead of having to pass the same value to the class repeatedly.
This gets also rid of all the switch-case-checks for 'unknown' language such as C_plus_plus11 as this
is no longer necessary.

Reviewers: labath, JDevlieghere

Reviewed By: labath

Subscribers: abidh

Differential Revision: https://reviews.llvm.org/D80793
2020-06-01 13:24:30 +02: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 5f02679847 [lldb][NFC] Remove a std::string->C string->StringRef conversion in ClangUserExpression 2020-05-29 11:19:33 +02:00
Jonas Devlieghere 8ae21fb8d2 [lldb/CMake] Set both the BUILD and INSTALL RPATH on macOS
This is necessary when building the framework.
2020-05-28 16:04:35 -07:00
Adrian Prantl a57a67c59b Fix a use-after-free in GetXcodeSDKPath
Introduced in https://reviews.llvm.org/D80595. Thanks Jonas for noticing!

Differential Revision: https://reviews.llvm.org/D80666
2020-05-27 14:27:16 -07:00
Adrian Prantl 3345521507 Also cache negative results in GetXcodeSDKPath (NFC)
This fixes a performance issue in the failure case.

rdar://63547920

Differential Revision: https://reviews.llvm.org/D80595
2020-05-27 12:26:04 -07:00
Jonas Devlieghere e7f1067ad6 [lldb/Reproducers] Skip API logging in the DUMMY macro
The purpose of the LLDB_RECORD_DUMMY macro is twofold: it is used in
functions that take arguments that we don't know how to serialize (e.g.
void*) and it's used by function where we want to avoid doing excessive
work because they can be called from a signal handler (e.g.
setTerminalWidth).

To support the latter case, I've disabled API logging form the Recorder
ctor used by the DUMMY macro. This ensures we don't allocate memory when
called from a signal handler.
2020-05-27 10:35:43 -07:00
Raphael Isemann 74a51753a6 [lldb] Make order of completions for expressions deterministic and sorted by Clang's priority values.
Summary:

It turns out that the order in which we provide completions for expressions is
nondeterministic. This leads to confusing user experience and also breaks the
reproducer tests (as two LLDB tests can go out of sync due to the
non-determinism in the completion lists)

The reason for the non-determinism is that the CompletionConsumer informs us
about decls in the order in which it finds declarations in the lookup store of
the DeclContexts it visits (mainly this snippet in SemaLookup.cpp):

``` lang=c++
    // Enumerate all of the results in this context.
    for (DeclContextLookupResult R :
         Load ? Ctx->lookups()
              : Ctx->noload_lookups(/*PreserveInternalState=*/false)) {
       [...]
```

This storage of the lookup is sorted by pointer values (see the hash of
`DeclarationName`) and can therefore be non-deterministic. The LLDB code
completion consumer that receives these calls originally expected that the order
of declarations is defined by Clang, but it seems the API expects the client to
provide an order to the completions.

This patch fixes the issue as follows:

* We sort the completions we get from Clang alphabetically and also by the
priority value we get from Clang (with priority value sorting having precedence
over the alphabetical sorting)

* We make all the functions/variables that touch a completion before the sorting
const-qualified. The idea is that this should prevent that we never have
observable side-effect from touching these declarations in a non-deterministic
order (e.g., we don't try to complete the type by accident).

This way we behave like the other parts of Clang which also sort the results by
some deterministic value (usually the name or something computed from a name,
e.g., edit distance to a given string).

We most likely also need to fix the Clang code to make the loop I listed above
deterministic to prevent these issues in the future (tracked in rdar://63442513
). This wouldn't replace the functionality provided in this patch though as we
would still need the priority and overall alphabetical sorting.

Note: I had to increase the lldb-vscode completion limit to 100 as the tests
look for strings that aren't in the first 50 results anymore due to variable
names starting with letters like 'v' (which are now always shown much further
down in the list due to the alphabetical sorting).

Fixes rdar://63200995

Reviewers: JDevlieghere, clayborg

Reviewed By: JDevlieghere

Subscribers: mgrang, abidh

Differential Revision: https://reviews.llvm.org/D80292
2020-05-27 19:22:01 +02:00
Gongyu Deng 763bc23057 [lldb] Tab completion for process plugin name
Summary:

1. Added tab completion to `process launch -p`, `process attach -P`, `process
connect -p`;

2. Bound the plugin name common completion as the default completion for
`eArgTypePlugin` arguments.

Reviewers: teemperor, JDevlieghere

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D79929
2020-05-27 14:11:16 +02:00
Raphael Isemann 18bb1f1067 [lldb] Fix a potential bug that may cause assert failure in CommandObject::CheckRequirements
Summary: `CommandObject::CheckRequirements` requires cleaning up `m_exe_ctx`
between commands. Function `HandleOptionCompletion` returns without cleaning up
`m_exe_ctx` could cause assert failure in later `CheckRequirements`.

Reviewers: teemperor, JDevlieghere

Reviewed By: teemperor

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D80447
2020-05-27 14:05:17 +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
Alex Langford 1079978b3c [lldb][Core] Remove dead codepath in Mangled
Summary:
Objective-C names are stored in m_demangled, not in m_mangled. The
method in the condition will never return true.

Differential Revision: https://reviews.llvm.org/D79823
2020-05-26 17:12:20 -07:00
Eric Christopher 713538b629 Be more specific about auto * vs auto for po alias. 2020-05-26 11:59:09 -07:00
Pavel Labath c34936dae7 [lldb] s/dyn_cast/isa
The cast result is unused and produces a warning with gcc.
2020-05-26 09:21:54 +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
Raphael Isemann fe22e5689e [lldb][NFC] Pass DeclarationName to NameSearchContext by value
DeclarationName is usually passed around by value as it's just a pointer.
2020-05-25 12:37:22 +02:00
Jaroslav Sevcik 83bd2c4a06 Prevent GetNumChildren from transitively walking pointer chains
Summary:

This is an attempt to fix https://bugs.llvm.org/show_bug.cgi?id=45988,
where SBValue::GetNumChildren returns 2, but SBValue::GetChildAtIndex(1) returns
an invalid value sentinel.

The root cause of this seems to be that GetNumChildren can return the number of
children of a wrong value. In particular, for pointers GetNumChildren just
recursively calls itself on the pointee type, so it effectively walks chains of
pointers. This is different from the logic of GetChildAtIndex, which only
recurses if pointee.IsAggregateType() returns true (IsAggregateType is false for
pointers and references), so it never follows chain of pointers.

This patch aims to make GetNumChildren (more) consistent with GetChildAtIndex by
only recursively calling GetNumChildren for aggregate types.

Ideally, GetNumChildren and GetChildAtIndex would share the code that decides
which pointers/references are followed, but that is a bit more invasive change.

Reviewers: teemperor, jingham, clayborg

Reviewed By: teemperor, clayborg

Subscribers: clayborg, labath, shafik, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D80254
2020-05-25 11:30:22 +02:00
Jonas Devlieghere c3116182c8 Revert "[lldb/Interpreter] Fix another eExpressionThreadVanished warning"
This reverts commit f2ffa33c79. My local
checkout was behind and Eric already took care of it in the meantime.
2020-05-23 13:37:46 -07:00
Jonas Devlieghere f2ffa33c79 [lldb/Interpreter] Fix another eExpressionThreadVanished warning
Fixes warning: enumeration value 'eExpressionThreadVanished' not handled
in switch [-Wswitch] in CommandInterpreter.cpp.
2020-05-23 13:27:31 -07:00
Adrian Prantl 220c17ffd4 Print a warning when stopped in a frame LLDB has no plugin for.
This patchs adds an optional warning that is printed when stopped at a
frame that was compiled in a source language that LLDB has no plugin
for.

The motivational use-case is debugging Swift code on Linux. When the
user accidentally invokes the system LLDB that was built without the
Swift plugin, it is very much non-obvious why debugging doesnt
work. This warning makes it easy to figure out what went wrong.

<rdar://problem/56986569>
2020-05-22 15:37:36 -07:00
Eric Christopher 7510aede62 Handle eExpressionThreadVanished in error switch to handle
covered switch warning.
2020-05-22 13:43:10 -07:00
Raphael Isemann 8cb7574541 Revert "[lldb] Enable C++14 when evaluating expressions in a C++14 frame"
This reverts commit 5f88f39ab8. It broke these
three tests on the Window bot:
  lldb-api :: commands/expression/completion/TestExprCompletion.py
  lldb-api :: lang/cpp/scope/TestCppScope.py
  lldb-api :: lang/cpp/standards/cpp11/TestCPP11Standard.py
2020-05-22 21:23:03 +02:00
Raphael Isemann 5f88f39ab8 [lldb] Enable C++14 when evaluating expressions in a C++14 frame
Summary:
Currently we never enable C++14 in the expression evaluator. This enables it when the language of the program is C++14.

It seems C++17 and so on isn't yet in any of the language enums (and the DWARF standard it seems), so C++17 support will be a follow up patch.

Reviewers: labath, JDevlieghere

Reviewed By: labath, JDevlieghere

Subscribers: aprantl

Differential Revision: https://reviews.llvm.org/D80308
2020-05-22 11:42:44 +02:00
Raphael Isemann bca378f68a [lldb][NFC] Overload raw_ostream operator << for ConstString
Summary: We are not doing this very often, but sometimes it's convenient when I can just << ConstStrings into llvm::errs() during testing.

Reviewers: labath, JDevlieghere

Reviewed By: labath, JDevlieghere

Subscribers: JDevlieghere

Differential Revision: https://reviews.llvm.org/D80310
2020-05-22 11:24:48 +02:00
Jonas Devlieghere 8a6333ef38 [lldb/REPL] Fix unhandled switch case
Fix warning: enumeration value 'eExpressionThreadVanished' not handled
in switch [-Wswitch]
2020-05-21 23:22:17 -07:00
Jim Ingham dbbed971e3 Handle the case where a thread exits while we are running a function on it. 2020-05-21 17:55:53 -07:00
Adrian Prantl e6b613254d Rename FunctionOptimizationWarning to the more generic FrameSelectedCallback (NFC) 2020-05-21 16:22:01 -07:00
Jonas Devlieghere 7606a54363 [lldb/Reproducers] Fix/skip passive replay failures in python_api subdir
Fixes or skips tests in the python_api subdirectory that were failing
with passive replay.
2020-05-20 23:23:53 -07:00
Nico Weber bc1c3655bf Give microsoftDemangle() an outparam for how many input bytes were consumed.
Demangling Itanium symbols either consumes the whole input or fails,
but Microsoft symbols can be successfully demangled with just some
of the input.

Add an outparam that enables clients to know how much of the input was
consumed, and use this flag to give llvm-undname an opt-in warning
on partially consumed symbols.

Differential Revision: https://reviews.llvm.org/D80173
2020-05-20 16:17:31 -04:00
Jonas Devlieghere 690993a09a [lldb/Reproducers] Add instrumentation to SBEnvironment
This class should've been instrumented when it landed. Whether the class
is "highly mutable" or not doesn't affect that.

With this patch TestSBEnvironment.py now passes when replayed.
2020-05-20 13:02:20 -07:00
Haibo Huang 04daba9670 [lldb] Cleans up system_libs
Summary:
Long long ago system_libs was appended to LLDB_SYSTEM_LIBS in
cmake/LLDBDependencies.cmake. After that file was removed, system_libs
is orphaned.

Currently the only user is source/Utility. Move the logic there and
remove system_libs.

Subscribers: mgorny, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D80253
2020-05-20 12:30:08 -07:00
Haibo Huang 780d7d7732 [lldb] Allows customizing libxml2 for darwin
Summary:
This changes allows to disable or use customized libxml2 for lldb.

1. Removes redundant include_directories. The one in LLDBConfig.cmake should be enough.

2. Link to ${LIBXML2_LIBRARIES} if xml2 is enabled.

Subscribers: mgorny, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D80257
2020-05-20 12:27:08 -07:00
Jonas Devlieghere bfb2783726 [lldb/Reproducers] Make SBStream::Print an API instead of a SWIG extension
This makes it possible to instrument the call for the reproducers. This
fixes TestStructuredDataAPI.py with reproducer replay.

Differential revision: https://reviews.llvm.org/D80312
2020-05-20 10:37:18 -07:00
Jonas Devlieghere d57b80e13e [lldb/Reproducers] Support reproducers for PlatformRemoteGDBServer
Add reproducer support to PlatformRemoteGDBServer. The logic is
essentially the same as for ProcessGDBRemote. During capture we record
the GDB packets and during replay we connect to a replay server.

This fixes TestPlatformClient.py when run form a reproducer.

Differential Revision: https://reviews.llvm.org/D80224
2020-05-20 09:18:57 -07:00
Raphael Isemann aa04ce7617 [lldb][NFC] Minor NamespaceMap refactor 2020-05-20 15:29:20 +02:00
Raphael Isemann 587f81f54a Revert "[lldb-server] Reset stop reason of all threads when resuming"
This reverts commit 56de738d18.

This broke the aarch64 bot. Reverting on behalf of jarin.
2020-05-20 13:29:04 +02: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 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
Emre Kultursay a9d7b458c0 Use IPv4 for Android connections
Summary:
When adb client connects to adb server, or when lldb connects to
lldb server on Android device, IPv6 does not work (at least on
Windows it does not work).

For Android on Windows, each IPv6 failure (fallback-to-IPv4) wastes
2 seconds, and since this is called 5 times when attaching, LLDB
is wasting 10 seconds. This CL brings a big improvement to attach latency.

Reviewers: labath

Reviewed By: labath

Subscribers: aadsm, clayborg, mgrang, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D79757
2020-05-20 11:32:03 +02:00
Jaroslav Sevcik 56de738d18 [lldb-server] Reset stop reason of all threads when resuming
Summary:
This patch makes the stop reason reset logic similar to MacOS' debugserver, where exceptions are reset for all threads when resuming process for stepping or continuing (see [[ 96f3ea0d21/lldb/tools/debugserver/source/MacOSX/MachThreadList.cpp (L433) | MachThreadList::ProcessWillResume ]] and [[ 96f3ea0d21/lldb/tools/debugserver/source/MacOSX/MachThread.cpp (L363) | MachThread::ThreadWillResume ]]).

Resetting stop reasons on resume fixes problems where LLDB spuriously reports SIGTRAP signal stop reason for deleted breakpoints (both internal and public) and where  LLDB stops on an internal breakpoint while stepping over while a breakpoint is hit in another thread. See [[ https://bugs.llvm.org/show_bug.cgi?id=45642 | PR45642 ]] for details.

Reviewed By: jingham, labath

Differential Revision: https://reviews.llvm.org/D79308
2020-05-20 11:08:34 +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
Jonas Devlieghere 018e5a96ee [lldb/Properties] Move OSPluginReportsAllThreads from Target to Process
This is what Jim wanted originally.

rdar://problem/61236293

Differential revision: https://reviews.llvm.org/D80159
2020-05-19 11:26:39 -07:00
Eric Christopher 15ee8a3a58 Silence warnings around int/float conversions. 2020-05-19 10:56:18 -07:00
Jonas Devlieghere 225f241c84 [lldb/Reproducers] Move connection logic into replay server (NFC)
Move the logic for connecting to the replay server into the replay
server itself, so it can be reused outside of ProcessGDBRemote.
2020-05-19 10:55:35 -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
Med Ismail Bennani 4e9e0488ab [lldb/Commands] Add ability to run shell command on the host.
This patch introduces the `(-h|--host)` option to the `platform shell`
command. It allows the user to run shell commands from the host platform
(always available) without putting lldb in the background.

Since the default behaviour of `platform shell` is to run the command of
the selected platform, having such a choice can be quite handy when
debugging remote targets, for instances.

This patch also introduces a `shell` alias, to improve the command
discoverability and make it more convenient to use for the user.

rdar://62856024

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-05-15 22:14:39 +02:00
Med Ismail Bennani 0eba9de71e [lldb/Dataformatter] Add support to CF{Dictionary,Set}Ref types
This patch improves data formatting for CFDictionaryRef and CFSetRef.
It uses the same data-formatter as NSCFDictionaries and NSCFSets introduced
previously but did require some adjustments in Core::ValueObject.

Since the "Ref" types are opaque pointers to the actual CF containers, if the
value object has a synthetic value, lldb will use the opaque pointer's pointee
type to create the new ValueObjectChild needed to dereference the ValueObject.
This allows the "Ref" types to behaves the same as CF containers when used with
the `frame variable` command, the SBAPI or in Xcode's variable inspector.

This patch also adds support for incomplete types in ValueObject.

rdar://53104287

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-05-15 22:14:39 +02:00
Pavel Labath 8b845ac5ed Recommit "[lldb] Don't dissasemble large functions by default"
This recommits f665e80c02 which was reverted in 1cbd1b8f69 for breaking
TestFoundationDisassembly.py. The fix is to use --force in the test to avoid
bailing out on large functions.

I have also doubled the large function limit to 8000 bytes (~~ 2000 insns), as
the foundation library contains a lot of large-ish functions. The intent of this
feature is to prevent accidental disassembling of enormous (multi-megabyte)
"functions", not to get in people's way.

The original commit message follows:

If we have a binary without symbol information (and without
LC_FUNCTION_STARTS, if on a mac), then we have to resort to using
heuristics to determine the function boundaries. However, these don't
always work, and so we can easily end up thinking we have functions
which are several megabytes in size. Attempting to (accidentally)
disassemble these can take a very long time spam the terminal with
thousands of lines of disassembly.

This patch works around that problem by adding a sanity check to the
disassemble command. If we are about to disassemble a function which is
larger than a certain threshold, we will refuse to disassemble such a
function unless the user explicitly specifies the number of instructions
to disassemble, uses start/stop addresses for disassembly, or passes the
(new) --force argument.

The threshold is currently fairly aggressive (4000 bytes ~~ 1000
instructions). If needed, we can increase it, or even make it
configurable.

Differential Revision: https://reviews.llvm.org/D79789
2020-05-15 11:57:48 +02:00
Raphael Isemann d48ef7cab5 [lldb] Print full Clang diagnostics when the ClangModulesDeclVendor fails to compile a module
Summary:
When the ClangModulesDeclVendor currently fails it just prints very basic and often incomplete diagnostics without any source locations:
```
(lldb) p @import Foundation
error: while importing modules:
'foo/bar.h' file not found
could not build module 'Darwin'
[...]
```
or even just
```
(lldb) p @import Foundation
error: while importing modules:
could not build module 'Darwin'
[...]
```

These diagnostics help neither the user nor us with figuring out what is the reason for the failure.

This patch wires up a full TextDiagnosticPrinter in the ClangModulesDeclVendor and makes
sure we always return the error stream to the user when we fail to compile our modules.

Fixes rdar://63216849

Reviewers: aprantl, jdoerfert

Reviewed By: aprantl

Subscribers: JDevlieghere

Differential Revision: https://reviews.llvm.org/D79947
2020-05-15 10:11:03 +02:00
Gongyu Deng 7c89297cf7 Correct the argument list of command `breakpoint read`
Summary: Command `breakpoint read` should not accept breakpoint ids as
arguments, and in fact, it is not implemented to deal with breakpoint id
arguments either. So this patch is to correct the argument list of this
command so that the help text won't misguide users.

Reviewers: teemperor, JDevlieghere, jingham

Reviewed By: teemperor, JDevlieghere

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D79722
2020-05-15 09:00:05 +02:00
shafik 1cbd1b8f69 Revert "[lldb] Don't dissasemble large functions by default"
This reverts commit f665e80c02.

Reverting because it breaks TestFoundationDisassembly.py
2020-05-14 14:15:51 -07:00
Ryan Mansfield 5144e48c14 [lldb] Update stop info override callback comment.
In D31172 GetStopInfoOverrideCallback was moved and renamed.

Differential revision: https://reviews.llvm.org/D79953
2020-05-14 13:08:56 -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
Pavel Labath dac6e9ca21 [lldb] Fix a "missing return" warning in XcodeSDK 2020-05-14 13:31:49 +02:00
Pavel Labath 638efe3929 [lldb] Use llvm::MC for register numbers in AArch64 ABIs
Summary:
This is equivalent to previous patches (e.g. 07355c1c0) for the x86 ABIs.

One name fixup is needed -- lldb refers to the floating/vector registers by
their vector name (vN). Llvm does not use this name, so we map it to qN,
representing the register as a single 128 bit value (this choice is fairly
arbitrary -- any other name would also work fine as they all have the same
DWARF number).

Reviewers: JDevlieghere, jasonmolenda, omjavaid

Reviewed By: omjavaid

Subscribers: clayborg, danielkiss, aprantl, kristof.beyls, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D75607
2020-05-14 13:31:48 +02:00
Pavel Labath deea174ee5 [lldb/gdb-remote] Change default value of use-libraries-svr4 to true
This setting was added last year, defaulting to false. There have been
no bug reports about the svr4 code path since then, and the using this
packet is definitely faster than walking the module list from lldb.

Set the default value of the setting to true, as that is a better
default. Users can still change it back if encountering problems, or we
can revert the change as well, in case of bigger issues.

I also add a note to the setting description that it is only effective
if lldb is built with xml support.
2020-05-14 12:17:37 +02:00
Pavel Labath 3a16829748 [lldb] Switch Section-dumping code to raw_ostream
Also, add a basic test for dumping sections.
2020-05-14 11:59:18 +02:00
Pavel Labath f665e80c02 [lldb] Don't dissasemble large functions by default
Summary:
If we have a binary without symbol information (and without
LC_FUNCTION_STARTS, if on a mac), then we have to resort to using
heuristics to determine the function boundaries. However, these don't
always work, and so we can easily end up thinking we have functions
which are several megabytes in size. Attempting to (accidentally)
disassemble these can take a very long time spam the terminal with
thousands of lines of disassembly.

This patch works around that problem by adding a sanity check to the
disassemble command. If we are about to disassemble a function which is
larger than a certain threshold, we will refuse to disassemble such a
function unless the user explicitly specifies the number of instructions
to disassemble, uses start/stop addresses for disassembly, or passes the
(new) --force argument.

The threshold is currently fairly aggressive (4000 bytes ~~ 1000
instructions). If needed, we can increase it, or even make it
configurable.

Differential Revision: https://reviews.llvm.org/D79789
2020-05-14 11:52:54 +02:00
Gabor Greif 20db891cef Fix typo in error message 2020-05-14 07:23:59 +02:00
Jonas Devlieghere 6671a81bc7 [lldb/Reproducers] Add test-specific API to set the test CWD
The reproducers' working directory is set to the current working
directory when they are initialized. While this is not optimal, as the
cwd can change during a debug session, it has been sufficient so far.

The current approach doesn't work for the API test suite however because
dotest temporarily changes the directory to where the test's Python file
lives.

This patch adds an API to tell the reproducers what to set the CWD to.
This is a NO-OP in every mode but capture.

Differential revision: https://reviews.llvm.org/D79825
2020-05-13 09:00:07 -07:00
Raphael Isemann 5f7a5e3bdb [lldb][NFC] Early-exit in SetupDeclVendor
Also removed the unnecessary element-by-element copy of the std::vector
hand_imported_modules to modules_for_macros.
2020-05-13 16:54:38 +02:00
Raphael Isemann 2fe6672498 [lldb][NFC] Don't specify a default argument when creating a TextDiagnosticPrinter 2020-05-13 15:55:51 +02:00
Pavel Labath e072b20bde [lldb] Merge PlatformXXX::ResolveExecutable
The near-identical implementations of this function for posix-y
platforms were merged in r293910. PlatformWindows was left out of this
merge because at the time we did not have a suitable base class to sink
the code into. That is no longer true, so this commit finishes the job
by moving the code into RemoteAwarePlatform::ResolveExecutable.
2020-05-13 13:28:19 +02:00
Mathias LANG e16111ce2f [lldb] Also recognize DWARF UTF base types using their size
Summary:
The D programming language has 'char', 'wchar', and 'dchar' as base types,
which are defined as UTF-8, UTF-16, and UTF-32, respectively.

It also has type constructors (e.g. 'const' and 'immutable'),
that leads to D compilers emitting DW_TAG_base_type with DW_ATE_UTF
and name 'char', 'immutable(wchar)', 'const(char)', etc...

Before this patch, DW_ATE_UTF would only recognize types that
followed the C/C++ naming, and emit an error message for the rest, e.g.:
```
error: need to add support for DW_TAG_base_type 'immutable(char)'
encoded with DW_ATE = 0x10, bit_size = 8
```

The code was changed to check the byte size first,
then fall back to the old name-based check.

Reviewers: clayborg, labath

Reviewed By: labath

Subscribers: labath, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D79559
2020-05-13 12:56:13 +02:00
Jonas Devlieghere ab22f71dd7 [lldb/Reproducers] Also record directories FileSystem::Collect.
Now that the FileCollector knows how to deal with directories we no
longer have to ignore them in the FileSystem class.
2020-05-12 15:59:24 -07:00
Fred Riss d9166ad272 [lldb/Driver] Support terminal resizing
Summary:
The comment in the Editine.h header made it sound like editline was
just unable to handle terminal resizing. We were not ever telling
editline that the terminal had changed size, which might explain why
it wasn't working.

This patch threads a `TerminalSizeChanged()` callback through the
IOHandler and invokes it from the SIGWINCH handler in the driver. Our
`Editline` class already had a `TerminalSizeChanged()` method which
was invoked only when editline was configured.

This patch also changes `Editline` to not apply the changes right away
in `TerminalSizeChanged()`, but instead defer that to the next
character read. During my testing, it happened once that the signal
was received while our `ConnectionFileDescriptor::Read` was allocating
memory. As `el_resize` seems to allocate memory too, this crashed.

Reviewers: labath, teemperor

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D79654
2020-05-12 11:55:25 -07: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
Kristof Beyls 5d7f5ca0e3 Add Linux SVE Ptrace macros.
Differential Revision: https://reviews.llvm.org/D79623
2020-05-12 15:24:24 +02:00
Eric Christopher 8d7796cf94 Fix a few clang-tidy warnings about auto * and const auto. 2020-05-11 15:33:17 -07:00
Eric Christopher cd7cb1f4ce Update lldb for rG10658691951f to avoid Werror messages around
new unhandled matrix types.
2020-05-11 13:45:21 -07:00
Raphael Isemann f8af9f5fca [lldb] Add missing nullptr checks to AppleObjCRuntime::GetBacktraceThreadFromException
Summary:
We got a few crash reports where LLDB crashes while derefencing the `frames_value` shared_ptr in the AppleObjCRuntime::GetBacktraceThreadFromException. `GetChildMemberWithName` returns a nullptr when an error occurs, so this seems to be just a missing nullptr check.

This patch adds that nullptr check and the other ones in the similar code directly below.

Fixes rdar://62174039

Reviewers: jingham, kubamracek

Reviewed By: jingham

Subscribers: abidh, JDevlieghere

Differential Revision: https://reviews.llvm.org/D78798
2020-05-11 16:02:51 +02:00
Gongyu Deng e87362e689 Tab completion for breakpoint write and breakpoint name add/delete
Summary: Apply the common completion created in [[ https://reviews.llvm.org/D75418 | Revision D75418 ]] to the commands  `breakpoint write` and `breakpoint name add/delete`.

Reviewers: teemperor, JDevlieghere

Reviewed By: teemperor

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D79686
2020-05-11 15:55:11 +02:00