Commit Graph

24591 Commits

Author SHA1 Message Date
Muhammad Omair Javaid 69a3269250 Support AArch64 PAC elf-core register read
This adds support for reading AArch64 Pointer Authentication regset
from elf-core file. Also includes a test-case for the same. Furthermore
there is also a slight refactoring of RegisterContextPOSIXCore_arm64
members and constructor. linux-aarch64-pac.core file is generated using
lldb/test/API/functionalities/postmortem/elf-core/main.c with following
clang arguments:
-march=armv8.5-a -mbranch-protection=pac-ret+leaf -nostdlib -static -g

Reviewed By: DavidSpickett

Differential Revision: https://reviews.llvm.org/D99941
2021-05-03 16:04:47 +05:00
Michał Górny db457e6479 [lldb] [Process/FreeBSD] Fix arm64 build after RegisterInfoPOSIX_arm64 changes
Commit 88a5b35d63 changed the API
of RegisterInfoPOSIX_arm64 and effectively broke the FreeBSD plugin.
Update it to work with the new API.

Differential Revision: https://reviews.llvm.org/D101521
2021-05-01 22:50:49 +02:00
David Spickett 44d0ad53af [lldb] Change DumpDataExtractorTest function names to lldb style (NFC) 2021-04-30 16:55:34 +01:00
David Spickett 8da5d111a5 [lldb] DumpDataExtractor tests for item byte size errors
Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D101631
2021-04-30 16:49:04 +01:00
David Spickett a86cbd4755 [lldb] More tests for DumpDataExtractor
* Using a base address or skipping it with LLDB_INVALID_ADDRESS
* Using a data offset, which does not effect the printed addresses
* Not providing an output stream
* Formatting a double sized HexFloat
* Formatting over multiple lines

Since address printing now has its own test,
I've removed the base address from all the format
type tests.

The multi line tests still use a base address to check that
it's incremented correctly for each new line.

Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D101627
2021-04-30 16:16:38 +01:00
Neal (nealsid) fd89af6880 Wrap edit line configuration calls into helper functions
Currently we call el_set directly to configure the editor in the libedit
wrapper.  There are some cases in which this causes extra casting, but we pass
captureless lambdas as function pointers, which should work out of the box.
Since el_set takes varargs, if the cast is incorrect or if the cast is not
present, it causes a run time failure rather than compile error.  This change
makes it so a few different types of configuration is done inside a helper
function to provide type safety and eliminate that casting.  I didn't do all
edit line configuration because I'm not sure how important it was in other cases
and it might require something more general keep up with libedit's signature.
I'm open to suggestions, though.

Reviewed By: teemperor, JDevlieghere

Differential Revision: https://reviews.llvm.org/D101250
2021-04-30 12:32:29 +02:00
David Spickett 8fdfc1d64c [lldb] Add tests for DumpDataExtractor formats
Covering basic cases where you have 1 item on 1 line.

Apart from eFormatCharArray, where using multiple lines
highlights the difference between it and eFormatVectorOfChar.

Reviewed By: #lldb, teemperor

Differential Revision: https://reviews.llvm.org/D101453
2021-04-30 10:29:05 +01:00
Jonas Devlieghere b535459d0a [debugserver] Use add_lldb_library instead of add_library
Use add_lldb_library to ensure debugserver inherits the defines set by
llvm and lldb.

Differential revision: https://reviews.llvm.org/D101596
2021-04-29 22:09:10 -07:00
Walter Erquinigo 1141ba677e [lldb-vscode] Follow up of D99989 - store some strings more safely
As a follow up of https://reviews.llvm.org/D99989#inline-953343, I'm now
storing std::string instead of char *. I know it might never break as char *,
but if it does, chasing that bug might be dauting.
Besides, I'm also checking of the strings gotten through the SB API are
null or not.
2021-04-29 18:37:44 -07:00
Raphael Isemann a76df78470 [lldb] Make the NSSet formatter faster and less prone to infinite recursion
Right now to get the 'NSSet *` pointer value we first derefence it and then take
the address of the result.

Beside being inefficient this potentially can cause an infinite recursion if the
`pointer` value we get is a pointer of a type that the TypeSystem can't
derefence. If the pointer is for example some form of `void *` that the dynamic
type resolution can't resolve to an actual type, then the `Derefence` call goes
back to asking the formatters how to reference it. If the NSSet formatter then
checks if it's an NSSet variation under the hood then we just end infinitely
often recursion.

In practice this seems to happen with some form of Builtin.RawPointer we get
from a NSDictionary in Swift.

FWIW, no other formatter is doing the same deref->addressOf as here and there
doesn't seem to be any specific reason to do so in the git history (it's just
part of the initial formatter commit)

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D101537
2021-04-29 19:13:43 +02:00
David Spickett f31e390453 [lldb][AArch64] Don't check for VmFlags in smaps files
AArch64 kernel builds default to having /smaps and
the "VmFlags" line was added in 3.8. Long before MTE
was supported.

So we can assume that if you're AArch64 with MTE,
you can run this test.

The previous method of checking had a race condition
where the process we read smaps for, could finish before
we get to read the file.

I explored some alternatives but in the end I think
it's fine to just assume we have what we need.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D100493
2021-04-29 09:30:14 +01:00
David Spickett d0c521da3f [lldb] Correct format enum comment (NFC)
'.' is used for unprintable chars (see NON_PRINTABLE_CHAR).
2021-04-28 12:17:03 +01:00
Jordan Rupprecht 44e2247dcd [lldb] Fix DataLayout reference after 0f1137ba79 2021-04-27 20:07:09 -07:00
Adrian Prantl 711a473cd9 Update testcase for D101333. 2021-04-27 13:24:24 -07:00
Adrian Prantl 25bf137b1e Also display the underlying error message when displaying a fixit
When the user running LLDB with default settings sees the fixit
notification it means that the auto-applied fixit didn't work. This
patch shows the underlying error message instead of just the fixit to
make it easier to understand what the error in the expression was.

Differential Revision: https://reviews.llvm.org/D101333
2021-04-27 10:40:42 -07:00
Michał Górny ca7824c2a8 [lldb] [gdb-remote] Report QPassSignals and qXfer via extensions API
Remove hardcoded platform list for QPassSignals, qXfer:auxv:read
and qXfer:libraries-svr4:read and instead query the process plugin
via the GetSupportedExtensions() API.

Differential Revision: https://reviews.llvm.org/D101241
2021-04-27 19:34:00 +02:00
Raphael Isemann a0c735e29a [lldb] Skip TestPointerToMemberTypeDependingOnParentSize on Windows and GCC
The test added in D100977 is failing to compile on these platforms. This seems
to be caused by GCC, MSVC and Clang@Windows rejecting the code because
`ToLayout` isn't complete when pointer_to_member_member is declared (even though
that seems to be valid code).

This also reverts the test changes in the lazy-loading test from D100977 as
that failed for the same reason.
2021-04-26 18:55:54 +02:00
Jonas Devlieghere 7d850db6b6 [lldb] Don't use ::fork or ::vfork on watchOS or tvOS
Update lldb-server to not use fork or vfork on watchOS and tvOS as these
functions are explicitly marked unavailable there.

llvm-project/lldb/test/API/tools/lldb-server/main.cpp:304:11:
error: 'fork' is unavailable: not available on watchOS
      if (fork() == 0)
          ^
WatchSimulator6.2.sdk/usr/include/unistd.h:447:8: note: 'fork' has been
explicitly marked unavailable here
pid_t    fork(void) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
         ^
llvm-project/lldb/test/API/tools/lldb-server/main.cpp:307:11:
error: 'vfork' is unavailable: not available on watchOS
      if (vfork() == 0)
          ^
WatchSimulator6.2.sdk/usr/include/unistd.h:602:8: note: 'vfork' has been
explicitly marked unavailable here
pid_t    vfork(void) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
         ^
2021-04-26 09:31:35 -07:00
Emre Kultursay e439a463a3 [lldb] Use forward type in pointer-to-member
This change is similar in spirit to the change at:
https://reviews.llvm.org/rG34c697c85e9d0af11a72ac4df5578aac94a627b3

It fixes the problem where the layout of a type was being accessed
while its base classes were not populated yet; which caused an
incorrect layout to be produced and cached.

This fixes PR50054

Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D100977
2021-04-26 15:23:58 +02:00
Michał Górny 06215023f4 [lldb] [Process/NetBSD] Report fork/vfork events to LLGS
Differential Revision: https://reviews.llvm.org/D100554
2021-04-25 19:40:59 +02:00
Michał Górny 65f2a75737 [lldb] [Process/FreeBSD] Report fork/vfork events to LLGS
Differential Revision: https://reviews.llvm.org/D100547
2021-04-25 19:40:46 +02:00
Jason Molenda 6fca189532 Simplify the breakpoint setting in DynamicLoaderMacOS::SetNotificationBreakpoint
Instead of looking up a symbol and reducing it to an addr_t to set
a breakpoint, set the breakpoint on the function name directly.
The old Mac OS X dynamic loader plugin worked in terms of addresses
and I incorrectly emulated that here when I wrote this newer one.

Differential Revision: https://reviews.llvm.org/D100931
2021-04-24 14:03:41 -07:00
Michał Górny fd0af0cf08 [lldb] [Process/Linux] Report fork/vfork stop reason
Enable reporting fork/vfork events to the server when supported.
At this moment, this is used only to test the server code, as real
client does not report fork-events and vfork-events as supported.

Differential Revision: https://reviews.llvm.org/D100208
2021-04-24 11:08:34 +02:00
Michał Górny bbae0c1f7b [lldb] [llgs] Support owning and detaching extra processes
Add a NativeDelegate API to pass new processes (forks) to LLGS,
and support detaching them via the 'D' packet.  A 'D' packet without
a specific PID detaches all processes, otherwise it detaches either
the specified subprocess or the main process, depending on the passed
PID.

Differential Revision: https://reviews.llvm.org/D100191
2021-04-24 11:08:33 +02:00
Michał Górny 6c37984eba [lldb] [gdb-remote server] Introduce new stop reasons for fork and vfork
Introduce three new stop reasons for fork, vfork and vforkdone events.
This includes server support for serializing fork/vfork events into
gdb-remote protocol.  The stop infos for the two base events take a pair
of PID and TID for the newly forked process.

Differential Revision: https://reviews.llvm.org/D100196
2021-04-24 11:08:33 +02:00
Michał Górny 312257688e [lldb] [Process] Introduce protocol extension support API
Introduce a NativeProcessProtocol API for indicating support for
protocol extensions and enabling them.  LLGS calls
GetSupportedExtensions() method on the process factory to determine
which extensions are supported by the plugin.  If the future is both
supported by the plugin and reported as supported by the client, LLGS
enables it and reports to the client as supported by the server.

The extension is enabled on the process instance by calling
SetEnabledExtensions() method.  This is done after qSupported exchange
(if the debugger is attached to any process), as well as after launching
or attaching to a new inferior.

The patch adds 'fork' extension corresponding to 'fork-events+'
qSupported feature and 'vfork' extension for 'vfork-events+'.  Both
features rely on 'multiprocess+' being supported as well.

Differential Revision: https://reviews.llvm.org/D100153
2021-04-24 11:08:33 +02:00
Raphael Isemann f3e6f856c2 [lldb][NFC] Remove a stray unicode character in the LLDB test docs
There was a U+2028 character in this line (a special paragraph separator).
2021-04-23 13:20:10 +02:00
Raphael Isemann f8f3fc1fba [lldb][NFC] Delete a checked-in build log in docs/testsuite 2021-04-23 10:36:43 +02:00
Jonas Devlieghere 91d3f73937 [lldb] Update register state parsing for JSON crashlogs
- The register encoding state in the JSON crashlog format changes.
   Update the parser accordingly.
 - Print the register state when printing the symbolicated thread.
2021-04-22 16:40:59 -07:00
Fred Riss 91e90cf622 lldb/Instrumentation: NFC-ish use GetFrameCodeAddressForSymbolication()
A couple of our Instrumentation runtimes were gathering backtraces,
storing it in a StructuredData array and later creating a HistoryThread
using this data. By deafult HistoryThread will consider the history PCs
as return addresses and thus will substract 1 from them to go to the
call address.

This is usually correct, but it's also wasteful as when we gather the
backtraces ourselves, we have much better information to decide how
to backtrace and symbolicate. This patch uses the new
GetFrameCodeAddressForSymbolication() to gather the PCs that should
be used for symbolication and configures the HistoryThread to just
use those PCs as-is.

(The MTC plugin was actaully applying a -1 itself and then the
HistoryThread would do it again, so this actaully fixes a bug there.)

rdar://77027680

Differential Revision: https://reviews.llvm.org/D101094
2021-04-22 13:32:43 -07:00
Jan Kratochvil 18a8527642 [trace][intel-pt] Fix a crash on unconsumed Expected's Error
Reproducible with build using libipt and -DLLVM_ENABLE_ASSERTIONS=ON:
(lldb) b main
(lldb) r
(lldb) process trace start
2021-04-22 22:27:08 +02:00
Adrian Prantl 007158ac42 Skip unreliable LLDB tests when running under asan 2021-04-22 11:55:43 -07:00
Jonas Devlieghere a62cbd9a02 [lldb] Include thread name in crashlog.py output
Update the JSON parser to include the thread name in the Thread object.

rdar://76677320
2021-04-22 11:38:53 -07:00
Raphael Isemann d616a6bd10 [lldb] Fix that the expression commands --top-level flag overwrites --allow-jit false
The `--allow-jit` flag allows the user to force the IR interpreter to run the
provided expression.

The `--top-level` flag parses and injects the code as if its in the top level
scope of a source file.

Both flags just change the ExecutionPolicy of the expression:
* `--allow-jit true` -> doesn't change anything (its the default)
* `--allow-jit false` -> ExecutionPolicyNever
* `--top-level` -> ExecutionPolicyTopLevel

Passing `--allow-jit false` and `--top-level` currently causes the `--top-level`
to silently overwrite the ExecutionPolicy value that was set by `--allow-jit
false`. There isn't any ExecutionPolicy value that says "top-level but only
interpret", so I would say we reject this combination of flags until someone
finds time to refactor top-level feature out of the ExecutionPolicy enum.

The SBExpressionOptions suffer from a similar symptom as `SetTopLevel` and
`SetAllowJIT` just silently disable each other. But those functions don't have
any error handling, so not a lot we can do about this in the meantime.

Reviewed By: labath, kastiglione

Differential Revision: https://reviews.llvm.org/D91780
2021-04-22 18:51:03 +02:00
Pavel Labath e5984a3680 [lldb/elf] Avoid side effects in function calls ParseUnwindSymbols
This addresses post-commit feedback to cd64273.
2021-04-22 14:31:00 +02:00
Raphael Isemann e3dd82ae3c [lldb] Don't leak LineSequence in PDB parsers
`InsertSequence` doesn't take ownership of the pointer so releasing this pointer
is just leaking memory.

Follow up to D100806 that was fixing other leak sanitizer test failures

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D100846
2021-04-22 14:11:01 +02:00
Raphael Isemann d2223c7a49 [lldb] XFAIL TestStoppedInStaticMemberFunction on Windows
It seems we can't find the symbols of static members on Windows? The bug is not
 relevant to what this test is actually testing so let's just XFAIL it.
2021-04-22 13:46:27 +02:00
Benjamin Kramer edc869cb57 [lldb-vscode] Use a DenseMap to pacify overly aggressive linters
Some linters get rather upset upon seeing
`std::unordered_map<const char*`, because it looks like a map of
strings but isn't. lldb uses interned strings so this is not a problem.
DenseMap is a better data structure for this anyways, so use that
instead.
2021-04-22 13:07:39 +02:00
Raphael Isemann 034c73d42e [lldb][NFC] Fix unsigned/signed cmp warning in MainLoopTest
The gtest checks compare all against unsigned int constants so this also needs
to be unsigned.
2021-04-22 12:20:32 +02:00
Raphael Isemann 00764c36ed [lldb] Add support for evaluating expressions in static member functions
At the moment the expression parser doesn't support evaluating expressions in
static member functions and just pretends the expression is evaluated within a
non-member function. This causes that all static members are inaccessible when
doing unqualified name lookup.

This patch adds support for evaluating in static member functions. It
essentially just does the same setup as what LLDB is already doing for
non-static member functions (i.e., wrapping the expression in a fake member
function) with the difference that we now mark the wrapping function as static
(to prevent access to non-static members).

Reviewed By: shafik, jarin

Differential Revision: https://reviews.llvm.org/D81550
2021-04-22 12:14:31 +02:00
Jonas Devlieghere 39ea3ceda3 [lldb] Disable TestSimulatorPlatform.py because it's causing a SIGHUP
Ever since Dave Zarzycki's patch to sort test start times based on prior
test timing data (https://reviews.llvm.org/D98179) the test suite aborts
with a SIGHUP. I don't believe his patch is to blame, but rather
uncovers an preexisting issue by making test runs more deterministic.

I was able to narrow down the issue to TestSimulatorPlatform.py. The
issue also manifests itself on the standalone bot on GreenDragon [1].
This patch disables the test until we can figure this out.

[1] http://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake-standalone/

rdar://76995109
2021-04-21 20:00:51 -07:00
Walter Erquinigo 875654f897 Fix VSCode/TestOptions.test
Found by https://lab.llvm.org/buildbot/#/builders/96/builds/6936
2021-04-21 15:46:26 -07:00
Walter Erquinigo c4a83c4e69 Fix TestVSCode_runInTerminal
It failed in https://lab.llvm.org/buildbot/#/builders/68/builds/10912

And it was caused due to https://reviews.llvm.org/rG64f47c1e58a1
2021-04-21 15:20:47 -07:00
Walter Erquinigo c9a0754b44 [lldb-vscode] Distinguish shadowed variables in the scopes request
VSCode doesn't render multiple variables with the same name in the variables view. It only renders one of them. This is a situation that happens often when there are shadowed variables.
The nodejs debugger solves this by adding a number suffix to the variable, e.g. "x", "x2", "x3" are the different x variables in nested blocks.

In this patch I'm doing something similar, but the suffix is " @ <file_name:line>), e.g. "x @ main.cpp:17", "x @ main.cpp:21". The fallback would be an address if the source and line information is not present, which should be rare.

This fix is only needed for globals and locals. Children of variables don't suffer of this problem.

When there are shadowed variables
{F16182150}

Without shadowed variables
{F16182152}

Modifying these variables through the UI works

Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D99989
2021-04-21 15:09:39 -07:00
Walter Erquinigo 64f47c1e58 [lldb-vscode] redirect stderr/stdout to the IDE's console
In certain occasions times, like when LLDB is initializing and
evaluating the .lldbinit files, it tries to print to stderr and stdout
directly. This confuses the IDE with malformed data, as it talks to
lldb-vscode using stdin and stdout following the JSON RPC protocol. This
ends up terminating the debug session with the user unaware of what's
going on. There might be other situations in which this can happen, and
they will be harder to debug than the .lldbinit case.

After several discussions with @clayborg, @yinghuitan and @aadsm, we
realized that the best course of action is to simply redirect stdout and
stderr to the console, without modifying LLDB itself. This will prove to
be resilient to future bugs or features.

I made the simplest possible redirection logic I could come up with. It
only works for POSIX, and to make it work with Windows should be merely
changing pipe and dup2 for the windows equivalents like _pipe and _dup2.
Sadly I don't have a Windows machine, so I'll do it later once my office
reopens, or maybe someone else can do it.

I'm intentionally not adding a stop-redirecting logic, as I don't see it
useful for the lldb-vscode case (why would we want to do that, really?).

I added a test.

Note: this is a simpler version of D80659. I first tried to implement a
RIIA version of it, but it was problematic to manage the state of the
thread and reverting the redirection came with some non trivial
complexities, like what to do with unflushed data after the debug
session has finished on the IDE's side.
2021-04-21 14:48:48 -07:00
Walter Erquinigo 12a2507646 Fix TestVSCode_launch test
Broken in https://lab.llvm.org/buildbot/#/builders/96/builds/6933

We don't really need to run this test on arm, but would be worth fixing
it later.
2021-04-21 14:33:34 -07:00
Walter Erquinigo 79fbbeb412 [lldb-vscode] Add postRunCommands
This diff ass postRunCommands, which are the counterpart of the preRunCommands. TThey will be executed right after the target is launched or attached correctly, which means that the targets can assume that the target is running.

Differential Revision: https://reviews.llvm.org/D100340
2021-04-21 13:51:30 -07:00
Jonas Devlieghere 5d1c43f333 [lldb] Use the compiler from the SDK in simulator tests
Use the clang compiler from the SDK to build the simulator test programs
to ensure we pick up the correct libc++.
2021-04-21 13:22:58 -07:00
Jordan Rupprecht eb5e11f460 [lldb] Fix RichManglingContext::FromCxxMethodName() leak
`RichManglingContext::FromCxxMethodName` allocates a m_cxx_method_parser, but never deletes it.

This fixes a `-DLLVM_USE_SANITIZER=Leaks` failure.

Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D100795
2021-04-21 12:32:08 -07:00
Michał Górny e414ede2cd [lldb] [test/Register] Initial tests for regsets in core dumps
Add initial tests for reading register sets from core dumps.  This
includes a C++ program to write registers and dump core, resulting core
dumps for Linux, FreeBSD and NetBSD, and the tests to verify them.

The tests are split into generic part, verifying user-specified register
values, and coredump-specific tests that verify memory addresses that
differ for every dump.

At this moment, all platforms support GPRs and FPRs up to XMM for amd64
target.  The i386 target does not work on NetBSD at all, and is missing
FPRs entirely on FreeBSD.

Differential Revision: https://reviews.llvm.org/D91963
2021-04-21 19:41:09 +02:00