Commit Graph

13216 Commits

Author SHA1 Message Date
Raphael Isemann 6b6a779ca8 [lldb][NFC] Always update m_cache_{hits/misses} in FormatCache
Summary:
These two variables are only incremented under LLDB_CONFIGURATION_DEBUG but their
value is always logged when verbose lldb formatter logging is enabled, which causes that our
cache hit/miss log looks like this in non-Debug builds:

```
Cache hits: 0 - Cache Misses: 0
...
Cache hits: 0 - Cache Misses: 0
...
Cache hits: 0 - Cache Misses: 0
```

This just always increments those two counters independent of build mode.

Reviewers: JDevlieghere

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D76687
2020-03-24 20:16:43 +01:00
Raphael Isemann aef982e35a [lldb] Don't dump the frame in SBTarget::EvaluateExpression in LLDB_CONFIGURATION_DEBUG
Summary:
Dumping the frame using the user-set format could cause that a debug LLDB doesn't behave as a release LLDB,
which could potentially break replaying a reproducer.

Also it's kinda strange that the frame format set by the user is used in the internal log output.

Reviewers: JDevlieghere

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D76685
2020-03-24 20:16:09 +01:00
Vedant Kumar 6905394d15 [lldb/DWARF] Use DW_AT_call_pc to determine artificial frame address
lldb currently guesses the address to use when creating an artificial
frame (i.e., a frame constructed by determining the sequence of (tail)
calls which must have happened).

Guessing the address creates problems -- use the actual address provided
by the DW_AT_call_pc attribute instead.

Depends on D76336.

rdar://60307600

Differential Revision: https://reviews.llvm.org/D76337
2020-03-24 12:02:03 -07:00
Raphael Isemann b8dab9b3d5 [lldb] Remove some debugging printfs from ITSession code
Summary:
This seems only useful for debugging and it's just plainly printf'ing to the console instead
of some log, so let's remove this.

Reviewers: #lldb, JDevlieghere

Reviewed By: JDevlieghere

Subscribers: JDevlieghere

Differential Revision: https://reviews.llvm.org/D76699
2020-03-24 18:09:27 +01:00
Jonas Devlieghere 1f80e51546 [lldb/Reproducers] Collect files imported by command script import
Files imported by the script interpreter aren't opened by LLDB so they
don't end up in the reproducer. The solution is to explicitly add them
to the FileCollector.

Differential revision: https://reviews.llvm.org/D76626
2020-03-24 08:54:26 -07:00
Jaroslav Sevcik 177dd63c8d Data formatters: fix detection of C strings
Summary:
Detection of C strings does not work well for pointers. If the value object holding a (char*) pointer does not have an address (e.g., if it is a temp), the value is not considered a C string and its formatting is left to DumpDataExtractor rather than the special handling in  ValueObject::DumpPrintableRepresentation. This leads to inconsistent outputs, e.g., in escaping non-ASCII characters. See the test for an example; the second test expectation is not met (without this patch). With this patch, the C string detection only insists that the pointer value is valid. The patch makes the code consistent with how the pointer is obtained in ValueObject::ReadPointedString.

Reviewers: teemperor

Reviewed By: teemperor

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D76650
2020-03-24 14:25:59 +01:00
Raphael Isemann 68687e75e7 [lldb][NFC] Mark GetNextPersistentVariableName as overriden to silence warning
This was triggering -Winconsistent-missing-override warnings.
2020-03-24 12:30:03 +01:00
Walter Erquinigo ca69be218c Create basic SBEnvironment class 2020-03-23 19:23:33 -07:00
Walter Erquinigo 318a0caf9a Revert "Create basic SBEnvironment class"
This reverts commit fd868f517d.
2020-03-23 18:20:10 -07:00
Walter Erquinigo fd868f517d Create basic SBEnvironment class 2020-03-23 17:59:06 -07:00
Fred Riss b6ae8937e0 [lldb/PlatformDarwin] Always delete destination file first in PutFile
Summary:
The default behavior of Platform::PutFile is to open the file and
truncate it if it already exists. This works fine and is a sensible
default, but it interacts badly with code-signing on iOS, as doing so
invalidates the signature of the file (even if the new content has a
valid code signature).

We have a couple tests which on purpose reload a different binary with
the same name. Those tests are currently broken because of the above
interaction.

This patch simply makes the Darwin platform unconditionally delete the
destination file before sending the new one to work around this issue.

Reviewers: jasonmolenda

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D76450
2020-03-23 14:34:17 -07:00
Jim Ingham 67d67ebe8f Internal expressions shouldn't increment the result variable numbering.
There an option: EvaluateExpressionOptions::SetResultIsInternal to indicate
whether the result number should be returned to the pool or not.  It
got broken when the PersistentExpressionState was refactored.

This fixes the issue and provides a test of the behavior.

Differential Revision: https://reviews.llvm.org/D76532
2020-03-23 13:30:37 -07:00
shafik a567d6809e [DataFormatters] Add formatter for libc++ std::unique_ptr
This adds a formatter for libc++ std::unique_ptr.

I also refactored GetValueOfCompressedPair(...) out of LibCxxList.cpp since I need the same functionality and it made sense to share it.

Differential Revision: https://reviews.llvm.org/D76476
2020-03-23 11:48:20 -07:00
Fred Riss b4a6e63ea1 [lldb/Target] Rework the way the inferior environment is created
Summary:
The interactions between the environment settings (`target.env-vars`,
`target.inherit-env`) and the inferior life-cycle are non-obvious
today. For example, if `target.inherit-env` is set, the `target.env-vars`
setting will be augmented with the contents of the host environment
the first time the launch environment is queried (usually at
launch). After that point, toggling `target.inherit-env` will have no
effect as there's no tracking of what comes from the host and what is
a user setting.

This patch computes the environment every time it is queried rather
than updating the contents of the `target.env-vars` property. This
means that toggling the `target.inherit-env` property later will now
have the intended effect.

This patch also adds a `target.unset-env-vars` settings that one can
use to remove variables from the launch environment. Using this, you
can inherit all but a few of the host environment.

The way the launch environment is constructed is:
  1/ if `target.inherit-env` is set, then read the host environment
  into the launch environment.
  2/ Remove for the environment the variables listed in
  `target.unset-env`.
  3/ Augment the launch environment with the contents of
  `target.env-vars`. This overrides any common values with the host
  environment.

The one functional difference here that could be seen as a regression
is that `target.env-vars` will not contain the inferior environment
after launch. The patch implements a better alternative in the
`target show-launch-environment` command which will return the
environment computed through the above rules.

Reviewers: labath, jingham

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D76470
2020-03-23 07:58:34 -07:00
Fred Riss cd7b45057c [lldb/API] Make Launch(Simple) use args and env from target properties
Summary:
When no arguments or environment is provided to SBTarget::LaunchSimple,
make it use the values surrently set in the target properties. You can
get the current behavior back by passing an empty array instead.

It seems like using the target defaults is a much more intuitive
behavior for those APIs. It's unllikely that anyone passed NULL/None to
this API after having set properties in order to explicitely ignore them.

One direct application of this change is within the testsuite. We have
plenty of tests calling LaunchSimple and passing None as environment.
If you passed --inferior-env to dotest.py to, for example, set
(DY)LD_LIBRARY_PATH, it wouldn't be taken into account.

Reviewers: jingham, labath, #libc_abi!

Subscribers: libcxx-commits, lldb-commits

Tags: #lldb, #libc_abi

Differential Revision: https://reviews.llvm.org/D76045
2020-03-23 07:58:33 -07:00
Fred Riss 9228a9efc6 [lldb/Target] Initialize new targets environment variables from target.env-vars
Summary:
The TargetProperties constructor invokes a series of callbacks to
prime the properties from the default ones. The one callback in
charge of updating the inferior environment was commented out
because it crashed.

The reason for the crash is that TargetProperties is a parent class
of Target and the callbacks were invoked using a Target that was
not fully initialized. This patch moves the initial callback
invocations to a separate function that can be called at the end
the Target constructor, thus preventing the crash.

One existing test had to be modified, because the initialization of
the environment properties now take place at the time the target is
created, not at the first use of the environment (usually launch
time).

The added test checks that the LaunchInfo object returned by
the target has been primed with the values from the settings.

Reviewers: jingham, labath

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D76009
2020-03-23 07:58:33 -07:00
Raphael Isemann 6a4905ae2d [lldb] Mark expressions that couldn't be parsed or executed as failed expressions
Summary:
LLDB keeps statistics of how many expression evaluations are 'successful' and 'failed'
which are updated after each expression evaluation (assuming statistics are enabled).
From what I understand the idea is that this could be used to define how well LLDB's
expression evaluator is working.

Currently all expressions are considered successful unless the user passes an explicit
positive element counting to the expression command (with the `-Z` flag) and then passes
an expression that successfully evaluates to a type that doesn't support element counting.
Expressions that fail to parse, execute or any other outcome are considered successful
at the moment which means we nearly always have a 100% expression evaluation
success rate.

This patch makes that expressions that fail to parse or execute to count as failed
expressions.

We can't know whether the expression failed because of an user error
of because LLDB couldn't correctly parse/compile it, but I would argue that this is
still an improvement. Assuming that the percentage of valid user expressions stays
mostly constant over time (which seems like a reasonable assumption), then this
way we can still see if we are doing relatively better/worse from release to release.

Reviewers: davide, aprantl, JDevlieghere

Reviewed By: aprantl

Subscribers: abidh

Differential Revision: https://reviews.llvm.org/D76280
2020-03-23 15:28:17 +01:00
Walter Erquinigo 7ece7c0faa Revert "Create basic SBEnvironment class"
This reverts commit 34c0759f84.
2020-03-20 19:25:27 -07:00
Walter Erquinigo 34c0759f84 Create basic SBEnvironment class
Summary: Inspired by https://reviews.llvm.org/D74636, I'm introducing a basic version of Environment in the API. More functionalities can be added as needed.

Reviewers: labath, clayborg

Subscribers: mgorny, lldb-commits, diazhector98

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D76111
2020-03-20 18:51:25 -07:00
Jonas Devlieghere 09c8845adf [lldb]/Tablegen] Use ElementType instead of DefaultValueUnsinged
The fourth field in the property struct is the default unsigned or enum
value for all types, except for Array and Dictionary types. For those,
it is the element type. During the tablegen conversion, this was
incorrectly translated to DefaultValueUnsigned with a value
corresponding to the OptionValue: enum type. So for
OptionValue::eTypeString this became DefaultUnsignedValue<16>. This
patch extends the tablegen backend to understand ElementType to express
this as ElementType<"String">.

Differential revision: https://reviews.llvm.org/D76535
2020-03-20 18:35:13 -07:00
Adrian Prantl 0a5fbf3093 Temporarily Revert "Create basic SBEnvironment class"
while investigating bot breakage.

This reverts commit 2dec82652e.
2020-03-20 16:47:50 -07:00
Walter Erquinigo 2dec82652e Create basic SBEnvironment class
Summary: Inspired by https://reviews.llvm.org/D74636, I'm introducing a basic version of Environment in the API. More functionalities can be added as needed.

Reviewers: labath, clayborg

Subscribers: mgorny, lldb-commits, diazhector98

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D76111
2020-03-20 14:38:50 -07:00
Davide Italiano 6385c2ab8f [AppleObjCRuntimeV2] Force lazily allocated class names to be resolved.
Fixes a couple of tests on new versions of the Obj-C runtime.
2020-03-20 13:43:08 -07:00
Sterling Augustine 5de4ba1770 Cleanup the plumbing for DILineInfoSpecifier. [NFC - Try 2] 2020-03-20 10:29:57 -07:00
Jaroslav Sevcik 089cfe113d Improve step over performance
Summary:
This patch improves step over performance for the case when we are
stepping over a call with a next-branch-breakpoint (see
https://reviews.llvm.org/D58678), and we encounter a stop during the
call. Currently, this causes the thread plan to step-out //each frame//
until it reaches the step-over range. This is a regression introduced by
https://reviews.llvm.org/D58678 (which did improve other things!). Prior
to that change, the step-over plan would always step-out just once.

With this patch, if we find ourselves stopped in a deeper stack frame
and we already have a next branch breakpoint, we simply return from the
step-over plan's ShouldStop handler without pushing the step out plan.

In my experiments this improved the time of stepping over a call that
loads 12 dlls from 14s to 5s. This was in remote debugging scenario with
10ms RTT, the call in question was Vulkan initialization
(vkCreateInstance), which loads various driver dlls. Loading those dlls
must stop on the rendezvous breakpoint, causing the perf problem
described above.

Reviewers: clayborg, labath, jingham

Reviewed By: jingham

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D76216
2020-03-20 11:41:56 +01:00
Raphael Isemann 7b2442584e Reland [lldb] Fix string summary of an empty NSPathStore2
(This is D68010 but I also set the new parameter in LibStdcpp.cpp to fix
the Debian tests).

Summary:
Printing a summary for an empty NSPathStore2 string currently prints random bytes behind the empty string pointer from memory (rdar://55575888).

It seems the reason for this is that the SourceSize parameter in the `ReadStringAndDumpToStreamOptions` - which is supposed to contain the string
length - actually uses the length 0 as a magic value for saying "read as much as possible from the buffer" which is clearly wrong for empty strings.

This patch adds another flag that indicates if we have know the string length or not and makes this behaviour dependent on that (which seemingly
was the original purpose of this magic value).

Reviewers: aprantl, JDevlieghere, shafik

Reviewed By: aprantl

Subscribers: christof, abidh, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D68010
2020-03-19 18:50:26 +01:00
Raphael Isemann 50f1985353 [lldb][NFC] Delete the original UserExpression before trying to reparse it with FixIts.
Currently when an expression fails to parse and we have a FixIt, we keep
the failed UserExpression around while trying to parse the expression with
applied fixits. This means that we have this rather confusing control flow:

1. Original expression created and parsing attempted.
2. Expression with applied FixIts is created and parsing attempted.
3. Original expression is destroyed and parser deconstructed.
4. Expression with applied FixIts is destroyed and parser deconstructed.

This patch just deletes the original expression so that step 2 and 3 are
swapped and the whole process looks more like just sequentially parsing two
expressions (which is what we actually do here).

Doesn't fix anything just makes the code less fragile.
2020-03-19 18:10:57 +01:00
Raphael Isemann 718d94187d Revert "[lldb] Fix string summary of an empty NSPathStore2"
This reverts commit 939ca455e7.

This failed on the debian bot for some reason:
  File "/home/worker/lldb-x86_64-debian/lldb-x86_64-debian/llvm-project/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py", line 67, in test_with_run_command
    "s summary wrong")
AssertionError: 'L"hello world! מזל טוב!\\0!\\0!!!!\\0\\0A\\0\\U0000fffd\\U0000fffd\\U0000fffd\\ [truncated]... != 'L"hello world! מזל טוב!"'
Diff is 2156 characters long. Set self.maxDiff to None to see it. : s summary wrong
2020-03-19 13:08:39 +01:00
Raphael Isemann 939ca455e7 [lldb] Fix string summary of an empty NSPathStore2
Summary:
Printing a summary for an empty NSPathStore2 string currently prints random bytes behind the empty string pointer from memory (rdar://55575888).

It seems the reason for this is that the SourceSize parameter in the `ReadStringAndDumpToStreamOptions` - which is supposed to contain the string
length - actually uses the length 0 as a magic value for saying "read as much as possible from the buffer" which is clearly wrong for empty strings.

This patch adds another flag that indicates if we have know the string length or not and makes this behaviour dependent on that (which seemingly
was the original purpose of this magic value).

Reviewers: aprantl, JDevlieghere, shafik

Reviewed By: aprantl

Subscribers: christof, abidh, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D68010
2020-03-19 12:20:35 +01:00
Davide Italiano f0ca0a2538 [AppleObjCRuntimeV2] Rewrite GetClassDescriptor, reducing indentation.
I'm going to modify this function to account for lazily allocated
class names in the Obj-C runtime, but first I need to understand
what it does.
2020-03-18 19:23:58 -07: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
Davide Italiano 85bd436961 [Host] Remove some code that's not needed anymore.
Discussed offline with Jason.
2020-03-18 14:44:53 -07:00
Fred Riss b40ee7ff1b [lldb/MemoryHistoryAsan] Fix address resolution for recorded backtraces
Summary:
The memory history plugin for Asan creates a HistoryThread with the
recorded PC values provided by the Asan runtime. In other cases,
thoses PCs are gathered by LLDB directly.

The PCs returned by the Asan runtime are the PCs of the calls in the
backtrace, not the return addresses you would normally get when
unwinding the stack (look for a call to GetPreviousIntructionPc in
AsanGetStack).

When the above addresses are passed to the unwinder, it will subtract
1 from each address of the non zero frames because it treats them as
return addresses. This can lead to the final report referencing the
wrong line.

This patch fixes this issue by threading a flag through HistoryThread
and HistoryUnwinder that tells them to treat every frame like the
first one. The Asan MemoryHistory plugin can then use this flag.

This fixes running TestMemoryHistory on arm64 devices, although it's
hard to guarantee that the test will continue to exhibit the boundary
condition that triggers this bug.

Reviewers: jasonmolenda, kubamracek

Subscribers: kristof.beyls, danielkiss, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D76341
2020-03-18 13:18:02 -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 3829d85cc6 [lldb/PlatformDarwin] Return POSIX path from FindXcodeContentsDirectoryInPath
Always return a POSIX-style path from FindXcodeContentsDirectoryInPath
so that the output is identical on all host platforms.
2020-03-17 15:57:34 -07: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
shafik 9e2715aaac [lldb] Remove template parameters from FunctionTemplateDecl names
Fix to get the AST we generate for function templates closer to what clang generates and expects.
We fix which FuntionDecl we are passing to CreateFunctionTemplateSpecializationInfo and we strip
template parameters from the name when creating the FunctionDecl and FunctionTemplateDecl.

These two fixes together fix asserts and ambiguous lookup issues for several cases which are added to the already existing small function template test.
This fixes issues with overloads, overloads and ADL, variadic function templates and templated operator overloads.

Differential Revision: https://reviews.llvm.org/D75761
2020-03-17 11:00:23 -07:00
Raphael Isemann 7c6e52ac0c [lldb] Ptrs->refs in CommandObjectExpression::EvaluateExpression parameters
The error_stream and result parameter were inconsistently checked for
being null, so we might as well make them references instead of crashing
in case someone passes a nullptr and hits one of the code paths that are
currently not doing a nullptr check on those parameters. Also change
output_stream for consistency.
2020-03-17 13:23:16 +01:00
Ayke van Laethem 0818e6cf1d
[LLDB] Add support for AVR breakpoints
I believe the actual opcode does not matter because the AVR architecture
is a Harvard architecture that does not support writing to program
memory. Therefore, debuggers and emulators provide hardware breakpoints.
But for some reason, this opcode must be defined or else LLDB will crash
with an assertion error.

Differential Revision: https://reviews.llvm.org/D74255
2020-03-17 13:17:48 +01:00
Michał Górny 06489eaa92 [lldb] [Host/NetBSD] Rename Host.cpp to HostNetBSD.cpp
Rename NetBSD-specific Host.cpp to HostNetBSD.cpp to avoid basename
conflict with common/Host.cpp.
2020-03-17 11:42:39 +01:00
Adrian Prantl 90a2fbdb04 Switch to TypeSystemClang over to CreateDeserialized() (NFC)
which is the more appropriate API for its use-case.

Differential Revision: https://reviews.llvm.org/D75715
2020-03-16 18:11:36 -07:00
Jonas Devlieghere 88fbd8f9e7 [lldb/Reproducers] Decode run-length encoding in GDB replay server.
The GDB replay server sanity-checks that every packet it receives
matches what it expects from the serialized packet log. This mechanism
tripped for TestReproducerAttach.py on Linux, because one of the packets
(jModulesInfo) uses run-length encoding. The replay server was comparing
the expanded incoming packet with the unexpanded packet in the log. As a
result, it claimed to have received an unexpected packet, which caused
the test to fail.

This patch addresses that issue by expanding the run-length encoding
before comparing the packets.

Differential revision: https://reviews.llvm.org/D76163
2020-03-16 08:47:39 -07:00
Raphael Isemann e2d8aa6bf7 [lldb] Re-add nullptr check to IRForTarget::RewriteObjCConstString log statement
The nullptr check here was removed in 4ef50a33b1
when I replaced (nearly) all log->Print to LLDB_LOG calls (which automatically
check for this stuff). But it seems this one call escaped my sed call.

Currently working on a test that can cover this code path but we can revert
this until I have found one.
2020-03-16 16:28:36 +01:00
Tatyana Krasnukha 0a840ef800 [lldb] Copy m_behaves_like_zeroth_frame on stack frame update
Fix to code from https://reviews.llvm.org/D64993.

Field StackFrame::m_behaves_like_zeroth_frame was introduced in commit
[1], however that commit hasn't added a copying of the field to
UpdatePreviousFrameFromCurrentFrame, therefore the value wouldn't change
when updating frames to reflect the current situation.

The particular scenario, where this matters is following. Assume we have
function main that invokes function func1. We set breakpoint at
func1 entry and in main after the func1 call, and do not stop at
the main entry. Therefore, when debugger stops for the first time,
func1 is frame#0, while main is frame#1, thus
m_behaves_like_zeroth_frame is set to 0 for main frame. Execution is
resumed, and stops now in main, where it is now frame#0. However while
updating the frame object, m_behaves_like_zeroth_frame remains false.
This field plays an important role when calculating line information for
backtrace: for frame#0, PC is the current line, therefore line
information is retrieved for PC, however for all other frames this is
not the case - calculated PC is a return-PC, i.e. instruction after the
function call line, therefore for those frames LLDB needs to step back
by one instruction. Initial implementation did this strictly for frames
that have index != 0 (and index is updated properly in
UpdatePreviousFrameFromCurrentFrame), but m_behaves_like_zeroth_frame
added a capability for middle-of-stack frames to behave in a similar
manner. But because current code now doesn't check frame idx,
m_behaves_like_zeroth_frame must be set to true for frames with 0 index,
not only for frame that behave like one. In the described test case,
after stopping in main, LLDB would still consider frame#0 as
non-zeroth, and would subtract instruction from the PC, and would report
previous like as current line.

The error doesn't manifest itself in LLDB interpreter though - it can be
reproduced through LLDB-MI and when using SB API, but not when we
interpreter command "continue" is executed. Honestly, I didn't fully
understand why it works in interpreter, I did found that bug "fixes"
itself if I enable DEBUG_STACK_FRAMES in StackFrameList.cpp, because
that calls StackFrame::Dump and that calls
GetSymbolContext(eSymbolContextEverything), which fills the context of
frame on the first breakpoint, therefore it doesn't have to be
recalculated (improperly) on a second frame. However, on first
breakpoint symbol context is calculated for the "call" line, not the
next one, therefore it should be recalculated anyway on a second
breakpoint, and it is done correctly, even though
m_behaves_like_zeroth_frame is still incorrect, as long as
GetSymbolContext(eSymbolContextEverything) has been called.

[1] 31e6dbe1c6 Fix PC adjustment in StackFrame::GetSymbolContext

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

Patch by Anton Kolesov <Anton.Kolesov@synopsys.com>
2020-03-16 16:20:11 +03:00
Pavel Labath 5abfa3226d [lldb/DWARF] Fix crash when a dwo compile unit refers to a non-dwo type
In this case dwo_num can be None => stop assuming it can't.
2020-03-16 12:12:59 +01:00
Jonas Devlieghere 4c90a5297d [lldb/Process] Include Unwind.h in FreeBSDThread
Fixes member access into incomplete type 'lldb_private::Unwind'. Thank
you to Paulf for pointing this out.
2020-03-15 20:38:40 -07:00
Jonas Devlieghere bfedb663cc [lldb/Host] s/FindProcesses/FindProcessesImpl/ in freebsd/Host.cpp
Fix the FreeBSD build. Thank you to Paulf for pointing this out.
2020-03-15 20:36:40 -07:00
Jonas Devlieghere 20e36f31df [lldb/Host] s/FindProcesses/FindProcessesImpl/ in windows/Host.cpp
Fix the Windows build.
2020-03-13 10:07:15 -07:00
Jonas Devlieghere 2451cbf07b [lldb/Reproducers] Intercept the FindProcesses API
This patch extends the reproducers to intercept calls to FindProcesses.
During capture it serializes the ProcessInstanceInfoList returned by the
API. During replay, it returns the serialized data instead of querying
the host.

The motivation for this patch is supporting the process attach workflow
during replay. Without this change it would incorrectly look for the
inferior on the host during replay and failing if no matching process
was found.

Differential revision: https://reviews.llvm.org/D75877
2020-03-13 09:31:35 -07:00
Jonas Devlieghere 2411f56bfd [lldb/Host] Fix the Windows build
Update use of ProcessInstanceInfoList which is now a std::vector.
2020-03-12 15:31:09 -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 638b06cf29 [lldb/Utility] Replace ProcessInstanceInfoList with std::vector. (NFCI)
Replace ProcessInstanceInfoList with std::vector<ProcessInstanceInfo>
and update the call sites.
2020-03-12 14:10:25 -07:00
Tatyana Krasnukha fe74df01a9 [lldb] Specify default value for platform.module-cache-directory
In addition to the commit rG352f16db87f583ec7f55f8028647b5fd8616111f,
this one fixes settings behavior on clearing - the setting should be
reverted to their default value, not an empty one.
2020-03-12 22:08:12 +03: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
Tatyana Krasnukha df90a15b1a [lldb] Clear all settings during a test's setUp
Global properties are shared between debugger instances and
if a test doesn't clear changes in settings it made,
this leads to side effects in other tests.

Differential Revision: https://reviews.llvm.org/D75537
2020-03-12 16:30:26 +03: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
Reid Kleckner 213aea4c58 Remove unused Endian.h includes, NFC
Mainly avoids including Host.h everywhere:

$ diff -u <(sort thedeps-before.txt) <(sort thedeps-after.txt) \
    | grep '^[-+] ' | sort | uniq -c | sort -nr
   3141 - /usr/local/google/home/rnk/llvm-project/llvm/include/llvm/Support/Host.h
2020-03-11 15:45:34 -07:00
Reid Kleckner e08464fb45 Avoid including FileManager.h from SourceManager.h
Most clients of SourceManager.h need to do things like turning source
locations into file & line number pairs, but this doesn't require
bringing in FileManager.h and LLVM's FS headers.

The main code change here is to sink SM::createFileID into the cpp file.
I reason that this is not performance critical because it doesn't happen
on the diagnostic path, it happens along the paths of macro expansion
(could be hot) and new includes (less hot).

Saves some includes:
    309 -    /usr/local/google/home/rnk/llvm-project/clang/include/clang/Basic/FileManager.h
    272 -    /usr/local/google/home/rnk/llvm-project/clang/include/clang/Basic/FileSystemOptions.h
    271 -    /usr/local/google/home/rnk/llvm-project/llvm/include/llvm/Support/VirtualFileSystem.h
    267 -    /usr/local/google/home/rnk/llvm-project/llvm/include/llvm/Support/FileSystem.h
    266 -    /usr/local/google/home/rnk/llvm-project/llvm/include/llvm/Support/Chrono.h

Differential Revision: https://reviews.llvm.org/D75406
2020-03-11 13:53:12 -07:00
Reid Kleckner c915cb957d Avoid including Module.h from ExternalASTSource.h
Module.h takes 86ms to parse, mostly parsing the class itself. Avoid it
if possible. ASTContext.h depends on ExternalASTSource.h.

A few NFC changes were needed to make this possible:

- Move ASTSourceDescriptor to Module.h. This needs Module to be
  complete, and seems more related to modules and AST files than
  external AST sources.
- Move "import complete" bit from Module* pointer int pair to
  NextLocalImport pointer. Required because PointerIntPair<Module*,...>
  requires Module to be complete, and now it may not be.

Reviewed By: aaron.ballman, hans

Differential Revision: https://reviews.llvm.org/D75784
2020-03-11 13:37:41 -07:00
Adrian Prantl ea96037186 Add a verification mechanism to CompilerType.
Badly-written code can combine an unrelated TypeSystem and opaque type
pointer into a CompilerType. This is particularly an issue in
swift-lldb. This patch adds an assertion mechanism that catches these
kinds of mistakes early. Because this is an assertion-only code path
there is not cost for release builds.

Differential Revision: https://reviews.llvm.org/D76011
2020-03-11 12:43:32 -07:00
Jonas Devlieghere 4016c6b07f [lldb/Reproducer] Prevent crash when GDB multi-loader can't be created.
Check that the multi loader isn't null and print an error otherwise.
This patch also extends the test to cover these error paths.
2020-03-10 23:16:55 -07:00
Pavel Labath 1ca1e08e75 [lldb] Break up CommandObjectDisassemble::DoExecute
The function consisted of a complicated set of conditions to compute the
address ranges which are to be disassembled (depending on the mode
selected by command line switches). This patch creates a separate
function for each mode, so that DoExecute is only left with the task of
figuring out how to dump the relevant ranges.

This is NFC-ish, except for one change in the error message, which is
actually an improvement.
2020-03-10 14:03:16 +01:00
Pavel Labath d00dff88b4 [lldb] Make UnwindLLDB a non-plugin
Summary:
This is the only real unwinder, and things have been this way for quite
a long time. At this point, the class has accumulated so many features
it is unlikely that anyone will want to reimplement the whole thing.

The class is also fairly closely coupled (through UnwindPlans and
FuncUnwinders) with a lot of other lldb components that it is hard to
imagine a different unwinder implementation being substantially
different without reimplementing all of those.

The existing unwinding functionality is nonetheless fairly complex and
there is space for adding more structure to it, but I believe a more
worthwhile effort would be to take the existing UnwindLLDB class and try
to break it down and introduce extension/customization points, instead
of writing a brand new Unwind implementation.

Reviewers: jasonmolenda, JDevlieghere, xiaobai

Subscribers: mgorny, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D75848
2020-03-10 13:56:15 +01:00
Davide Italiano 9d389f7858 [AppleObjCRuntimeV2] Fix a typo. Evalulate -> evaluate. 2020-03-09 15:40:09 -07:00
Davide Italiano a3c4e6b44a [AppleObjC2RuntimeV2] Remove dead code. NFC. 2020-03-09 15:37:12 -07:00
Davide Italiano 3cabd173a1 [ObjC] Dynamic type resolution logging should go to the types log. 2020-03-09 15:35:51 -07:00
Jonas Devlieghere 12ba989eef [lldb/Process] Update ThreadKDP for API change
GetUnwinder now returns a reference instead of a pointer.
2020-03-09 10:01:53 -07:00
Pavel Labath 34d7143b03 [lldb] Fix windows build, second attempt 2020-03-09 16:24:34 +01:00
Pavel Labath 24b1831ebf [lldb] Fix windows&freebsd builds for c0b1af68 2020-03-09 14:55:43 +01:00
Pavel Labath c0b1af6878 [lldb] Return Unwinder& from Thread::GetUnwinder
The function always returns a valid object. Let the return type reflect
that, and remove some null checks.
2020-03-09 14:13:22 +01:00
Pavel Labath af3db4e9aa [lldb] Reduce duplication in the Disassembler class
Summary:
The class has two pairs of functions whose functionalities differ in
only how one specifies how much he wants to disasseble. One limits the
process by the size of the input memory region. The other based on the
total amount of instructions disassembled. They also differ in various
features (like error reporting) that were only added to one of the
versions.

There are various ways in which this could be addressed. This patch
does it by introducing a helper struct called "Limit", which is
effectively a pair specifying the value that you want to limit, and the
actual limit itself.

Reviewers: JDevlieghere

Subscribers: sdardis, jrtc27, atanasyan, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D75730
2020-03-09 13:41:43 +01:00
Yaxun (Sam) Liu fe73d36f23 Fix lldb build failure due to clang mangler change 2020-03-08 00:38:30 -05:00
Raphael Isemann 8f7c911b58 [lldb][NFC] Refactor our option generation out of EvaluateExpression 2020-03-06 18:32:16 -08:00
Raphael Isemann ce1bc00f37 [lldb][cmake] Move remove_module_flags macro to AddLLDB.cmake
Summary: This is currently hidden in the Host CMakeLists but we should also use this macro in other parts of LLDB where we have ObjC++ sources (see D74891)

Reviewers: JDevlieghere

Reviewed By: JDevlieghere

Subscribers: mgorny, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D75164
2020-03-06 17:21:24 -08:00
Raphael Isemann 2bba1c22e7 tab completion for process signal
Summary: Provide a list of Unix signals for the tap completion for command "process signal".

Reviewers: teemperor

Subscribers: labath, jingham, JDevlieghere, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D75418
2020-03-06 17:05:25 -08:00
Adrian Prantl 33b696b57a Fix test broken by simulator triple changes. 2020-03-06 11:28:31 -08:00
Raphael Isemann 3b2c4e7178 [lldb] Remove some #ifdef LLDB_CONFIGURATION_DEBUG around asserts
Summary:
Otherwise this code won't run on the Release+Asserts builds we have on the CI.

Fixes rdar://problem/59867885 (partly)

Reviewers: aprantl

Reviewed By: aprantl

Subscribers: JDevlieghere, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D75493
2020-03-06 11:21:00 -08:00
Gongyu Deng ec31255c00 [lldb] Update the current execution context at the beginning of tab completions
Summary: Fix a bug that tab completions won't synchronous the current execution context. ( Thanks for Jim's explanation! )

Reviewers: teemperor, labath, jingham

Reviewed By: jingham

Subscribers: jingham, labath

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D75597
2020-03-06 10:44:00 -08:00
Adrian Prantl 000847f8be Correctly identify iOS simulator processes in debugserver.
Starting with iOS 13 simulator binaries are identified with an
explicit platform in the new LC_BUILD_VERSION load command.

On older deployment targets using the LC_VERSION_MIN load commands,
this patch detects when an ios process runs on a macOS host and
updates the target triple with the "simulator" environment
accordingly.

(Patch re-applied with bugfix this time).

This is part of https://bugs.swift.org/browse/SR-11971

rdar://problem/58438125

Differential Revision: https://reviews.llvm.org/D75696
2020-03-06 10:16:47 -08:00
Adrian Prantl 4ebe9b498d Revert "Correctly identify iOS simulator processes in debugserver."
This reverts commit 59d816d884.

It broke TestGDBRemoteClient.
2020-03-06 10:16:47 -08:00
Adrian Prantl 58c506d8e8 Correctly identify iOS simulator processes in debugserver.
Starting with iOS 13 simulator binaries are identified with an
explicit platform in the new LC_BUILD_VERSION load command.

On older deployment targets using the LC_VERSION_MIN load commands,
this patch detects when an ios process runs on a macOS host and
updates the target triple with the "simulator" environment
accordingly.

(Patch re-applied without modifications, the bot failure was unrelated).

This is part of https://bugs.swift.org/browse/SR-11971

rdar://problem/58438125

Differential Revision: https://reviews.llvm.org/D75696
2020-03-06 09:59:30 -08:00
Adrian Prantl 66a6fa631e Revert "Correctly identify iOS simulator processes in debugserver."
This reverts commit 59d816d884.

It broke TestGDBRemoteClient.
2020-03-06 09:52:20 -08:00
Adrian Prantl 59d816d884 Correctly identify iOS simulator processes in debugserver.
Starting with iOS 13 simulator binaries are identified with an
explicit platform in the new LC_BUILD_VERSION load command.

On older deployment targets using the LC_VERSION_MIN load commands,
this patch detects when an ios process runs on a macOS host and
updates the target triple with the "simulator" environment
accordingly.

This is part of https://bugs.swift.org/browse/SR-11971

rdar://problem/58438125

Differential Revision: https://reviews.llvm.org/D75696
2020-03-06 09:42:05 -08:00
Pavel Labath 92c0cda928 [lldb/Disassembler] Move address resolution into the ParseInstructions function
The static Disassembler can be thought of as shorthands for three
operations:
- fetch an appropriate disassembler instance (FindPluginForTarget)
- ask it to dissassemble some bytes (ParseInstructions)
- ask it to dump the disassembled instructions (PrintInstructions)

The only thing that's standing in the way of this interpretation is that
the Disassemble function also does some address resolution before
calling ParseInstructions. This patch moves this functionality into
ParseInstructions so that it is available to users who call
ParseInstructions directly.
2020-03-06 11:23:41 +01:00
Pavel Labath 71c1c18474 [lldb] Delete UnwindMacOSXFrameBackchain
Summary:
It isn't used anywhere (except on imaginary triples like
sparc-apple-ios) and it also violates plugin separation.

This patch deletes it and declares UnwindLLDB to be _the_ lldb unwinder.

Reviewers: jasonmolenda, JDevlieghere, xiaobai

Subscribers: jyknight, mgorny, krytarowski, fedor.sergeev, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D75680
2020-03-06 08:27:13 +01:00
Jonas Devlieghere 621d969a96 [lldb/DWARF] Fix 80 col formatting (NFC)
Forgot to run git clang-format before landing my previous commit
(226d52b1fa).
2020-03-05 21:28:23 -08:00
Jonas Devlieghere 226d52b1fa [lldb/DWARF] Replace C style casts with static_cast<> (NFC)
Using static_cast instead of C style casts better conveys the code's
intent, is a tad more safe and stands out more.
2020-03-05 21:24:51 -08:00
Shu Anzai 467969161d [lldb/Core] Minor code cleanup in Editline.cpp (NFC)
Simplify the code a bit.

Differential revision: https://reviews.llvm.org/D75294
2020-03-05 16:15:26 -08:00
Raphael Isemann d0e8abc438 [lldb] Fix more typos in log statements in ClangASTSource
The indexes need to start at 0 but in D74951 I removed the first parameter
and didn't decrement all the indexes. This patch at least makes sure that
LLDB logging no longer crashes (but it still deadlocks).
2020-03-05 14:13:09 -08:00
Pavel Labath 04592d5b23 [lldb] s/ExecutionContext/Target in Disassembler
Some functions in this file only use the "target" component of an
execution context. Adjust the argument lists to reflect that.

This avoids some defensive null checks and simplifies most of the
callers.
2020-03-05 14:46:39 +01:00
Pavel Labath ea68462ed1 [lldb] Make Disassembler::PrintInstructions a method
the previously static member function took a Disassembler* argument
anyway. This renames the argument to "this". The function also always
succeeds (returns true), so I change the return type to void.
2020-03-05 12:07:49 +01:00
Pavel Labath c6a38957a7 [lldb] Delete two overloads of Disassembler::Disassemble
by "inlining" them into their single caller (CommandObjectDisassemble).
The functions mainly consist of long argument lists and defensive
checks. These become unnecessary after inlining, so the end result is
less code. Additionally, this makes the implementation of
CommandObjectDisassemble more uniform (first figure out what you're
going to disassemble, then actually do it), which enables further
cleanups.
2020-03-05 11:00:37 +01:00
Tatyana Krasnukha a31130f6fc [lldb][testsuite] Create a SBDebugger instance for each test
Some tests set settings and don't clean them up, this leads to side effects in other tests.
The patch removes a global debugger instance with a per-test debugger to avoid such effects.

From what I see, lldb.DBG was needed to determine the platform before a test is run,
lldb.selected_platform is used for this purpose now. Though, this required adding a new function
to the SBPlatform interface.

Differential Revision: https://reviews.llvm.org/D74903
2020-03-05 10:12:54 +03:00
Raphael Isemann 70b8f95813 [lldb][NFC] Use C++11 for loop in ClangASTSource::FindExternalLexicalDecls 2020-03-04 12:57:05 -08:00
Raphael Isemann 4ab2ea9fc0 [lldb] Fix typo in ClangASTSource logging statement 2020-03-04 11:05:48 -08:00
Raphael Isemann e98ef0af2c [lldb] Fix several LLDB_LOGs with wrong indices in ClangASTSource.cpp 2020-03-04 10:32:50 -08:00
Raphael Isemann 0ab109d43d [lldb][NFC] Modernize logging UserExpression 2020-03-04 09:04:54 -08:00
Tatyana Krasnukha b1324e74da [lldb][NFC] Move local variables near to their usage 2020-03-04 16:56:51 +03:00
Tatyana Krasnukha 6c17cc531f [lldb] Make BreakpointResolver hold weak_ptr instead of raw pointer to breakpoint
This prevents calling Breakpoint::shared_from_this of an object that is not owned by any shared_ptr.

Differential Revision: https://reviews.llvm.org/D74557
2020-03-04 16:56:50 +03:00
Pavel Labath 3245dd59b1 [lldb] Reduce duplication in CommandObjectDisassemble
This command had nearly identical code for the "then" and "else"
branches of the "if (m_options.num_instructions != 0)" condition.

This patch factors out the common parts of the two blocks to reduce
duplication.
2020-03-04 13:47:35 +01:00