Commit Graph

24330 Commits

Author SHA1 Message Date
Andy Yankovsky 754ab803b8 [lldb] Use current execution context in SBDebugger
Use `GetSelectedExecutionContext()` instead of
`GetCommandInterpreter().GetExecutionContext()` in
`SBDebugger::GetInternalVariableValue/SBDebugger::SetInternalVariable`. The
execution context in the command interpreter might be empty, if no commands has
been executed yet (it is updated only when handling commands or completions --
e.g.
https://github.com/llvm/llvm-project/blob/main/lldb/source/Interpreter/CommandInterpreter.cpp#L1855).

Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D95761
2021-02-01 13:12:42 +01:00
Martin Storsjö 11e74e512d [lldb] Remove a stray semicolon, fixing GCC warnings. NFC. 2021-02-01 13:45:07 +02:00
Med Ismail Bennani b8923c0022 [lldb/API] Expose Module::IsLoadedInTarget() to SB API (NFC)
This patch adds an `SBTarget::IsLoaded(const SBModule&) const` endpoint
to lldb's Scripting Bridge API. As the name suggests, it will allow the
user to know if the module is loaded in a specific target.

rdar://37957625

Differential Review: https://reviews.llvm.org/D95686

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-02-01 12:16:33 +01:00
xgupta 94fac81fcc [Branch-Rename] Fix some links
According to the [[ https://foundation.llvm.org/docs/branch-rename/ | status of branch rename ]], the master branch of the LLVM repository is removed on 28 Jan 2021.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D95766
2021-02-01 16:43:21 +05:30
Raphael Isemann 2939d2e1b4 [lldb][docs] Attempt to disable the generated GitHub button on the LLDB website
For unknown reasons the alabaster theme on the docs server is always generating
a GitHub link in the side bar. Beside the privacy problems of having an iframe
to some third-party service, we never configured any GitHub integration so
this button just links to the GitHub main site.

The button generation should be disabled by default, but as that's apparently
not true in the alabaster theme on the server, this patch tries working around
the issue by just explicitly turning off the GitHub integration.
2021-02-01 09:47:39 +01:00
Michał Górny 9d029362d1 [lldb] [Process/FreeBSDRemote] Introduce arm (32-bit) support
Introduce a NativeRegisterContextFreeBSD for 32-bit ARM platform.
This includes support for GPR + VFP registers as exposed by FreeBSD's
ptrace(2) API.  Hardware breakpoints or watchpoints are not supported
due to missing kernel support.  The code is roughly based on the arm64
context.

It also includes an override for GetSoftwareBreakpointTrapOpcode() based
on the matching code in the PlatformFreeBSD plugin.

Differential Revision: https://reviews.llvm.org/D95696
2021-01-31 19:52:08 +01:00
Michał Górny f43c0707f6 [lldb] [Process/FreeBSDRemote] Introduce arm64 support
Introduce arm64 support in the FreeBSDRemote plugin.  The code
is roughly based on Linux and reuses the same POSIX RegisterInfos
(but the buffers need to be a few bytes larger due to stricter struct
member alignment in FreeBSD structures -- luckily, they do not affect
the actual member offsets).  It supports reading and writing
general-purpose and FPU registers.  SVE and hardware watchpoint support
is missing due to the limitations of FreeBSD ptrace(2) API.

Differential Revision: https://reviews.llvm.org/D95297
2021-01-31 19:52:08 +01:00
Nathan Hawes 719f778441 [VFS] Combine VFSFromYamlDirIterImpl and OverlayFSDirIterImpl into a single implementation (NFC)
As a fixme notes, both of these directory iterator implementations are
conceptually similar and duplicate the functionality of returning and uniquing
entries across two or more directories. This patch combines them into a single
class 'CombiningDirIterImpl'.

This also drops the 'Redirecting' prefix from RedirectingDirEntry and
RedirectingFileEntry to save horizontal space. There's no loss of clarity as
they already have to be prefixed with 'RedirectingFileSystem::' whenever
they're referenced anyway.

rdar://problem/72485443
Differential Revision: https://reviews.llvm.org/D94857
2021-01-30 11:10:10 +10:00
serge-sans-paille 27f2fe9163 Adapt lldb-instr to d47ee525f9 APi change 2021-01-29 10:58:40 +01:00
Jonas Devlieghere b2545b71d1 [lldb] Use `foo is None` instead of `not foo` in darwin.py
Explicitly compare to None when checking the triple's components so we
don't bail out when one of them is the empty string.
2021-01-28 20:03:44 -08:00
Walter Erquinigo 0bca9a7ce2 Fix lldb-vscode builds on Windows targeting POSIX
@stella.stamenova found out that lldb-vscode's Win32 macros were failing
when building on windows targetings POSIX platforms.

I'm changing these macros for LLVM_ON_UNIX, which should be more
accurate.
2021-01-28 09:36:13 -08:00
Walter Erquinigo ab5591e1d8 Fix runInTerminal failures on Windows
stella.stemenova mentioned in https://reviews.llvm.org/D93951 failures on Windows for this test.

I'm fixing the macro definitions and disabling the tests for python
versions lower than 3.7. I'll figure out that actual issue with
python3.6 after the buildbots are fine again.
2021-01-27 13:17:23 -08:00
Raphael Isemann e2a1a718bb [lldb] Add move_iterator to supported template list
Identical to previous commits that just add a standard library template to the
supported template list and test it. Adding this rather obscure class to the
template list is mostly caused by the std::deque test unexpectedly referencing
this type when testing against newer libc++ versions on macOS.

Fixes TestQueueFromStdModule and TestQueueFromStdModule on macOS.
Fixes rdar://73213589
2021-01-27 13:52:42 +01:00
Jim Ingham 7636b1f6ef Make SBDebugger::CreateTargetWithFileAndArch work with lldb::LLDB_DEFAULT_ARCH
Second try, handling both a bogus arch string and the "null file & arch" used
to create an empty but valid target.
Also check in that case before logging (previously the logging would have
crashed.)
2021-01-26 12:17:39 -08:00
Raphael Isemann 48e09faa94 [lldb][NFC] Another attempt to fix GCC 5.x compilation
37510f69b4 tried to fix GCC 5.x compilation
by making the enum which is used as a unordered_map key unscoped. However it
seems that in GCC 5.x, enum keys are not supported *at all* in unordered_maps
(at least that's what some trial&error on godbolt tells me). This updates the
workaround to just use an int until GCC 5.x support is dropped.
2021-01-26 19:13:12 +01:00
Dave Lee 90b8ae016b [lldb] Remove unused ThreadPlanStack::GetStackOfKind (NFC)
This function isn't used.

Differential Revision: https://reviews.llvm.org/D95411
2021-01-26 09:22:25 -08:00
Georgii Rymar 2a33b092f5 [LLDB][test] - Fix test after yaml2obj change.
D95354 started to set the sh_link field for SHT_SYMTAB sections.
Previously it was set for symbol tables basing on their names (e.g. ".symtab").

This test now crashes see:
http://lab.llvm.org:8011/#/builders/68/builds/5911

I updated it to restore the old behavior.
2021-01-26 12:42:54 +03:00
Richard Smith 8b11714885 Revert "Fix SBDebugger::CreateTargetWithFileAndArch to accept LLDB_ARCH_DEFAULT."
Also revert "Follow on to: f05dc40c31d1883b46b8bb60547087db2f4c03e3"

After these changes, multiple lldb tests are failing. Calls to
CreateTargetWithFileAndArch(None, None) appear to fail after these
changes.

This reverts commit f05dc40c31 and
1fba21778f.
2021-01-25 18:05:17 -08:00
Duncan P. N. Exon Smith 8b6aedc4c9 ExpressionParser: Migrate to FileEntryRef in ParseInternal, NFC
Migrate to the `FileEntryRef` overload of `SourceManager::createFileID`
(using `FileManager::getOptionalFileRef`) in
`ClangExpressionParser::ParseInternal`.

No functionality change here.

Differential Revision: https://reviews.llvm.org/D92957
2021-01-25 16:38:42 -08:00
Pedro Tammela 532e4203c5 [lldb/Lua] add support for Lua function breakpoint
Adds support for running a Lua function when a breakpoint is hit.

Example:
   breakpoint command add -s lua -F abc

The above runs the Lua function 'abc' passing 2 arguments. 'frame', 'bp_loc' and 'extra_args'.

A third parameter 'extra_args' is only present when there is structured data
declared in the command line.

Example:
   breakpoint command add -s lua -F abc -k foo -v bar

Differential Revision: https://reviews.llvm.org/D93649
2021-01-25 23:40:57 +00:00
David Blaikie 6846686128 Fix -Wmissing-override in lldb 2021-01-25 15:04:21 -08:00
Walter Erquinigo 50337fb933 Fix runInTerminal errors on ARM
Caused by https://reviews.llvm.org/D93951

This feature is not needed on ARM, so let's just disable the tests on
ARM.
2021-01-25 14:55:15 -08:00
Jim Ingham 1fba21778f Follow on to: f05dc40c31
When you pass in a bogus ArchSpec, TargetList.CreateTarget
makes a target with the arch of the executable.  That wasn't the
case with a bogus triple, so this change caused one of the bogus
input data tests to fail.  So check that the ArchSpec is valid
before passing it to CreateTarget.
2021-01-25 14:25:51 -08:00
Walter Erquinigo 1ac36b34db Fix 0f0462cacf
This fails on Windows because std::future<llvm::Error> fail to compile.
Now switching to SBError as a workaround.

Failed buildbot: http://lab.llvm.org:8011/#/builders/83/builds/3021
2021-01-25 14:06:10 -08:00
Walter Erquinigo 12049d8885 Fix 0f0462cacf
This test fails on ARM, but this feature won't be used on ARM, so we can
disable it for that architecture.
2021-01-25 13:24:57 -08:00
Jim Ingham f05dc40c31 Fix SBDebugger::CreateTargetWithFileAndArch to accept LLDB_ARCH_DEFAULT.
The API docs in SBDebugger.i claim this should work but it doesn't.  This
should fix it.

Differential Revision: https://reviews.llvm.org/D95164
2021-01-25 12:53:37 -08:00
Walter Erquinigo 0f0462cacf [vscode] Improve runInTerminal and support linux
Depends on D93874.

runInTerminal was using --wait-for, but it was some problems because it uses process polling looking for a single instance of the debuggee:

- it gets to know of the target late, which renders breakpoints in the main function almost impossible
- polling might fail if there are already other processes with the same name
- polling might also fail on some linux machine, as it's implemented with the ps command, and the ps command's args and output are not standard everywhere

As a better way to implement this so that it works well on Darwin and Linux, I'm using now the following process:

- lldb-vscode notices the runInTerminal, so it spawns lldb-vscode with a special flag --launch-target <target>. This flags tells lldb-vscode to wait to be attached and then it execs the target program. I'm using lldb-vscode itself to do this, because it makes finding the launcher program easier. Also no CMAKE INSTALL scripts are needed.
- Besides this, the debugger creates a temporary FIFO file where the launcher program will write its pid to. That way the debugger will be sure of which program to attach.
- Once attach happend, the debugger creates a second temporary file to notify the launcher program that it has been attached, so that it can then exec. I'm using this instead of using a signal or a similar mechanism because I don't want the launcher program to wait indefinitely to be attached in case the debugger crashed. That would pollute the process list with a lot of hanging processes. Instead, I'm setting a 20 seconds timeout (that's an overkill) and the launcher program seeks in intervals the second tepmorary file.

Some notes:
- I preferred not to use sockets because it requires a lot of code and I only need a pid. It would also require a lot of code when windows support is implemented.
- I didn't add Windows support, as I don't have a windows machine, but adding support for it should be easy, as the FIFO file can be implemented with a named pipe, which is standard on Windows and works pretty much the same way.

The existing test which didn't pass on Linux, now passes.

Differential Revision: https://reviews.llvm.org/D93951
2021-01-25 12:30:05 -08:00
Walter Erquinigo 4bb6244871 [ThreadPlan] fix exec on Linux 2021-01-25 11:30:48 -08:00
Muhammad Omair Javaid e9a3fac76c [LLDB] Skip TestPlatformProcessConnect on arm/aarch64 buildbot
TestPlatformProcessConnect is randomly failing on LLDB Arm/AArch64
buildbot. I am disabling it temporarily untill problem is fixed.
2021-01-25 20:48:16 +05:00
Muhammad Omair Javaid 2fd4d923a8 [LLDB] Define AUXV_AT_HWCAP2 in AuxVector.h
This patch defines AUXV_AT_HWCAP2 for accessing Aux extensions.
2021-01-25 20:48:16 +05:00
Muhammad Omair Javaid b45020cf63 [LLDB] Remove leftovers and typos from RegisterInfos_arm64_sve.h
This patch removes a couple of left-overs and a typo from
RegisterInfos_arm64_sve.h and RegisterInfoPOSIX_arm64.h.
2021-01-25 20:48:15 +05:00
David Blaikie 78d41a1295 lldb: Add support for printing variables with DW_AT_ranges on DW_TAG_subprograms
Finishing out the support (to the best of my knowledge/based on current
testing running the whole check-lldb with a clang forcibly using
DW_AT_ranges on all DW_TAG_subprograms) for this feature.

Differential Revision: https://reviews.llvm.org/D94064
2021-01-24 18:39:06 -08:00
Augusto Noronha 2afaf072f5 Implement vAttachOrWait
Implements the required functions on gdb-remote so the '--include-existing' flag of process attach works correctly on Linux.

Reviewed By: labath, clayborg

Differential Revision: https://reviews.llvm.org/D94672
2021-01-24 21:30:09 +01:00
Fangrui Song 50830e5003 [lldb] Add -Wl,-rpath to make tests run with fresh built libc++
On my Debian machine, system libc++/libc++abi is not installed (`libc++1-9 libc++abi-9`),
21 check-lldb-api tests fail because -stdlib=libc++ linked executables cannot
find runtime libc++.so.1 at runtime.

Use the `-Wl,-rpath,$(LLVM_LIBS_DIR)` mechanism in
`packages/Python/lldbsuite/test/make/Makefile.rules` (D58630 for NetBSD) to
allow such tests compile/link with fresh libc++ built beside lldb.
(A system libc++.so.1 is not guaranteed to match fresh libc++ header files.)

Some tweaks to the existing NetBSD rule when generalizing:

* Drop `-L$(LLVM_LIBS_DIR)` since Clang driver adds it correctly.
* Add `-stdlib=libc++` only for `USE_LIBCPP`.

Also, drop `-isystem /usr/include/c++/v1` introduced in D9426. It is not needed
by Clang driver. GCC using libc++ requires more setup.

I don't find any test needing `-Wl,-rpath` in `test/Shell/helper/{build,toolchain}.py` (D58630 for NetBSD added them).

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D94888
2021-01-24 20:21:57 +00:00
Pedro Tammela 2bbc762b8f [lldb/Lua] add 'Lua' before naming versions
NFC
2021-01-23 15:20:54 +00:00
Pedro Tammela 5997e8987f [lldb/Lua] add initial Lua typemaps
This patch adds the integer handling typemaps and the typemap for
string returning functions.

The integer handling typemaps overrides SWIG's own typemaps to distinct
the handling of integers from floating point.

The typemap for string returning functions is a port of Python's
typemap.

Differential Revision: https://reviews.llvm.org/D94937
2021-01-23 14:53:11 +00:00
Jason Molenda ad25bdcb8e Change static buffer to be BSS instead of DATA in HandlePacket_qSpeedTest
Having this 4MB buffer with a compile-time initialized string forced it
into the DATA section and it took up 4MB of space in the binary, which
accounts for like 80% of debugserver's footprint on disk.  Change it to
BSS and strcpy in the initial value at runtime instead.

<rdar://problem/73503892>
2021-01-22 16:14:24 -08:00
Jonas Devlieghere 3a50ed84f4 [lldb] FixFileSystem::GetExternalPath for VFS API change 2021-01-22 15:04:17 -08:00
Shafik Yaghmour dc057e87f6 [LLDB] Fix how ObjCBOOLSummaryProvider deals with BOOL
ObjCBOOLSummaryProvider was incorrectly treating BOOL as unsigned and this is now fixed.
Also adding tests for one bit bit-fields of BOOL and unsigned char.
2021-01-22 10:05:24 -08:00
Walter Erquinigo 39239f9b56 [lldb-vscode] improve modules request
lldb-vsdode was communicating the list of modules to the IDE with events, which in practice ended up having some drawbacks
- when debugging large targets, the number of these events were easily 10k, which polluted the messages being transmitted, which caused the following: a harder time debugging the messages, a lag after terminated the process because of these messages being processes (this could easily take several seconds). The latter was specially bad, as users were complaining about it even when they didn't check the modules view.
- these events were rarely used, as users only check the modules view when something is wrong and they try to debug things.

After getting some feedback from users, we realized that it's better to not used events but make this simply a request and is triggered by users whenever they needed.

This diff achieves that and does some small clean up in the existing code.

Differential Revision: https://reviews.llvm.org/D94033
2021-01-21 13:18:50 -08:00
Raphael Isemann 37510f69b4 [lldb][NFC] Fix build with GCC<6
GCC/libstdc++ before 6.1 can't handle scoped enums as unordered_map keys. LLVM
(and some build) bots officially support some GCC 5.x versions, so this patch
just makes the enum unscoped until we can require GCC 6.x.
2021-01-21 15:04:41 +01:00
Raphael Isemann ed2853d2c8 Reland [lldb] Fix TestThreadStepOut.py after "Flush local value map on every instruction"
The original patch got reverted as a dependency of cf1c774d6a .
That patch got relanded so it's also necessary to reland this patch.

Original summary:

After cf1c774d6a, Clang seems to generate code
that is more similar to icc/Clang, so we can use the same line numbers for
all compilers in this test.
2021-01-21 13:35:13 +01:00
Raphael Isemann 060b51e052 [lldb] Make TestBSDArchives a no-debug-info-test
The DSYM variant of this test is failing since D94890. But as we explicitly
try to disable the DSYM generation in the makefile and build the archive on
our own, I don't see why we even need to run the DSYM version of the test.

This patch disables the generated derived versions of this test for the
different debug information containers (which includes the failing DSYM one).
2021-01-21 13:06:48 +01:00
Raphael Isemann 99b7b41edf [lldb][import-std-module] Do some basic file checks before trying to import a module
Currently when LLDB has enough data in the debug information to import the `std` module,
it will just try to import it. However when debugging libraries where the sources aren't
available anymore, importing the module will generate a confusing diagnostic that
the module couldn't be built.

For the fallback mode (where we retry failed expressions with the loaded module), this
will cause the second expression to fail with a module built error instead of the
actual parsing issue in the user expression.

This patch adds checks that ensures that we at least have any source files in the found
include paths before we try to import the module. This prevents the module from being
loaded in the situation described above which means we don't emit the bogus 'can't
import module' diagnostic and also don't waste any time retrying the expression in the
fallback mode.

For the unit tests I did some refactoring as they now require a VFS with the files in it
and not just the paths. The Python test just builds a binary with a fake C++ module,
then deletes the module before debugging.

Fixes rdar://73264458

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D95096
2021-01-21 12:32:51 +01:00
Jonas Devlieghere baf6c2987e [lldb] Upstream eCore_arm_arm64e enum value in ArchSpec
Upstream the eCore_arm_arm64e enum value in ArchSpec. All the other
arm64e triple changes already landed in LLVM.

Differential revision: https://reviews.llvm.org/D95110
2021-01-20 19:39:47 -08:00
Jim Ingham 98feb08e44 Use CXX_SOURCES and point to the right source file.
Copy paste error, but the test still built on macOS.  Weird.
It failed on debian linux with an error about -fno-limit-debug-info
not being a supported flag???  Not sure how this goof would cause
that error, but let's see if it did...
2021-01-20 18:38:07 -08:00
Jim Ingham bff389120f Fix a bug with setting breakpoints on C++11 inline initialization statements.
If they occurred before the constructor that used them, we would refuse to
set the breakpoint because we thought they were crossing function boundaries.

Differential Revision: https://reviews.llvm.org/D94846
2021-01-20 17:58:34 -08:00
Fangrui Song 6afdf13ae4 Makefile.rules: Avoid redundant .d generation (make restart) and inline archive rule to the only test
Take an example when `CXX_SOURCES` is main.cpp.

main.d is an included file. make will rebuild main.d, re-executes itself [1] to read
in the new main.d file, then rebuild main.o, finally link main.o into a.out.
main.cpp is parsed twice in this process.

This patch merges .d generation into .o generation [2], writes explicit rules
for .c/.m and deletes suffix rules for %.m and %.o. Since a target can be
satisfied by either of .c/.cpp/.m/.mm, we use multiple pattern rules. The
rule with the prerequisite (with VPATH considered) satisfied is used [3].

Since suffix rules are disabled, the implicit rule for archive member targets is
no long available [4]. Rewrite, simplify the archive rule and inline it into the
only test `test/API/functionalities/archives/Makefile`.

[1]: https://www.gnu.org/software/make/manual/html_node/Remaking-Makefiles.html
[2]: http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/
[3]: https://www.gnu.org/software/make/manual/html_node/Pattern-Match.html
[4]: https://www.gnu.org/software/make/manual/html_node/Archive-Update.html

ObjC/ObjCXX tests only run on macOS. I don't have testing environment.  Hope
someone can do it for me.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D94890
2021-01-20 14:22:33 -08:00
Med Ismail Bennani 8fc9b6c2c5
[lldb/Commands] Align process launch --plugin with process attach (NFC)
Following `7169d3a315f4cdc19c4ab6b8f20c6f91b46ba9b8`, this patch updates
the short option for the plugin command option to (`-p` to `-P`) to
align with the `process attach` command options.

The long option remains the same since there are already the same for both
commands.

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-01-20 21:01:23 +01:00
Pavel Labath 599fdfc5db Revert "[lldb] Re-enable TestPlatformProcessConnect on macos"
This reverts commit 079e664661. It needs
more work.
2021-01-20 20:49:03 +01:00
Med Ismail Bennani 7169d3a315 [lldb/Commands] Refactor ProcessLaunchCommandOptions to use TableGen (NFC)
This patch refactors the current implementation of
`ProcessLaunchCommandOptions` to be generated by TableGen.

The patch also renames the class to `CommandOptionsProcessLaunch` to
align better with the rest of the codebase style and moves it to
separate files.

Differential Review: https://reviews.llvm.org/D95059

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-01-20 18:53:06 +01:00
Hans Wennborg 8ba442bc21 Revert "Following up on PR48517, fix handling of template arguments that refer"
Combined with 'da98651 - Revert "DR2064:
decltype(E) is only a dependent', this change (5a391d3) caused verifier
errors when building Chromium. See https://crbug.com/1168494#c1 for a
reproducer.

Additionally it reverts changes that were dependent on this one, see
below.

> Following up on PR48517, fix handling of template arguments that refer
> to dependent declarations.
>
> Treat an id-expression that names a local variable in a templated
> function as being instantiation-dependent.
>
> This addresses a language defect whereby a reference to a dependent
> declaration can be formed without any construct being value-dependent.
> Fixing that through value-dependence turns out to be problematic, so
> instead this patch takes the approach (proposed on the core reflector)
> of allowing the use of pointers or references to (but not values of)
> dependent declarations inside value-dependent expressions, and instead
> treating template arguments as dependent if they evaluate to a constant
> involving such dependent declarations.
>
> This ends up affecting a bunch of OpenMP tests, due to OpenMP
> imprecisely handling instantiation-dependent constructs, bailing out
> early instead of processing dependent constructs to the extent possible
> when handling the template.
>
> Previously committed as 8c1f2d15b8, and
> reverted because a dependency commit was reverted.

This reverts commit 5a391d38ac.

It also restores clang/test/SemaCXX/coroutines.cpp to its state before
da986511fb.

Revert "[c++20] P1907R1: Support for generalized non-type template arguments of scalar type."

> Previously committed as 9e08e51a20, and
> reverted because a dependency commit was reverted. This incorporates the
> following follow-on commits that were also reverted:
>
> 7e84aa1b81 by Simon Pilgrim
> ed13d8c667 by me
> 95c7b6cadb by Sam McCall
> 430d5d8429 by Dave Zarzycki

This reverts commit 4b574008ae.

Revert "[msabi] Mangle a template argument referring to array-to-pointer decay"

> [msabi] Mangle a template argument referring to array-to-pointer decay
> applied to an array the same as the array itself.
>
> This follows MS ABI, and corrects a regression from the implementation
> of generalized non-type template parameters, where we "forgot" how to
> mangle this case.

This reverts commit 18e093faf7.
2021-01-20 15:55:35 +01:00
Raphael Isemann b3c260d8fa [lldb][docs] Expand CSS fix for LLDB doc tables
Apparently the sphinx version on the server doesn't place <p> tags in the
table cells, so the previous fix from commit 7fce3b240b
didn't fix the bug for that sphinx version. Just expand the CSS workaround
to all <td> tags.
2021-01-20 10:30:00 +01:00
Raphael Isemann 3c69ff4b03 [lldb][docs] Filter out 'thisown' attribute and inheritance boilerplate
This patch implements a filter that post-processes some of the generated RST sources
of the Python API docs. I mainly want to avoid two things:

1. Filter out all the inheritance boilerplate that just keeps mentioning for
every class that it inherits from the builtin 'object'. There is no inheritance
in the SB API.

2. More importantly, removes the SWIG generated `thisown` attribute from the
public documentation. I don't think we want users to mess with that attribute
and this is probably causing more confusion than it would help anyone. It also
makes the documentation for some smaller classes more verbose than necessary.

This patch just uses the sphinx event for reading source and removes the parts
that we don't want in documentation.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D94967
2021-01-20 09:07:36 +01:00
Raphael Isemann 7fce3b240b [lldb][docs] Remove -webkit-hyphens in table cells so that table widths are correct on Safari
The tables in the new LLDB documentation currently are less wide than their
contents. The reason for that seems to be the `-webkit-hyphens: auto` property
that sphinx is setting for all `p` tags. The `p` tags in the generated Python
documentation seem to trigger some Safari layout issue, so Safari is calculating
the cell width to be smaller than it should be (which ends up looking like this
{F15104344} ).

This patch just sets that property back to the browser default `manual`. Not
sure if that's the proper workaround, but I clicked around on the website with
the changed CSS and nothing looked funny (which is I believe how webdev unit
testing works).

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D94991
2021-01-20 09:05:28 +01:00
Stella Stamenova 3471455384 [lldb/test] Skip TestProcessAttach: test_attach_to_process_from_different_dir_by_id on Windows
This test is flakey on Windows and on failure it hangs causing the test suite to fail and future builds (on the buildbot, especially) to fail because they cannot re-write the files that are currently in use
2021-01-19 14:09:09 -08:00
Raphael Isemann 2f80995090 [lldb][docs] Update .htaccess to redirect from old SB API documentation to new one
This is mostly SEO so that the new API can take over the old API when people
search for the different SB* classes. Sadly epydoc decided to throw in a -class
prefix behind all the class file names, so we can't just overwrite the old files
with the newly generated ones.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D94900
2021-01-19 18:58:43 +01:00
Raphael Isemann 3cae8b3329 [lldb][docs] Add a doc page for enums and constants
Enums and constants are currently missing in the new LLDB Python API docs.

In theory we could just let them be autogenerated like the SB API classes, but sadly the generated documentation
suffers from a bunch of problems. Most of these problems come from the way SWIG is representing enums, which is
done by translating every single enum case into its own constant. This has a bunch of nasty effects:

* Because SWIG throws away the enum types, we can't actually reference the enum type itself in the API. Also because automodapi is impossible to script, this can't be fixed in post (at least without running like sed over the output files).
* The lack of enum types also causes that every enum *case* has its own full doc page. Having a full doc page that just shows a single enum case is pointless and it really slows down sphinx.
* There is no SWIG code for the enums, so there is also no place to write documentation strings for them. Also there is no support for copying the doxygen strings (which would be in the wrong format, but better than nothing) for enums (let alone our defines), so we can't really document all this code.
* Because the enum cases are just forwards to the native lldb module (which we mock), automodapi actually takes the `Mock` docstrings and adds it to every single enum case.

I don't see any way to solve this via automodapi or SWIG. The most reasonable way to solve this is IMHO to write a simple Clang tool
that just parses our enum/constant headers and emits an *.rst file that we check in. This way we can do all the LLDB-specific enum case and constant
grouping that we need to make a readable documentation page.

As we're without any real documentation until I get around to write that tool, I wrote a doc page for the enums/constants as a stop gap measure.
Most of this is done by just grepping our enum header and then manually cleaning up all the artifacts and copying the few doc strings we have.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D94959
2021-01-19 18:54:05 +01:00
Raul Tambre 480643a95c [CMake] Remove dead code setting policies to NEW
cmake_minimum_required(VERSION) calls cmake_policy(VERSION),
which sets all policies up to VERSION to NEW.
LLVM started requiring CMake 3.13 last year, so we can remove
a bunch of code setting policies prior to 3.13 to NEW as it
no longer has any effect.

Reviewed By: phosek, #libunwind, #libc, #libc_abi, ldionne

Differential Revision: https://reviews.llvm.org/D94374
2021-01-19 17:19:36 +02:00
Raphael Isemann 626681b09a [lldb] Fix two documentation typos 2021-01-19 15:25:15 +01:00
Muhammad Omair Javaid 4d3081331a [LLDB] Test SVE dynamic resize with multiple threads
This patch adds a new test case which depends on AArch64 SVE support and
dynamic resize capability enabled. It created two seperate threads which
have different values of sve registers and SVE vector granule at various
points during execution.

We test that LLDB is doing the size and offset updates properly for all
of the threads including the main thread and when we VG is updated using
prctl call or by 'register write vg' command the appropriate changes are
also update in register infos.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D82866
2021-01-19 15:01:32 +05:00
Muhammad Omair Javaid e448ad787e [LLDB] Add support to resize SVE registers at run-time
This patch builds on previously submitted SVE patches regarding expedited
register set and per thread register infos. (D82853 D82855 and D82857)

We need to resize SVE register based on value received in expedited list.
Also we need to resize SVE registers when we write vg register using
register write vg command. The resize will result in a updated offset
for all of fpr and sve register set. This offset will be configured
in native register context by RegisterInfoInterface and will also be
be updated on client side in GDBRemoteRegisterContext.

A follow up patch will provide a API test to verify this change.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D82863
2021-01-19 15:01:32 +05:00
Pavel Labath 079e664661 [lldb] Re-enable TestPlatformProcessConnect on macos
The test couldn't find lldb-server as it's path was being overridden by
LLDB_DEBUGSERVER_PATH environment variable (pointing to debugserver).
This test should always use lldb-server, as it tests its platform
capabilities.

There's no need for the environment override, as lldb-server tests
should test the executable they just built, so I just remote the
override capability.
2021-01-19 11:01:07 +01:00
David Spickett 9a7672ac49 [lldb] Fix crash in "help memory read"
When a command option does not have a short version
(e.g. -f for --file), we use an arbitrary value in the
short_option field to mark it as invalid.
(though this value is unqiue to be used later for other
things)

We check that this short option is valid to print using
llvm::isPrint. This implicitly casts our int to char,
meaning we check the last char of any short_option value.

Since the arbitrary value we chose for these options is
some shortened hex version of the name, this returned true
even for invalid values.

Since llvm::isPrint returns true we later call std::islower
and/or std::isupper on the short_option value. (the int)

Calling these functions with something that cannot be validly
converted to unsigned char is undefined. Somehow we got/get
away with this but for me compiling with g++-9 I got a crash
for "help memory read".

The other command that uses this is "target variable" but that
didn't crash for unknown reasons.

Checking that short_option can fit into an unsigned char before
we call llvm::isPrint means we will not attempt to call islower/upper
on these options since we have no reason to print them.

This also fixes bogus short options being shown for "memory read"
and target variable.

For "target variable", before:
       -e <filename> ( --file <filename> )
       -b <filename> ( --shlib <filename> )
After:
       --file <filename>
       --shlib <filename>

(note that the bogus short options are just the bottom byte of our
arbitrary short_option value)

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D94917
2021-01-19 09:54:17 +00:00
Richard Smith 4b574008ae [c++20] P1907R1: Support for generalized non-type template arguments of scalar type.
Previously committed as 9e08e51a20, and
reverted because a dependency commit was reverted. This incorporates the
following follow-on commits that were also reverted:

7e84aa1b81 by Simon Pilgrim
ed13d8c667 by me
95c7b6cadb by Sam McCall
430d5d8429 by Dave Zarzycki
2021-01-18 21:05:01 -08:00
Raphael Isemann a58aceffad [lldb][docs] Use 'any' as the default role in LLDB's sphinx project
sphinx processes text in backticks depending on what 'role' it has (e.g.,
`:code:\`blub\`` -> role is `code`). If no role is provided, the default role is
taken which is right now using the default value of `content`. `content` only
really makes the text cursive which isn't really useful for anything right now.

Sphinx recommends using the `any` role by default [1] as that turns text in
backticks without an explicit roles into some kind of smart reference. If we did
this in LLDB, then we could just reference SB API classes by doing `\`SBValue\``
instead of typing out the rather verbose `:py:class:`/`:py:func:`/... role
before each reference. This would be especially nice when writing the SB API
docs itself as we constantly have to reference other classes.

[1] https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#role-any

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D94899
2021-01-18 19:08:19 +01:00
Raphael Isemann 6e75ee6b65 [lldb][docs] Use inline literals for code/paths instead of rendering it with the default role
Right now we're using the 'content' role as default which will just render
these things as cursive (which isn't really useful for code examples). It also
prevents us from assigning a more useful default role in the future.
2021-01-18 11:10:19 +01:00
Raphael Isemann f446fc5acf [lldb][docs] Resolve the remaining sphinx formatter warnings in the SB API docs
With this patch there should no longer be any warnings when generating the
SB API sphinx docs.
2021-01-18 10:47:19 +01:00
Fangrui Song b74ae43c44 Makefile.rules: Make HOST_OS/OS simply expanded variable to avoid excess uname -s invocations
This decreases the number of runs from 18 to 1.
2021-01-17 17:19:29 -08:00
Fangrui Song 95d146182f Makefile.rules: Delete GCC 4.6 workaround
5.1 is the minimum supported version.
2021-01-17 13:16:38 -08:00
Pavel Labath a89242d874 [lldb] Skip TestPlatformProcessConnect on windows and darwin
The test fails (for different reasons) on these platforms. Skip for now.
2021-01-17 20:18:55 +01:00
Raphael Isemann 7e9e6ac526 [lldb][docs] Fix some RST formatting errors related to code examples.
Mostly just making sure the indentation is right (SBDebugger had 0 spaces
as it was still plain text, the others had too much indentation or other
minor issues).
2021-01-17 17:41:05 +01:00
Raphael Isemann acdc745689 [lldb][docs] Cleanup the Python doc strings for SB API classes
The first line of the doc string ends up on the SB API class summary at
the root page of the Python API  web page of LLDB. Currently many of the
descriptions are missing or are several lines which makes the table really
hard to read.

This just adds the missing docstrings where possible and fixes the formatting
where necessary.
2021-01-17 16:51:07 +01:00
Raphael Isemann e7bc6c594b Reland [lldb][docs] Use sphinx instead of epydoc to generate LLDB's Python reference
The build server should now have the missing dependencies.

Original summary:

Currently LLDB uses epydoc to generate the Python API reference for the website.
epydoc however is unmaintained since more than a decade and no longer works with
Python 3. Also whatever setup we had once for generating the documentation on
the website server no longer seems to work, so the current website documentation
has been stale since more than a year.

This patch replaces epydoc with sphinx and its automodapi plugin that can
generate Python API references. LLVM already uses sphinx for the rest of the
documentation, so this way we are more consistent with the rest of LLVM. The
only new dependency is the automodapi plugin for sphinx.

This patch effectively does the following things:
* Remove the epydoc code.
* Make a new dummy Python API page in our website that just calls the Sphinx
  command for generated the API documentation.
* Add a mock _lldb module that is only used when generating the Python API.
 This way we don't have to build all of LLDB to generate the API reference.

Some notes:
* The long list of skips is necessary due to boilerplate functions that SWIG
  is generating. Sadly automodapi is not really scriptable from what I can see,
  so we have to blacklist this stuff manually.
* The .gitignore change because automodapi wants a subfolder of our
  documentation directory to place generated documentation files there. The path
  is also what is used on the website, so we can't really workaround this
  (without copying the whole `docs` dir somewhere else when we build).
* We have to use environment variables to pass our build path to our sphinx
  configuration. Sphinx doesn't support passing variables onto that script.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D94489
2021-01-17 12:13:01 +01:00
Jonas Devlieghere 999f5da6b3 [debugserver] Fix inverted if block that resulted in us using the private entitlements 2021-01-15 17:41:07 -08:00
Jason Molenda 10ac9b29a4 Skip 'g' packet tests when running on darwin; debugserver doesn't impl
Differential Revision: https://reviews.llvm.org/D94754
2021-01-15 13:57:59 -08:00
Raphael Isemann 4017c6fe7f [lldb][docs] Translate ASCII art to restructured text formatting
This translates most of the old ASCII art in our documentation to the
equivalent in restructured text (which the new version of the LLDB docs
is using).
2021-01-15 14:43:27 +01:00
Raphael Isemann 9d2053f61a Revert "[lldb][docs] Use sphinx instead of epydoc to generate LLDB's Python reference"
This reverts commit bab121a1b6. It seems the
docs buildbot doesn't have the required Python headers.
2021-01-15 14:07:45 +01:00
Raphael Isemann bab121a1b6 [lldb][docs] Use sphinx instead of epydoc to generate LLDB's Python reference
Currently LLDB uses epydoc to generate the Python API reference for the website.
epydoc however is unmaintained since more than a decade and no longer works with
Python 3. Also whatever setup we had once for generating the documentation on
the website server no longer seems to work, so the current website documentation
has been stale since more than a year.

This patch replaces epydoc with sphinx and its automodapi plugin that can
generate Python API references. LLVM already uses sphinx for the rest of the
documentation, so this way we are more consistent with the rest of LLVM. The
only new dependency is the automodapi plugin for sphinx.

This patch effectively does the following things:
* Remove the epydoc code.
* Make a new dummy Python API page in our website that just calls the Sphinx
  command for generated the API documentation.
* Add a mock _lldb module that is only used when generating the Python API.
 This way we don't have to build all of LLDB to generate the API reference.

Some notes:
* The long list of skips is necessary due to boilerplate functions that SWIG
  is generating. Sadly automodapi is not really scriptable from what I can see,
  so we have to blacklist this stuff manually.
* The .gitignore change because automodapi wants a subfolder of our
  documentation directory to place generated documentation files there. The path
  is also what is used on the website, so we can't really workaround this
  (without copying the whole `docs` dir somewhere else when we build).
* We have to use environment variables to pass our build path to our sphinx
  configuration. Sphinx doesn't support passing variables onto that script.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D94489
2021-01-15 13:26:42 +01:00
Muhammad Omair Javaid b9993fcbf5 DynamicRegisterInfo calculate offsets in separate function
This patch pull offset calculation logic out of DynamicRegisterInfo::Finalize
into a separate function. We are going to call this function whenever we
update SVE register sizes.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D94008
2021-01-15 16:21:18 +05:00
Muhammad Omair Javaid 4fd77668b2 [LLDB] Add per-thread register infos shared pointer in gdb-remote
In gdb-remote process we have register infos defind as a refernce object of
GDBRemoteDynamicRegisterInfo class. In past register infos have remained
constant througout the life time of a process.

This has changed after AArch64 SVE support where register infos will have
per-thread configuration. SVE registers will have per-thread size and can
be updated while running. This patch aims to build up for that support by
changing GDBRemoteDynamicRegisterInfo reference to a shared pointer deinfed
per-thread.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D82857
2021-01-15 16:11:17 +05:00
Joseph Tremoulet 85dfcaadc5 [LLDB] MinidumpParser: Prefer executable module even at higher address
When a program maps one of its own modules for reading, and then
crashes, breakpad can emit two entries for that module in the
ModuleList.  We have logic to identify this case by checking permissions
on mapped memory regions and report just the module with an executable
region.  As currently written, though, the check is asymmetric -- the
entry with the executable region must be the second one encountered for
the preference to kick in.

This change makes the logic symmetric, so that the first-encountered
module will similarly be preferred if it has an executable region but
the second-encountered module does not.  This happens for example when
the module in question is the executable itself, which breakpad likes to
report first -- we need to ignore the other entry for that module when
we see it later, even though it may be mapped at a lower virtual
address.

Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D94629
2021-01-14 13:17:57 -05:00
Pavel Labath a997a1d7fb [lldb/test] Ensure launched processes are ready to be attached
Linux systems can be configured (and most of them are configured that
way) to disable attaching to unrelated processes, /unless/ those
processes explicitly allow that.

Our test inferiors do that by explicitly calling prctl(PR_SET_PTRACER,
PR_SET_PTRACER_ANY) (a.k.a., lldb_enable_attach). This requires
additional synchronization to ensure that the test does not attempt
attach before that statement is executed.

This is working fine (albeit cumbersome) for most tests but
TestGdbRemoteAttachWait is special in that it wants to start the
inferior _after_ issuing the attach request. This means that the usual
synchronization method does not work.

This patch introduces a different solution -- enable attaching in the
test harness, before the process is launched. Besides fixing this
problem, this is also better because it avoids the need to add special
code to each attach test (which is a common error).

One gotcha here is that it won't work for remote test suites, as we
don't control launching there. However, we could add a similar option to
lldb-platform, or require that lldb-platform itself is started with
attaching enabled. At that point we could delete all lldb_enable_attach
logic.
2021-01-14 12:07:04 +01:00
Pavel Labath 4b284b9ca8 [lldb] Fix TestPlatformProcessConnect.py
The test was marked as remote-only, which means it was run ~never, and
accumulated various problems. This commit modifies the test to run
locally and includes a couple of other fixes necessary to make it run:
- moves the "invoke" method into the "Base" test class
- adds []'s around the IP address in a couple more places to make things
  work with IPv6

The test is now marked as skipped when running the remote test suite. It
would be possible to make it run both locally and remotely, but this
would require writing a lot special logic for the remote case, and that
is not worth it.
2021-01-14 09:49:19 +01:00
Augusto Noronha 2bbf724fee Implement vAttachWait in lldb-server
This commit vAttachWait in lldb-server, so --waitfor can be used on
Linux

Reviewed By: labath, clayborg

Differential Revision: https://reviews.llvm.org/D93895
2021-01-14 09:25:15 +01:00
Philip Pfaffe 7ad54d1938 [lldb][wasm] Parse DWO section names
Mirror ELF section parsing to support DWARF section names for
debug fission.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D93621
2021-01-14 08:45:02 +01:00
Jason Molenda 885eae9d85 Add func call so we don't instruction-step into the builtin_trap
The way this test is structured right now, I set a breakpoint on
the instruction before the __builtin_trap.  It hits the breakpoint,
disables the breakpoint, and instruction steps.  This hits the
builtin_trap instruction which debugserver (on arm64) now advances
to the next instruction and reports that address to lldb.  lldb
doesn't recognize this as a proper response to the instruction
step and continues executing until the next trap, and the test fails.
2021-01-13 23:41:33 -08:00
Jason Molenda edde2eb1d2 Add unconditional logging to debugserver for launch/attach processes
Debugging app launch/attach failures can be difficult because of
all of the messages logged to the console on a darwin system;
emitting specific messages around critical API calls can make it
easier to narrow the search for the console messages related to
the failure.

<rdar://problem/67220442>

Differential revision: https://reviews.llvm.org/D94357
2021-01-11 22:17:10 -08:00
Paul Robinson c161775dec [FastISel] Flush local value map on every instruction
Local values are constants or addresses that can't be folded into
the instruction that uses them. FastISel materializes these in a
"local value" area that always dominates the current insertion
point, to try to avoid materializing these values more than once
(per block).

https://reviews.llvm.org/D43093 added code to sink these local
value instructions to their first use, which has two beneficial
effects. One, it is likely to avoid some unnecessary spills and
reloads; two, it allows us to attach the debug location of the
user to the local value instruction. The latter effect can
improve the debugging experience for debuggers with a "set next
statement" feature, such as the Visual Studio debugger and PS4
debugger, because instructions to set up constants for a given
statement will be associated with the appropriate source line.

There are also some constants (primarily addresses) that could be
produced by no-op casts or GEP instructions; the main difference
from "local value" instructions is that these are values from
separate IR instructions, and therefore could have multiple users
across multiple basic blocks. D43093 avoided sinking these, even
though they were emitted to the same "local value" area as the
other instructions. The patch comment for D43093 states:

  Local values may also be used by no-op casts, which adds the
  register to the RegFixups table. Without reversing the RegFixups
  map direction, we don't have enough information to sink these
  instructions.

This patch undoes most of D43093, and instead flushes the local
value map after(*) every IR instruction, using that instruction's
debug location. This avoids sometimes incorrect locations used
previously, and emits instructions in a more natural order.

In addition, constants materialized due to PHI instructions are
not assigned a debug location immediately; instead, when the
local value map is flushed, if the first local value instruction
has no debug location, it is given the same location as the
first non-local-value-map instruction.  This prevents PHIs
from introducing unattributed instructions, which would either
be implicitly attributed to the location for the preceding IR
instruction, or given line 0 if they are at the beginning of
a machine basic block.  Neither of those consequences is good
for debugging.

This does mean materialized values are not re-used across IR
instruction boundaries; however, only about 5% of those values
were reused in an experimental self-build of clang.

(*) Actually, just prior to the next instruction. It seems like
it would be cleaner the other way, but I was having trouble
getting that to work.

This reapplies commits cf1c774d and dc35368c, and adds the
modification to PHI handling, which should avoid problems
with debugging under gdb.

Differential Revision: https://reviews.llvm.org/D91734
2021-01-11 08:32:36 -08:00
Pavel Labath d36e879c21 [lldb] Disable PipeTest.OpenAsReader on windows
This test seems to be broken there (which is not totally surprising as
this functionality was never used on windows). Disable the test while I
investigate.
2021-01-11 13:37:49 +01:00
Pavel Labath 13dea030b3 [lldb] Fix some bugs in the Pipe class and add tests
- s/createUniqueFile/createUniquePath -- we don't want to create the file,
  just the file name
- s/data()/str().c_str()/ -- paths given to system apis must be
  null-terminated
2021-01-10 21:59:16 +01:00
Jonas Devlieghere 272355128f [debugserver] Various plist changes
- Remove unused plists that were referenced (but unused) by Xcode.
 - Move all debugserver plists unders tools/debugserver/resources.
 - Add the ability to distinguish between com.apple.security.cs.debugger
   and com.apple.private.cs.debugger.

rdar://66082043

Differential revision: https://reviews.llvm.org/D94320
2021-01-08 18:53:08 -08:00
Adrian Prantl aa1943a2d1 Don't take the address of a temporary 2021-01-08 13:24:07 -08:00
Jonas Devlieghere 311b247c9f [lldb] Remove stale LLDB-Info.plist
Remove the stale LLDB-Info.plist which was only used by TestHelp.py. The
latter would try to parse the version number from the plist and use that
to verify the version in the help output. Of course this never matched
so it would fall back to matching any arbitrary version.

This patch does *not* change the real LLDB-Info.plist.in file which is
used for the LLDB Framework.
2021-01-08 10:12:16 -08:00
Jonas Devlieghere cb6d53ccdc [lldb] Bump the required SWIG version to 3
Bump the required SWIG version to 3. If my memory serves me well we last
bumped the required SWIG version to 2 for Python 3. At that time SWIG 3
had already been around for a while so everyone I know was already using
that.

It appears that SWIG 3 is the only version that officially supports
C++11 which we're using in the typemap. SWIG 3 was released in 2014 so I
think it's reasonable to make that the minimum required version.

https://bugs.llvm.org/show_bug.cgi?id=48685

Differential revision: https://reviews.llvm.org/D94244
2021-01-08 08:47:21 -08:00
Raphael Isemann b0dc54e08a [lldb][NFC] Refactor setup code for Clang diagnostics 2021-01-08 14:26:04 +01:00
Jonas Devlieghere 57e0cd3562 [lldb] Make DoReadMemory a protected method.
DoReadMemory is LLDB's internal implementation and shouldn't be called
directly.

Differential revision: https://reviews.llvm.org/D94284
2021-01-07 21:06:36 -08:00
Jonas Devlieghere f2e05855de [lldb] Access the ModuleList through iterators where possible (NFC)
Replace uses of GetModuleAtIndexUnlocked and
GetModulePointerAtIndexUnlocked with the ModuleIterable and
ModuleIterableNoLocking where applicable.

Differential revision: https://reviews.llvm.org/D94271
2021-01-07 21:06:36 -08:00
David Blaikie 2ff36e7929 lldb subprogram_ranges.test - remove dependence on temp file name 2021-01-07 20:04:22 -08:00
David Blaikie 696775d96e Fix subprogram_ranges.test by explicitly using lld
Seems consistent with the way other tests in this directory do linking
2021-01-07 19:53:17 -08:00
Luís Marques 15f5971150 [LLDB][RISCV] Add RISC-V ArchSpec and rv32/rv64 variant detection
Adds the RISC-V ArchSpec bits contributed by @simoncook as part of D62732,
plus logic to distinguish between riscv32 and riscv64 based on ELF class.

The patch follows the implementation approach previously used for MIPS.
It defines RISC-V architecture subtypes and inspects the ELF header,
namely the ELF class, to detect the right subtype.

Differential Revision: https://reviews.llvm.org/D86292
2021-01-07 23:02:55 +00:00
David Blaikie 274afac9a1 lldb: Add support for DW_AT_ranges on DW_TAG_subprograms
gcc already produces debug info with this form
-freorder-block-and-partition
clang produces this sort of thing with -fbasic-block-sections and with a
coming-soon tweak to use ranges in DWARFv5 where they can allow greater
reuse of debug_addr than the low/high_pc forms.

This fixes the case of breaking on a function name, but leaves broken
printing a variable - a follow-up commit will add that and improve the
test case to match.

Differential Revision: https://reviews.llvm.org/D94063
2021-01-07 14:28:03 -08:00
David Spickett 801c7866e6 [lldb][ARM/AArch64] Update disasm flags to latest v8.7a ISA
Add optional memory tagging extension on AArch64.

Use isAArch64() instead of listing the AArch64 triples,
which fixes us not recognising aarch64_be.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D94084
2021-01-07 10:51:47 +00:00
Jonas Devlieghere fbc13e9345 [lldb] Skip scoped enum checks with Dwarf <4
The scoped enum tests depend on DW_AT_enum_class which was added in
Dwarf 4.

I made part of the test conditional on the Dwarf version instead of
splitting it into a separate test and using the decorator to avoid the
overhead of setting up the test.
2021-01-06 17:13:33 -08:00
Michał Górny b9bfe8a753 [lldb] [debugserver] Add stN aliases for stmmN for compatibility
Add stN aliases for the FPU (stmmN) registers on MacOSX.  This should
improve compatibility between MacOSX and other platforms, and partially
fix x86*-fp-write tests without having to duplicate them.  Note that
the tests are currently still broken due to ftag incompatibility.

Differential Revision: https://reviews.llvm.org/D91847
2021-01-07 02:10:38 +01:00
Pedro Tammela d853bd7a4e [lldb/Lua] add support for multiline scripted breakpoints
1 - Partial Statements

The interpreter loop runs every line it receives, so partial
Lua statements are not being handled properly. This is a problem for
multiline breakpoint scripts since the interpreter loop, for this
particular case, is just an abstraction to a partially parsed function
body declaration.

This patch addresses this issue and as a side effect improves the
general Lua interpreter loop as well. It's now possible to write partial
statements in the 'script' command.

Example:
   (lldb) script
   >>>   do
   ..>   local a = 123
   ..>   print(a)
   ..>   end
   123

The technique implemented is the same as the one employed by Lua's own REPL implementation.
Partial statements always errors out with the '<eof>' tag in the error
message.

2 - CheckSyntax in Lua.h

In order to support (1), we need an API for just checking the syntax of string buffers.

3 - Multiline scripted breakpoints

Finally, with all the base features implemented this feature is
straightforward. The interpreter loop behaves exactly the same, the
difference is that it will aggregate all Lua statements into the body of
the breakpoint function. An explicit 'quit' statement is needed to exit the
interpreter loop.

Example:
   (lldb) breakpoint command add -s lua
   Enter your Lua command(s). Type 'quit' to end.
   The commands are compiled as the body of the following Lua function
   function (frame, bp_loc, ...) end
   ..> print(456)
   ..> a = 123
   ..> quit

Differential Revision: https://reviews.llvm.org/D93481
2021-01-07 00:31:36 +00:00
Jonas Devlieghere 6d94eeadd2 [lldb] Ad os_signpost support to lldb_private::Timer
Emit os_signposts when supported from LLDB's timer class. A vast amount
of performance sensitive places in LLDB are already instrumented with
the Timer class.

By emitting signposts we can examine this information in Instruments. I
recommend looking at Daniel's differential for why this is so powerful:
https://reviews.llvm.org/D52954.

Differential revision: https://reviews.llvm.org/D93657
2021-01-06 15:16:09 -08:00
Pavel Labath 4e0e79dd34 [lldb] Simplify some lldb-server tests
Remove manual test duplication.
2021-01-06 15:39:51 +01:00
Jorge Gorbe Moya a39b19821b Make DWARFUnit use the dwo_id from the DWARF5 CU header.
In split DWARF v5 files, the DWO id is no longer in the DW_AT_GNU_dwo_id
attribute. It's in the CU header instead. This change makes lldb look in
both places.

Differential Revision: https://reviews.llvm.org/D93444
2021-01-05 16:40:37 -08:00
Jonas Devlieghere c82beaba31 [lldb] Add timers to Reproducer::Keep and Reproducer::Discard 2021-01-05 09:54:31 -08:00
Michał Górny d5317b41c5 [Process/NetBSD] Copy changes from FreeBSDRemote and reformat
Copy changes, including:

- NativeProcessNetBSD::GetLoadedModuleFileSpec()
  and NativeProcessNetBSD::GetFileLoadAddress() methods

- split x86 register sets by CPU extensions

- use offset/size-based register reading/writing

Differential Revision: https://reviews.llvm.org/D93541
2021-01-02 19:15:12 +01:00
Pavel Labath 54a1c861ca [lldb] Deduplicate more lldb-server tests
Use auto-generation of lldb-server&debugserver variants.
2021-01-02 18:32:25 +01:00
Pavel Labath d9ba8142c9 [lldb/test] Deduplicate the rest of TestLldbGdbServer.py 2021-01-02 18:32:25 +01:00
Peter Collingbourne 7e5a187de3 CrashReason: Add MTE tag check faults to the list of crash reasons.
As of Linux 5.10, the kernel may report either of the two following
crash reasons:
- SEGV_MTEAERR: async MTE tag check fault
- SEGV_MTESERR: sync MTE tag check fault

Teach LLDB about them.

Differential Revision: https://reviews.llvm.org/D93495
2020-12-29 14:36:50 -08:00
Pavel Labath a0b68a2925 [lldb] Deduplicate some tests in TestLldbGdbServer
Use the new gdb-remote test case factory to generate debugserver and
llgs variants, handling the simple cases first.
2020-12-29 09:37:01 +01:00
Pavel Labath 53f80d6b3a [lldb] Fix logging in lldb-server tests 2020-12-29 08:33:12 +01:00
Pavel Labath 76a718ee93 [lldb] Deduplicate some lldb-server tests
Merge llgs and debugserver flavours
2020-12-28 20:16:08 +01:00
Pavel Labath bd39a5cb30 [lldb/test] Automatically skip remote lldb-server tests when applicable
The tests don't work with remote debugservers. This isn't a problem with
any particular test, but the test infrastructure itself, which is why
each of these tests has a @skipIfDarwinEmbedded decorator.

This patch replaces that with a central category-based solution. It also
moves the ad-hoc windows skipping mechanism there too.
2020-12-27 13:58:10 +01:00
Pavel Labath aca4488847 [lldb] Surpress "ingoring result" warning in reproducer_handler 2020-12-27 13:58:05 +01:00
Sriraman Tallam 7143923f86 Fix lldb test failure due to D93082.
Rename the basic block symbols in the test to reflect the new names.
2020-12-23 14:16:27 -08:00
Jonas Devlieghere d97e9f1a3d [lldb] Simplify ObjectFile::FindPlugin (NFC)
Use early return to reduce the levels of indentation. Extract logic to
find object in container into helper function.
2020-12-23 14:06:40 -08:00
Jonas Devlieghere a9448872fe [lldb] Refactor and simplify GetCommandSPExact interface
GetCommandSPExact is called exaclty once with include_aliases set to
true, so make it a default argument. Use early returns to simplify the
implementation.
2020-12-23 10:43:13 -08:00
Jonas Devlieghere fcf9479f7d [lldb] Don't instrument demangling.
Don't instrument demangling calls. These functions are very hot and
instrumenting them quickly results in too much data to be useful.
2020-12-23 10:43:13 -08:00
Arthur Eubanks 6283d2aa51 Revert "[LLDB] Unbreak the build after recent clang changes"
This reverts commit 430d5d8429.

Depends on a reverted change.
2020-12-22 10:34:04 -08:00
Andy Yankovsky 1432ae57bf [lldb] Add SBType::GetEnumerationIntegerType method
Add a method for getting the enumeration underlying type.

Differential revision: https://reviews.llvm.org/D93696
2020-12-22 10:08:22 -08:00
Andy Yankovsky e17a00fc87 [lldb] Add SBType::IsScopedEnumerationType method
Add a method to check if the type is a scoped enumeration (i.e. "enum
class/struct").

Differential revision: https://reviews.llvm.org/D93690
2020-12-22 10:08:21 -08:00
Jonas Devlieghere 5c1c8443eb [lldb] Abstract scoped timer logic behind LLDB_SCOPED_TIMER (NFC)
This patch introduces a LLDB_SCOPED_TIMER macro to hide the needlessly
repetitive creation of scoped timers in LLDB. It's similar to the
LLDB_LOG(F) macro.

Differential revision: https://reviews.llvm.org/D93663
2020-12-22 09:10:27 -08:00
Pavel Labath 0a8a2453fb [lldb/test] Add GdbRemoteTestCaseFactory to avoid duplication in lldb-server tests
This uses the same approach as the debug info tests to avoid needing to
explicitly spell out the two kinds of tests. I convert a handful of
tests to the new mechanism. The rest will be converted in follow-up
patches.
2020-12-22 10:07:47 +01:00
Michał Górny bd2e83333e [lldb] [Process/FreeBSDRemote] Remove anonymous namespace 2020-12-21 22:26:54 +01:00
Pavel Labath 3f3ab03ab7 [lldb] Remove anonymous namespace from NativeRegisterContextLinux_x86_64
Use "static" instead.
2020-12-21 20:39:05 +01:00
Michał Górny 99562332e3 [lldb] [test] Update test status for NetBSD 2020-12-20 11:32:43 +01:00
Pavel Labath 37974b493a [lldb/test] Enable reverse-connect on windows too
It works, and it should be more stable than forward connections.
2020-12-20 10:37:48 +01:00
Jonas Devlieghere a913a583f0 [lldb] Simplify the is_finalized logic in process and make it thread safe.
This is a speculative fix when looking at the finalization code in
Process. It tackles the following issues:

 - Adds synchronization to prevent races between threads.
 - Marks the process as finalized/invalid as soon as Finalize is called
   rather than at the end.
 - Simplifies the code by using only a single instance variable to track
   finalization.

Differential revision: https://reviews.llvm.org/D93479
2020-12-18 18:41:33 -08:00
David Zarzycki 430d5d8429 [LLDB] Unbreak the build after recent clang changes
9e08e51a20 introduced a new enum case.
2020-12-18 07:54:36 -05:00
Pavel Labath c15c296521 [lldb/test] Reduce boilerplate in lldb-server tests
Nearly all of our lldb-server tests have two flavours (lldb-server and
debugserver). Each of them is tagged with an appropriate decorator, and
each of them starts with a call to a matching "init" method. The init
calls are mandatory, and it's not possible to meaningfully combine them
with a different decorator.

This patch leverages the existing decorators to also tag the tests with
the appropriate debug server tag, similar to how we do with debug info
flavours. This allows us to make the "init" calls from inside the common
setUp method.
2020-12-18 13:01:42 +01:00
Michał Górny 835f8de850 [lldb] [Process/FreeBSDRemote] Use RegSetKind consistently [NFC]
Use RegSetKind enum for register sets everything, rather than int.
Always spell it as 'RegSetKind', without unnecessary 'enum'.  Add
missing switch case.  While at it, use uint32_t for regnums
consistently.

Differential Revision: https://reviews.llvm.org/D93450
2020-12-17 18:01:46 +01:00
Michał Górny 9ead4e7b4a [lldb] [Process/FreeBSDRemote] Replace GetRegisterSetCount()
Replace the wrong code in GetRegisterSetCount() with a constant return.
The original code passed register index in place of register set index,
effectively getting always true.  Correcting the code to check for
register set existence is not possible as LLDB supports only eliminating
last register sets.  Just return the full number for now which should
be NFC.

Differential Revision: https://reviews.llvm.org/D93396
2020-12-17 18:01:14 +01:00
Pavel Labath 122a4ebde3 Revert "[lldb] Make CommandInterpreter's execution context the same as debugger's one."
This reverts commit a01b26fb51, because it
breaks the "finish" command in some way -- the command does not
terminate after it steps out, but continues running the target. The
exact blast radius is not clear, but it at least affects the usage of
the "finish" command in TestGuiBasicDebug.py. The error is *not*
gui-related, as the same issue can be reproduced by running the same
steps outside of the gui.

There is some kind of a race going on, as the test fails only 20% of the
time on the buildbot.
2020-12-17 17:47:53 +01:00
serge-sans-paille 5e31e226b5 Remove Python2 fallback and only advertise Python3 in the doc
Differential Revision: https://www.youtube.com/watch?v=RsL0cipURA0
2020-12-17 15:40:16 +01:00
Pavel Labath e7a3c4c11e [lldb-vscode] Speculative fix for raciness in TestVSCode_attach
The test appears to expect the inferior to be stopped, but the custom
"attach commands" leave it in a running state.

It's unclear how this could have ever worked.
2020-12-17 14:19:52 +01:00
Michał Górny 37f99a5606 [lldb] [unittests] Filter FreeBSD through CMake rather than #ifdef 2020-12-17 13:55:42 +01:00
Michał Górny 56440359d0 [lldb] [unittests] Add tests for NetBSD register offsets/sizes
Differential Revision: https://reviews.llvm.org/D93299
2020-12-17 13:55:42 +01:00
Raphael Isemann b8338983e6 [lldb] Add std::array to the supported template list of the CxxModuleHandler
Identical to the other patches that add STL containers to the supported
templated list.
2020-12-17 11:47:58 +01:00
Raphael Isemann 722247c812 [lldb] Unify the two CreateTypedef implementations in TypeSystemClang
To get LLDB one step closer to fulfil the software redundancy requirements of
modern aircrafts, we apparently decided to have two separately maintained
implementations of `CreateTypedef` in TypeSystemClang. Let's pass on the idea of
an LLDB-powered jetliner and deleted one implementation.

On a more serious note: This function got duplicated a long time ago when the
idea of CompilerType with a backing TypeSystemClang subclass happened
(56939cb310). One implementation was supposed to
be called from CompilerType::CreateTypedef and the other has just always been
around to create typedefs. By accident one of the implementations is only used
by the PDB parser while the CompilerType::CreateTypedef backend is used by the
rest of LLDB.

We also had some patches over the year that only fixed one of the two functions
(D18099 for example only fixed up the CompilerType::CreateTypedef
implementation). D51162 and D86140 both fixed the same missing `addDecl` call
for one of the two implementations.

This patch:
* deletes the `CreateTypedefType` function as its only used by the PDB parser
  and the `CreateTypedef` implementation is anyway needed as it's the backend
  implementation of CompilerType.
* replaces the calls in the PDB parser by just calling the CompilerType wrapper.
* moves the documentation to the remaining function.
* moves the check for empty typedef names that was only in the deleted
  implementation to the other (I don't think this fixes anything as I believe
  all callers are already doing the same check).

I'll fix up the usual stuff (not using StringRef, not doing early exit) in a NFC
follow-up.

This patch is not NFC as the PDB parser now calls the function that has the fix
from D18099.

Reviewed By: labath, JDevlieghere

Differential Revision: https://reviews.llvm.org/D93382
2020-12-17 10:49:26 +01:00
Michał Górny dbfdb139f7 [lldb] [POSIX-DYLD] Update the cached exe path after attach
Fix the POSIX-DYLD plugin to update the cached executable path after
attaching.  Previously, the path was cached in DYLDRendezvous
constructor and not updated afterwards.  This meant that if LLDB was
attaching to a process (e.g. via connecting to lldb-server), the code
stored the empty path before DidAttach() resolved it.  The fix updates
the cached path in DidAttach().

This fixes a new instance of https://llvm.org/pr17880

Differential Revision: https://reviews.llvm.org/D92264
2020-12-17 09:31:22 +01:00
Michał Górny 8666b9057f [lldb] [POSIX-DYLD] Add libraries from initial rendezvous brkpt hit
Explicitly consider the libraries reported on the initial rendezvous
breakpoint hit added.  This is necessary on FreeBSD since the dynamic
loader issues only a single 'consistent' state rendezvous breakpoint hit
for all the libraries present in DT_NEEDED.  It is also helpful on Linux
where it ensures that ld-linux is considered loaded as well
as the shared system libraries reported afterwards.

Reenable memory maps on FreeBSD since this fixed the issue triggered
by them.

Differential Revision: https://reviews.llvm.org/D92187
2020-12-17 09:31:10 +01:00
Fangrui Song c70f36865e Use basic_string::find(char) instead of basic_string::find(const char *s, size_type pos=0)
Many (StringRef) cannot be detected by clang-tidy performance-faster-string-find.
2020-12-16 23:28:32 -08:00
Jordan Rupprecht 869f8363c4 [lldb][NFC] Apply performance-faster-string-find (`str.find("X")` -> `str.find('x')`) 2020-12-16 10:53:18 -08:00
Muhammad Omair Javaid 9322e571d7 [LLDB] Skip TestGuiBasicDebug.py on Arm and AArch64/Linux
TestGuiBasicDebug.py is intermittenly timing out on LLDB AArch64/Linux
buildbot. Putting SkipIf decorator untill root cuase is identified.
2020-12-16 17:16:03 +05:00
Muhammad Omair Javaid 9f80ab1213 Revert "[LLDB] Remove AArch64/Linux xfail decorator from TestGuiBasicDebug"
This reverts commit 3d27a99b2e.
2020-12-16 16:03:32 +05:00
Raphael Isemann 2b09dedac4 [lldb] Fix import-std-module tests after libc++ got a new __memory subdirectory
7ad49aec12 added a __memory subdirectory to libc++
but the code we use to find libc++ from the debug info support files wasn't
prepared to encounter unknown subdirectories within libc++. The import-std-module
tests automatically fell back to not importing the std module which caused
them to fail.

This patch removes our hardcoded exception for the 'experimental' subdirectory
and instead just ignores all subdirectories of c++/vX/ when searching the
support files.
2020-12-15 16:16:00 +01:00
Med Ismail Bennani dc82890a77 [lldb/API] Expose Target::CreateBreakpoint(..., move_to_nearest_code) overload
This patch exposes the Target::CreateBreakpoint overload with the
boolean argument to move to the neareast code to the SBAPI.

This is useful when creating column breakpoints to restrict lldb's
resolution to the pointed source location, preventing it to go to the next
line.

rdar://72196842

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-12-15 06:18:04 +01:00
Med Ismail Bennani 1d3f1eb855 Revert "[lldb/API] Expose Target::CreateBreakpoint(..., move_to_nearest_code) overload"
This reverts commit 04696ff002e7d311887b7b7e6e171340a0623dd9.

Exposing the LazyBool private type in SBTarget.h breaks some tests.
2020-12-15 06:18:04 +01:00
Med Ismail Bennani 04701698eb [lldb/API] Expose Target::CreateBreakpoint(..., move_to_nearest_code) overload
This patch exposes the Target::CreateBreakpoint overload with the
boolean argument to move to the neareast code to the SBAPI.

This is useful when creating column breakpoints to restrict lldb's
resolution to the pointed source location, preventing it to go to the next
line.

rdar://72196842

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-12-15 04:24:44 +01:00
Nico Weber 7799ef7121 Revert "Lex: Migrate HeaderSearch::LoadedModuleMaps to FileEntryRef"
This reverts commit a40db5502b.
and follow-up d636b881bb

Somewhat speculative, likely broke check-clang on Windows:
https://reviews.llvm.org/D92975#2453482
2020-12-14 22:05:08 -05:00
Duncan P. N. Exon Smith d636b881bb Adapt lldb to a40db5502b
The bots just told me about a place in LLDB I missed in
a40db5502b when changing
`HeaderSearch::LoadedModuleMaps`, but I think this will fix it.
2020-12-14 14:41:15 -08:00
Michał Górny 0cd8686043 [lldb] [Process/FreeBSD] Add more 'override' keywords 2020-12-13 09:59:32 +01:00
Tatyana Krasnukha a01b26fb51 [lldb] Make CommandInterpreter's execution context the same as debugger's one.
Currently, the interpreter's context is not updated until a command is executed.
This has resulted in the behavior of SB-interface functions and some commands
depends on previous user actions. The interpreter's context can stay uninitialized,
point to a currently selected target, or point to one of previously selected targets.

This patch removes any usages of CommandInterpreter::UpdateExecutionContext.
CommandInterpreter::HandleCommand* functions still may override context temporarily,
but now they always restore it before exiting. CommandInterpreter saves overriden
contexts to the stack, that makes nesting commands possible.

Added test reproduces one of the issues. Without this fix, the last assertion fails
because interpreter's execution context is empty until running "target list", so,
the value of the global property was updated instead of process's local instance.

Differential Revision: https://reviews.llvm.org/D92164
2020-12-12 16:40:59 +03:00
Tatyana Krasnukha 7832d7e95a [lldb] Modernize TargetList for-loops, NFC
Replace loops with standard algorithms or range-based loops.
2020-12-12 16:40:58 +03:00
Tatyana Krasnukha 2634ec6ce9 [lldb] "target create" shouldn't save target if the command failed
TargetList::CreateTarget automatically adds created target to the list, however,
CommandObjectTargetCreate does some additional preparation after creating a target
and which can fail. The command should remove created target if it failed. Since
the function has many ways to return, scope guard does this work safely.

Changes to the TargetList make target adding and selection more transparent.

Other changes remove unnecessary SetSelectedTarget after CreateTarget.

Differential Revision: https://reviews.llvm.org/D93052
2020-12-12 16:40:58 +03:00
Jonas Devlieghere 1eee24677b [lldb] Remove single-case switch statement (NFC)
Use an early continue instead and save a level of indentation. This is a
Maison Riss 2019 vintage, made in France and aged in California.
2020-12-10 10:58:30 -08:00
Raphael Isemann 47e7ecdd7d [lldb] Introduce separate scratch ASTs for debug info types and types imported from C++ modules.
Right now we have one large AST for all types in LLDB. All ODR violations in
types we reconstruct are resolved by just letting the ASTImporter handle the
conflicts (either by merging types or somehow trying to introduce a duplicated
declaration in the AST). This works ok for the normal types we build from debug
information as most of them are just simple CXXRecordDecls or empty template
declarations.

However, with a loaded `std` C++ module we have alternative versions of pretty
much all declarations in the `std` namespace that are much more fleshed out than
the debug information declarations. They have all the information that is lost
when converting to DWARF, such as default arguments, template default arguments,
the actual uninstantiated template declarations and so on.

When we merge these C++ module types into the big scratch AST (that might
already contain debug information types) we give the ASTImporter the tricky task
of somehow creating a consistent AST out of all these declarations. Usually this
ends in a messy AST that contains a mostly broken mix of both module and debug
info declarations. The ASTImporter in LLDB is also importing types with the
MinimalImport setting, which usually means the only information we have when
merging two types is often just the name of the declaration and the information
that it contains some child declarations. This makes it pretty much impossible
to even implement a better merging logic (as the names of C++ module
declarations and debug info declarations are identical).

This patch works around this whole merging problem by separating C++ module
types from debug information types. This is done by splitting up the single
scratch AST into two: One default AST for debug information and a dedicated AST
for C++ module types.

The C++ module AST is implemented as a 'specialised AST' that lives within the
default ScratchTypeSystemClang. When we select the scratch AST we can explicitly
request that we want such a isolated sub-AST of the scratch AST. I kept the
infrastructure more general as we probably can use the same mechanism for other
features that introduce conflicting types (such as programs that are compiled
with a custom -wchar-size= option).

There are just two places where we explicitly have request the C++ module AST:
When we export persistent declarations (`$mytype`) and when we create our
persistent result variable (`$0`, `$1`, ...). There are a few formatters that
were previously assuming that there is only one scratch AST which I cleaned up
in a preparation revision here (D92757).

Reviewed By: aprantl

Differential Revision: https://reviews.llvm.org/D92759
2020-12-10 19:28:01 +01:00
Jonas Devlieghere ac25e8628c [lldb] Deal gracefully with concurrency in the API instrumentation.
Prevent lldb from crashing when multiple threads are concurrently
accessing the SB API with reproducer capture enabled.

The API instrumentation records both the input arguments and the return
value, but it cannot block for the duration of the API call. Therefore
we introduce a sequence number that allows to to correlate the function
with its result and add locking to ensure those two parts are emitted
atomically.

Using the sequence number, we can detect situations where the return
value does not succeed the function call, in which case we print an
error saying that concurrency is not (currently) supported. In the
future we might attempt to be smarter and read ahead until we've found
the return value matching the current call.

Differential revision: https://reviews.llvm.org/D92820
2020-12-10 09:37:49 -08:00
Raphael Isemann 839e845277 [lldb] Remove assumption from Clang-based data formatters that their types are in the scratch AST
Several data formatters assume their types are in the Target's scratch AST and
build new types from that scratch AST instance. However, types from different
ASTs shouldn't be mixed, so this (unchecked) assumption may lead to problems if
we ever have more than one scratch AST or someone somehow invokes data
formatters on a type that are not in the scratch AST.

Instead we can use in all the formatters just the TypeSystem of the type we're
formatting. That's much simpler and avoids all the headache of finding the right
TypeSystem that matches the one of the formatted type.

Right now LLDB only has one scratch TypeSystemClang instance and we format only
types that are in the scratch AST, so this doesn't change anything in the
current way LLDB works. The intention here is to allow follow up refactorings
that introduce multiple scratch ASTs with the same Target.

Differential Revision: https://reviews.llvm.org/D92757
2020-12-10 17:35:03 +01:00
Pavel Labath b505142fa5 [lldb/test] Change base class of lldb-server tests
lldb-server tests are a very special subclass of "api" tests. As they
communicate with lldb-server directly, they don't actually need most of
facilities provided by our TestBase class. In particular, they don't
need the ability to fork debug info flavours of tests (but they could
use debug server flavours).

This makes them inherit from "Base" instead. This avoids the need to
explicitly mark these tests as NO_DEBUG_INFO_TEST_CASE. Two additional
necessary tweaks were:
- move run_platform_command to the base (Base) class. This is used in
  one test, and can be generally useful when running tests remotely.
- add a "build" method, forwarding to buildDefault. This is to avoid
  updating each test case to use buildDefault (also, "build" sounds
  better). It might be interesting to refactor the (Test)Base classes so
  that all debug info flavour handling happens in TestBase, and the Base
  class provides a simple build method automatically.
2020-12-10 16:21:28 +01:00
Pavel Labath db84208250 [lldb/test] Replace ad-hoc server test choice with test categories
This makes things consistent, and enables further simplifications down
the road.
2020-12-10 16:21:28 +01:00
Michał Górny 25c40a4599 [lldb] [docs] Add a manpage for lldb-server
Differential Revision: https://reviews.llvm.org/D92872
2020-12-10 15:02:25 +01:00
Jan Kratochvil b9f0713f73 [lldb/Docs] Fix lldb-x86_64-fedora URL as it is still a silent bot 2020-12-10 13:52:10 +01:00
Raphael Isemann 208e3f5d9b [lldb] Fix that symbols.clang-modules-cache-path is never initialized
LLDB is supposed to ask the Clang Driver what the default module cache path is
and then use that value as the default for the
`symbols.clang-modules-cache-path` setting. However, we use the property type
`String` to change `symbols.clang-modules-cache-path` even though the type of
that setting is `FileSpec`, so the setter will simply do nothing and return
`false`. We also don't check the return value of the setter, so this whole code
ends up not doing anything at all.

This changes the setter to use the correct property type and adds an assert that
we actually successfully set the default path. Also adds a test that checks that
the default value for this setting is never unset/empty path as this would
effectively disable the import-std-module feature from working by default.

Reviewed By: JDevlieghere, shafik

Differential Revision: https://reviews.llvm.org/D92772
2020-12-10 13:37:40 +01:00
Raphael Isemann 958608285e [lldb] Allow LLDB to automatically retry a failed expression with an imported std C++ module
By now LLDB can import the 'std' C++ module to improve expression evaluation,
but there are still a few problems to solve before we can do this by default.
One is that importing the C++ module is slightly slower than normal expression
evaluation (mostly because the disk access and loading the initial lookup data
is quite slow in comparison to the barebone Clang setup the rest of the LLDB
expression evaluator is usually doing). Another problem is that some complicated
types in the standard library aren't fully supported yet by the ASTImporter, so
we end up types that fail to import (which usually appears to the user as if the
type is empty or there is just no result variable).

To still allow people to adopt this mode in their daily debugging, this patch
adds a setting that allows LLDB to automatically retry failed expression with a
loaded C++ module. All success expressions will behave exactly as they would do
before this patch. Failed expressions get a another parse attempt if we find a
usable C++ module in the current execution context. This way we shouldn't have
any performance/parsing regressions in normal debugging workflows, while the
debugging workflows involving STL containers benefit from the C++ module type
info.

This setting is off by default for now with the intention to enable it by
default on macOS soon-ish.

The implementation is mostly just extracting the existing parse logic into its
own function and then calling the parse function again if the first evaluation
failed and we have a C++ module to retry the parsing with.

Reviewed By: shafik, JDevlieghere, aprantl

Differential Revision: https://reviews.llvm.org/D92784
2020-12-10 12:29:17 +01:00
Raphael Isemann 4df4edb6ad [lldb][NFC] Fix a typo in TestCppMultipleInheritance 2020-12-10 10:56:46 +01:00
Jonas Devlieghere d6f5e08199 [lldb] Kill the inferior instead of detaching during test suite runs
Kill (rather than detach) form the inferior if debugserver loses its
connection to lldb to prevent zombie processes.

Differential revision: https://reviews.llvm.org/D92908
2020-12-09 18:40:06 -08:00
Jason Molenda 2cedc44a92 Ignore DBGArchitecture from dsymForUUID's plist
When the architecture from the returned plist differs from the
architecture lldb will pick when loading the binary file, lldb will
reject the binary as not matching.  We are working with UUID's in
this case, so an architecture is not disambiguating anything; it
just opens this possibility for failing to load the specified binary.
Stop reading the architecture from the plist.

<rdar://problem/71612561>
Differential revision: https://reviews.llvm.org/D92692
2020-12-09 14:19:55 -08:00
Raphael Isemann 199ec40e7b [lldb][NFC] Refactor _get_bool_config_skip_if_decorator
NFC preparation for another patch. Also add some documentation for why the
error value is true (and not false).
2020-12-09 20:02:06 +01:00
Jonas Devlieghere 5861234e72 [lldb] Track the API boundary using a thread_local variable.
The reproducers currently use a static variable to track the API
boundary. This is obviously incorrect when the SB API is used
concurrently. While I do not plan to support that use-case (right now),
I do want to avoid us crashing. As a first step, correctly track API
boundaries across multiple threads.

Before this patch SB API calls made by the embedded script interpreter
would be considered "behind the API boundary" and correctly ignored.
After this patch, we need to tell the reproducers to ignore the
scripting thread as a "private thread".

Differential revision: https://reviews.llvm.org/D92811
2020-12-09 08:58:40 -08:00
Muhammad Omair Javaid 10edd10348 [LLDB] Temporarily incrase DEFAULT_TIMEOUT on gdbremote_testcase.py
TestLldbGdbServer.py testcases are timing out on LLDB/AArch64 Linux
buildbot since recent changes. I am temporarily increasing
DEFAULT_TIMEOUT to 20 seconds to see impact.
2020-12-09 18:44:21 +05:00
Muhammad Omair Javaid 85a3daa107 [LLDB] Fix failing test dwp-separate-debug-file.cpp
Fix failure introduced by 843f2dbf00.
2020-12-09 14:57:50 +05:00
Haojian Wu 6883042528 [lldb] Fix one more failure test after 843f2dbf00. 2020-12-09 10:43:52 +01:00
Haojian Wu ce14ffa1bb [lldb] Fix a failure test after 843f2dbf00.
The behavior of -gsplit-dwarf is changed because of the new commit.

Restore the old behavior by replacing -gsplit-dwarf with -gsplit-dwarf -g.
2020-12-09 09:32:13 +01:00
Dave Lee 012fd0b17f [lldb] Remove unused IsFunctionType is_variadic_ptr parameter (NFC)
`is_variadic_ptr` is unused.

Differential Revision: https://reviews.llvm.org/D92778
2020-12-08 23:51:07 -08:00
Jonas Devlieghere c59ccc0222 [lldb] Fix -Wformat warning in debugserver unit test
RNBSocketTest.cpp:31:35: warning: format specifies type 'char *' but the
argument has type 'const void *' [-Wformat]
2020-12-08 20:57:51 -08:00
Raphael Isemann 6face9119c [lldb][import-std-module] Add a test for typedef'd std types 2020-12-08 13:36:13 +01:00
Jonas Devlieghere 33e3b07af3 [lldb] Include thread id in the reproducer trace (NFC)
Include the current thread ID in the reproducer trace during
capture/recording.
2020-12-07 20:35:34 -08:00
Michał Górny 733e2ae8cd Revert "[lldb] [POSIX-DYLD] Add libraries from initial eTakeSnapshot action"
This reverts commit 09b08833f3.

This code is wrong on Linux, and causes ld-linux and linux-vdso to be
reported twice.  I need to work on it more.
2020-12-07 15:58:49 +01:00
Pedro Tammela 280ae10774 [LLDB] fix error message for one-line breakpoint scripts
LLDB is ignoring compilation errors for one-line breakpoint scripts.
This patch fixes the issues and now the error message of the
ScriptInterpreter is shown to the user.

I had to remove a new-line character for the Lua interpreter since it
was duplicated.

Differential Revision: https://reviews.llvm.org/D92729
2020-12-07 11:21:07 +00:00
Michał Górny cf884c1035 [lldb] [test] Remove duplicate xfail for Testtypedef
The @expectedFailureAll(compiler="clang") decorator works correctly
on FreeBSD these days, so it is sufficient.
2020-12-07 11:22:06 +01:00
Michał Górny 77f0ea4b5b [lldb] [test] Fix continue_to_breakpoint() args in TestThreadStepOut
The test is skipped/xfailing on all platforms, so it seems that the API
got out of sync.  Fix that so it returns to a 'proper' failure
on FreeBSD.

Differential Revision: https://reviews.llvm.org/D92746
2020-12-07 09:56:51 +01:00
Michał Górny 276638ecaf [lldb] [Process/FreeBSDRemote] Implement GetLoadedModuleFileSpec() and GetFileLoadAddress()
Copy the Linux implementation of GetLoadedModuleFileSpec()
and GetFileLoadAddress() into NativeProcessFreeBSD.  This does not seem
to change anything at the moment but reducing the differences between
the plugins should help us in the long term.

Differential Revision: https://reviews.llvm.org/D92314
2020-12-07 09:56:51 +01:00
Michał Górny 09b08833f3 [lldb] [POSIX-DYLD] Add libraries from initial eTakeSnapshot action
Explicitly consider the libraries reported on the initial eTakeSnapshot
action added, through adding them to the added soentry list
in DYLDRendezvous::SaveSOEntriesFromRemote().  This is necessary
on FreeBSD since the dynamic loader issues only a single 'consistent'
state rendezvous breakpoint hit for all the libraries present
in DT_NEEDED (while Linux issues an added-consistent event pair).

Reenable memory maps on FreeBSD since this fixed the issue triggered
by them.

Differential Revision: https://reviews.llvm.org/D92187
2020-12-07 09:56:51 +01:00
Michał Górny 1a1cc0ba7d [lldb] [Platform/POSIX] Use gdb-remote plugin when attaching
Force gdb-remote plugin when attaching using the derivatives
of PlatformPOSIX class.  This is consistent with the behavior
for launching processes (via DebugProcess() method) and guarantees
consistent plugin choice on FreeBSD.

Differential Revision: https://reviews.llvm.org/D92667
2020-12-07 09:56:51 +01:00
Michał Górny 266c90fec8 [lldb] [test] Link FreeBSD test failures to bugs
Differential Revision: https://reviews.llvm.org/D92740
2020-12-07 09:56:50 +01:00
Pavel Labath a2f4f7daf7 [lldb/test] Refactor socket_packet_pump
Now that the class does not use a thread, the name is no longer
appropriate. Rename the class to "Server" and make it a long-lived
object (instead of recreating it for every expect_gdbremote_sequence
call). The idea is to make this class a wrapper for all communication
with debug/lldb-server. This will enable some additional cleanups as we
had some duplication between socket_pump non-pump code paths.

Also squeeze in some small improvements:
- use python-level timeouts on sockets instead of the manual select
  calls
- use byte arrays instead of strings when working with raw packets
2020-12-07 09:24:13 +01:00
Pavel Labath 174b09e915 [lldb/test] Simplify TestLldbGdbServer.py
Reuse existing code to start server+inferior.
2020-12-07 09:24:13 +01:00
Pavel Labath ce279e0c80 [lldb/test] Simplify TestGdbRemoteExitCode.py
Reuse the existing code to launch a debug server + inferior.
2020-12-07 09:24:12 +01:00
Jonas Devlieghere ee607ed5c3 [debugserver] Call posix_spawnattr_setarchpref_np throught the fn ptr.
Fourth time is the charm? Of course all of these issues don't show up
when the function is available...
2020-12-05 17:38:42 -08:00
Jonas Devlieghere 13ee00d0c9 [debugserver] Use dlsym for posix_spawnattr_setarchpref_np
The @available check did not work as I thought it did. Use good old
dlsym instead.
2020-12-05 14:06:45 -08:00
Jonas Devlieghere c722096b39 [debugserver] Remove bridgeos availability
I didn't realize that the 'bridgeos' is not part of the public SDK.
2020-12-05 10:18:45 -08:00
Jonas Devlieghere 0db37576c1 [debugserver] Honor the cpu sub type if specified
Use the newly added spawnattr API, posix_spawnattr_setarchpref_np, to
select a slice preferences per cpu and subcpu types, instead of just cpu
with posix_spawnattr_setarchpref_np.

rdar://16094957

Differential revision: https://reviews.llvm.org/D92712
2020-12-04 20:37:41 -08:00
Jonas Devlieghere 315fab428d [lldb] Remove unused argument to expectedFailure 2020-12-04 20:37:41 -08:00
Raphael Isemann e97b991eef [lldb] Remove LLDB session dir and just store test traces in the respective test build directory
Test runs log some of their output to files inside the LLDB session dir. This
session dir is shared between all tests, so all the tests have to make sure they
choose a unique file name inside that directory. We currently choose by default
`<test-class-name>-<test-method-name>` as the log file name. However, that means
that if not every test class in the test suite has a unique class name, then we
end up with a race condition as two tests will try to write to the same log
file.

I already tried in D83767 changing the format to use the test file basename
instead (which we already require to be unique for some other functionality),
but it seems the code for getting the basename didn't work on Windows.

This patch instead just changes that dotest stores the log files in the build
directory for the current test. We know that directory is unique for this test,
so no need to generate some unique file name now. Also removes all the
environment vars and parameters related to the now unused session dir.

The new log paths now look like this for a failure in 'TestCppOperators`:
```
./lldb-test-build.noindex/lang/cpp/operators/TestCppOperators.test_dwarf/Failure.log
./lldb-test-build.noindex/lang/cpp/operators/TestCppOperators.test_dsym/Failure.log
./lldb-test-build.noindex/lang/cpp/operators/TestCppOperators.test_gmodules/Failure.log
```

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D92498
2020-12-04 11:43:10 +01:00
Raphael Isemann 594308c7ad [lldb][NFC] Rename TypeSystemClang::GetScratch to ScratchTypeSystemClang::GetForTarget
Also add some documentation while I'm at it.
2020-12-04 11:29:08 +01:00
Raphael Isemann 973f3907a4 [lldb][NFC] Rename TypeSystemClangForExpressions to ScratchTypeSystemClang
We keep referring to the single object created by this class as
'scratch AST/Context/TypeSystem' so at this point we might as well rename the
class. It's also not involved at all in expression evaluation, so the
'ForExpressions' prefix is a bit misleading.
2020-12-04 09:41:42 +01:00
Jonas Devlieghere 54710b346c [lldb] Use the cpu subtype enum values from llvm::MachO in ArchSpec (NFC)
Use the cpu subtype enum values from llvm::MachO in the ArchSpec MachO
table. As I'm already cluttering the history, restore the table's
formatting to its original glory.

Differential revision: https://reviews.llvm.org/D92601
2020-12-03 15:10:18 -08:00
Jonas Devlieghere 99ea2c461d [lldb] Refactor the Symbolicator initializer
We found out that we have clients relying on the old signature of the
Symbolicator initializer. Make the signature compatible again and
provide a factory method to initialize the class correctly based on
whether you have a target or want the symbolicator to create one for
you.

Differential revision: D92601
2020-12-03 14:31:59 -08:00
Jonas Devlieghere 9d9959eeac [lldb] Recognize MachO cpu sub-type 2 as arm64
Make sure we recognize cpu sub-type 2 as arm64. In reality it's arm64e,
but we don't have the triple for that. Without this patch, we fall back
to unknown-apple-macosx- for the default architecture, which breaks
things like running expressions without a target.

Differential revision: https://reviews.llvm.org/D92603
2020-12-03 13:31:31 -08:00
Jonas Devlieghere dd2054d38a [lldb] Treat remote macOS debugging like any other remote darwin platform
Extract remote debugging logic from PlatformMacOSX and move it into
PlatformRemoteMacOSX so it can benefit from all the logic necessary for
remote debugging.

Until now, remote macOS debugging was treated almost identical to local
macOS debugging. By moving in into its own class, we can have it inherit
from PlatformRemoteDarwinDevice and all the functionality it provides,
such as looking at the correct DeviceSupport directory.

rdar://68167374

Differential revision: https://reviews.llvm.org/D92452
2020-12-02 17:03:22 -08:00
Jonas Devlieghere dcdd231df6 [lldb] Return the original path when tilde expansion fails.
Differential revision: https://reviews.llvm.org/D92513
2020-12-02 16:01:30 -08:00
Raphael Isemann 640567d464 [lldb] X-FAIL class template parameter pack tests on Windows
Both seem to fail to read values from the non-running target.
2020-12-03 00:38:05 +01:00
Raphael Isemann c49e718051 [lldb][NFC] Make DeclOrigin::Valid() const 2020-12-03 00:08:19 +01:00
Raphael Isemann 291cc1bbea [lldb][NFC] Give class template pack test files unique class names 2020-12-02 19:19:35 +01:00
Pedro Tammela d055e3a0eb [LLDB/Python] Fix segfault on Python scripted entrypoints
The code that gets the ScriptInterpreter was not considering the
case that it receives a Lua interpreter.

Differential Revision: https://reviews.llvm.org/D92249
2020-12-02 11:25:31 +00:00
Raphael Isemann c526426f5c [lldb] Don't reject empty or unnamed template parameter packs
We currently reject all templates that have either zero args or that have a
parameter pack without a name. Both cases are actually allowed in C++, so
rejecting them leads to LLDB instead falling back to a dummy 'void' type. This
leads to all kind of errors later on (most notable, variables that have such
template types appear to be missing as we can't have 'void' variables and
inheriting from such a template type will cause Clang to hit some asserts when
finding that the base class is 'void').

This just removes the too strict tests and adds a few tests for this stuff (+
some combinations of these tests with preceding template parameters).

Things that I left for follow-up patches:
* All the possible interactions with template-template arguments which seem like a whole new source of possible bugs.
* Function templates which completely lack sanity checks.
* Variable templates are not implemented.
* Alias templates are not implemented too.
* The rather strange checks that just make sure that the separate list of
  template arg names and values always have the same length. I believe those
  ought to be asserts, but my current plan is to move both those things into a
  single list that can't end up in this inconsistent state.

Reviewed By: JDevlieghere, shafik

Differential Revision: https://reviews.llvm.org/D92425
2020-12-02 10:50:41 +01:00
Raphael Isemann 9126ba25a3 [lldb][NFC] Fix test file name in lang/cpp/non-type-template-param
The 'AlignAsBaseClass' part was a leftover form the align_as test that served as
the template for this test.
2020-12-02 08:41:53 +01:00
Fangrui Song ce5e21868c [lldb] Fix build after found_decls was removed by 1f40d60a3b 2020-12-01 19:14:35 -08:00
Muhammad Omair Javaid fa7fabb644 [LLDB] Rename duplicate TestAlignAsBaseClass.py
lldb-dotest breaks due to duplicate TestAlignAsBaseClass.py. I have
renamed later version to TestAlignAsBaseClassNonTemplateParam.py.
2020-12-02 07:31:29 +05:00
David Blaikie 615f63e149 Revert "[FastISel] Flush local value map on ever instruction" and dependent patches
This reverts commit cf1c774d6a.

This change caused several regressions in the gdb test suite - at least
a sample of which was due to line zero instructions making breakpoints
un-lined. I think they're worth investigating/understanding more (&
possibly addressing) before moving forward with this change.

Revert "[FastISel] NFC: Clean up unnecessary bookkeeping"
This reverts commit 3fd39d3694.

Revert "[FastISel] NFC: Remove obsolete -fast-isel-sink-local-values option"
This reverts commit a474657e30.

Revert "Remove static function unused after cf1c774."
This reverts commit dc35368ccf.

Revert "[lldb] Fix TestThreadStepOut.py after "Flush local value map on every instruction""
This reverts commit 53a14a47ee.
2020-12-01 14:26:23 -08:00
Michał Górny e1f613ce3c [lldb] [test] Reenable two passing tests on FreeBSD
[Reenable TestReproducerAttach and TestThreadSpecificBpPlusCondition
on FreeBSD -- both seem to pass correctly now.
2020-12-01 23:25:45 +01:00
Muhammad Omair Javaid 78cb4562fa Make offset field optional in RegisterInfo packet for Arm64
This patch carries forward our aim to remove offset field from qRegisterInfo
packets and XML register description. I have created a new function which
returns if offset fields are dynamic meaning client can calculate offset on
its own based on register number sequence and register size. For now this
function only returns true for NativeRegisterContextLinux_arm64 but we can
test this for other architectures and make it standard later.

As a consequence we do not send offset field from lldb-server (arm64 for now)
while other stubs dont have an offset field so it wont effect them for now.
On the client side we have replaced previous offset calculation algorithm
with a new scheme, where we sort all primary registers in increasing
order of remote regnum and then calculate offset incrementally.

This committ also includes a test to verify all of above functionality
on Arm64.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D91241
2020-12-02 03:19:43 +05:00
Muhammad Omair Javaid 26b8ea2e37 RegisterInfoPOSIX_arm64 remove unused bytes from g/G packet
This came up while putting together our new strategy to create g/G packets
in compliance with GDB RSP protocol where register offsets are calculated in
increasing order of register numbers without any unused spacing.

RegisterInfoPOSIX_arm64::GPR size was being calculated after alignment
correction to 8 bytes which meant there was a 4 bytes unused space between
last gpr (cpsr) and first vector register V. We have put LLVM_PACKED_START
decorator on RegisterInfoPOSIX_arm64::GPR to make sure single byte
alignment is enforced. Moreover we are now doing to use arm64 user_pt_regs
struct defined in ptrace.h for accessing ptrace user registers.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D92063
2020-12-02 03:19:39 +05:00
Raphael Isemann 64f04629aa [lldb][NFC] Modernize and cleanup TestClassTemplateParameterPack
* Un-inline the test.
* Use expect_expr everywhere and also check all involved types.
* Clang-format the test sources.
* Explain what we're actually testing with the 'C' and 'D' templates.
* Split out the non-template-parameter-pack part of the test into its own small test.
2020-12-01 15:53:40 +01:00
Jonas Devlieghere 173bb3c2eb [lldb] Refactor GetDeviceSupportDirectoryNames and GetPlatformName (NFC)
Both functions are effectively returning a single string literal. Change
the interface to return a llvm::StringRef instead of populating a vector
of std::strings or returning a std::string respectively.
2020-11-30 19:37:12 -08:00
Jonas Devlieghere 1b9f214efc [lldb] Give TestDefaultTemplateArgs a unique class name
Multiple tests cannot share the same test class name.
2020-11-30 14:41:35 -08:00
Raphael Isemann e0e7bbeb54 [lldb] Always include template arguments that have their default value in the internal type name
Our type formatters/summaries match on the internal type name we generate in LLDB for Clang types.

These names were generated using Clang's default printing policy. However Clang's
default printing policy got tweaked over the last month to make the generated type
names more readable (by for example excluding inline/anonymous namespaces and
removing template arguments that have their default value). This broke the formatter
system where LLDB's matching logic now no longer can format certain types as
the new type names generated by Clang's default printing policy no longer match
the type names that LLDB/the user specified.

I already introduced LLDB's own type printing policy and fixed the inline/anonymous
namespaces in da121fff11 (just to get the
test suite passing again).

This patch is restoring the old type printing behaviour where always include the template
arguments in the internal type name (even if they match the default args). This should get
template type formatters/summaries working again in the rare situation where we do
know template default arguments within LLDB. This can only happen when either having
a template that was parsed in the expression parser or when we get type information from a C++ module.

The Clang change that removed defaulted template arguments from Clang's printing policy was
e7f3e2103c

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D92311
2020-11-30 16:40:50 +01:00
Pedro Tammela a0d7406ae8 [LLDB/Lua] add support for one-liner breakpoint callback
These callbacks are set using the following:
   breakpoint command add -s lua -o "print('hello world!')"

The user supplied script is executed as:
   function (frame, bp_loc, ...)
      <body>
   end

So the local variables 'frame', 'bp_loc' and vararg are all accessible.
Any global variables declared will persist in the Lua interpreter.
A user should never hold 'frame' and 'bp_loc' in a global variable as
these userdatas are context dependent.

Differential Revision: https://reviews.llvm.org/D91508
2020-11-30 14:12:26 +00:00
Muhammad Omair Javaid 4e8aeb97ca Send SVE vg register in custom expedited registerset
This patch ovverides GetExpeditedRegisterSet for
NativeRegisterContextLinux_arm64 to send vector granule register in
expedited register set if SVE mode is selected.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D82855
2020-11-30 17:34:19 +05:00
Muhammad Omair Javaid b69c09bf43 Support custom expedited register set in gdb-remote
This patch adds capability to introduce a custom expedited register set
in gdb remote. Currently we send register set 0 as expedited register set
but for the case of AArch64 SVE we intend to send additional information
about SVE registers size/offset configuration which can be calculated
from vg register. Therefore we will expedited Vg register in case of
AArch64 is in SVE mode to speedup register configuration calculations.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D82853
2020-11-30 17:34:19 +05:00
David Spickett a7f8d96b16 [lldb] Use llvm::Optional for port in LaunchGDBServer
Previously we used UINT16_MAX to mean no port/no specifc
port. This leads to confusion because 65535 is a valid
port number.

Instead use an optional. If you want a specific port call
LaunchGDBServer as normal, otherwise pass an empty optional
and it will be set to the port that gets chosen.
(or left empty in the case where we fail to find a port)

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D92035
2020-11-30 11:20:39 +00:00
David Spickett 98e87f76d0 [lldb] Error when there are no ports to launch a gdbserver on
Previously if you did:
$ lldb-server platform --server <...> --min-gdbserver-port 12346
--max-gdbserver-port 12347
(meaning only use port 12346 for gdbservers)

Then tried to launch two gdbservers on the same connection,
the second one would return port 65535. Which is a real port
number but it actually means lldb-server didn't find one it was
allowed to use.

send packet: $qLaunchGDBServer;<...>
read packet: $pid:1919;port:12346;#c0
<...>
send packet: $qLaunchGDBServer;<...>
read packet: $pid:1927;port:65535;#c7

This situation should be an error even if port 65535 does happen
to be available on the current machine.

To fix this make PortMap it's own class within
GDBRemoteCommunicationServerPlatform.

This almost the same as the old typedef but for
GetNextAvailablePort() returning an llvm::Expected.
This means we have to handle not finding a port,
by returning an error packet.

Also add unit tests for this new PortMap class.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D91634
2020-11-30 10:19:14 +00:00
Pavel Labath b6e04ac5aa [lldb/test] Avoid the socket "pump" thread
A separate thread is not necessary, as we can do its work on the main
thread, while waiting for the packet to arrive. This makes the code
easier to understand and debug (other simplifications are possible too,
but I'll leave that for separate patches). The new implementation also
avoids busy waiting.
2020-11-30 09:07:45 +01:00
Raphael Isemann 3f6c856bb5 [ASTImporter] Import the default argument of TemplateTypeParmDecl
The test case isn't using the AST matchers for all checks as there doesn't seem to be support for
matching TemplateTypeParmDecl default arguments. Otherwise this is simply importing the
default arguments.

Also updates several LLDB tests that now as intended omit the default template
arguments of several std templates.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D92103
2020-11-26 18:01:30 +01:00
Raphael Isemann 53a14a47ee [lldb] Fix TestThreadStepOut.py after "Flush local value map on every instruction"
After cf1c774d6a, Clang seems to generate code
that is more similar to icc/Clang, so we can use the same line numbers for
all compilers in this test.
2020-11-26 09:43:47 +01:00
Richard Smith 3fb0879867 Refactor and simplify class scope name lookup.
This is partly in preparation for an upcoming change that can change the
order in which DeclContext lookup results are presented.

In passing, fix some obvious errors where name lookup's notion of a
"static member function" missed static member function templates, and
where its notion of "same set of declarations" was confused by the same
declarations appearing in a different order.
2020-11-25 16:25:33 -08:00
Paul Robinson cf1c774d6a [FastISel] Flush local value map on ever instruction
Local values are constants or addresses that can't be folded into
the instruction that uses them. FastISel materializes these in a
"local value" area that always dominates the current insertion
point, to try to avoid materializing these values more than once
(per block).

https://reviews.llvm.org/D43093 added code to sink these local
value instructions to their first use, which has two beneficial
effects. One, it is likely to avoid some unnecessary spills and
reloads; two, it allows us to attach the debug location of the
user to the local value instruction. The latter effect can
improve the debugging experience for debuggers with a "set next
statement" feature, such as the Visual Studio debugger and PS4
debugger, because instructions to set up constants for a given
statement will be associated with the appropriate source line.

There are also some constants (primarily addresses) that could be
produced by no-op casts or GEP instructions; the main difference
from "local value" instructions is that these are values from
separate IR instructions, and therefore could have multiple users
across multiple basic blocks. D43093 avoided sinking these, even
though they were emitted to the same "local value" area as the
other instructions. The patch comment for D43093 states:

  Local values may also be used by no-op casts, which adds the
  register to the RegFixups table. Without reversing the RegFixups
  map direction, we don't have enough information to sink these
  instructions.

This patch undoes most of D43093, and instead flushes the local
value map after(*) every IR instruction, using that instruction's
debug location. This avoids sometimes incorrect locations used
previously, and emits instructions in a more natural order.

This does mean materialized values are not re-used across IR
instruction boundaries; however, only about 5% of those values
were reused in an experimental self-build of clang.

(*) Actually, just prior to the next instruction. It seems like
it would be cleaner the other way, but I was having trouble
getting that to work.

Differential Revision: https://reviews.llvm.org/D91734
2020-11-25 13:05:00 -05:00
Muhammad Omair Javaid 2bd4540f38 [LLDB] Fix typo in RegisterContextPOSIXProcessMonitor_arm64
This patch fixes a minor typo in RegisterContextPOSIXProcessMonitor_arm64
constructor where memset target was wrongly specified as m_fpr instead of
m_gpr_arm64.
2020-11-24 07:09:00 +05:00
Jonas Devlieghere b20f3cc5b5 [lldb] Add platform select to TestProcessConnect.py
Extend TestProcessConnect to cover the scenario fixed by
6c0cd5676e. This replaces
command-process-connect.test which would fail if port 4321
was open.
2020-11-23 18:02:00 -08:00
Jordan Rupprecht 5b8e4a1102 [lldb/test] Remove flaky `process connect` test.
This test is flaky because it assumes port 4321 is not already open on a machine.
2020-11-23 12:49:50 -08:00
Michał Górny a8f6f4e873 [lldb] [test] Restore Windows-skip on 'process connect' tests 2020-11-23 14:27:32 +01:00
Michał Górny 18e4272a4f [lldb] Prevent 'process connect' from using local-only plugins
Add a 'can_connect' parameter to Process plugin initialization, and use
it to filter plugins to these capable of remote connections.  This is
used to prevent 'process connect' from picking up a plugin that can only
be used locally, e.g. the legacy FreeBSD plugin.

Differential Revision: https://reviews.llvm.org/D91810
2020-11-23 09:48:55 +01:00
Michał Górny 8018e7b447 [lldb] [Process/FreeBSDRemote] Fix regset names and related tests
Restore Linux-alike regset names for AVX/MPX registers
as TestLldbGdbServer seems to depend on them.  At the same time, fix
TestRegisters to be aware that they are not available on FreeBSD
and NetBSD, at least until we figure out a better way of reporting
unsupported register sets.

Differential Revision: https://reviews.llvm.org/D91923
2020-11-23 09:28:20 +01:00
Michał Górny 9367b57dad [lldb] [test] Fix qRegisterInfo lldb-server tests to handle missing registers
Fix qRegisterInfo tests to handle Exx error response when querying
registers that are not supported on the platform in question.  This
is how FreeBSD and NetBSD platforms reporting missing registers right
now, and there certainly is value from verifying the remaining
registers.

This change fixes the test for FreeBSD but NetBSD has other regressions
that still need to be researched.

Differential Revision: https://reviews.llvm.org/D91922
2020-11-23 09:26:23 +01:00
Michał Górny 8f2f9a82e2 [lldb] [Process/Utility] Declare register overlaps between ST and MM
Explicitly declare register overlaps/invalidation between ST(i) and MMi
registers.

Differential Revision: https://reviews.llvm.org/D91728
2020-11-23 09:23:14 +01:00
Michał Górny 7b7c372e3f [lldb] [Process/FreeBSD] Add missing 'override' kws to POSIXStopInfo
Differential Revision: https://reviews.llvm.org/D91934
2020-11-23 09:22:41 +01:00
Michał Górny 8aea95f3cb [lldb] Reland "Use translated full ftag values"
Translate between abridged and full ftag values in order to expose
the latter in the gdb-remote protocol while the former are used by
FXSAVE/XSAVE...  This matches the gdb behavior.

The Shell/Register tests now rely on the new behavior, and therefore
are run on non-Darwin systems only.  The Python (API) test relies
on the legacy behavior, and is run on Darwin only.

Differential Revision: https://reviews.llvm.org/D91504
2020-11-21 17:11:38 +01:00
Nathan Lanza 33c79f76af Revert "[lldb] add a missing dependency on intrinsics_gen"
This reverts commit 137ff73317.

This belongs in Apple's Swift fork since this is a direct fix for
unified Swift + llvm + lldb builds.
2020-11-20 16:02:16 -05:00
Dave Lee dbcc69217a [lldb] Add examples and reword source-map help string
Update the help string for `target.source-map` to remove the use of the word
"duple" and to add examples. Additionally I rewrote parts with the goal of
making the description more concrete.

rdar://68736012

Differential Revision: https://reviews.llvm.org/D91742
2020-11-20 10:01:36 -08:00
Raphael Isemann ffb3fd8f18 Partially revert '[MachO] Update embedded part of ObjectFileMachO for Mangled API change'
Commit f3aa9e36d9 fixed the embedded OS
build by removing all passed args for `GetName`/`GetDemangledName`. The motivation
for this was that these arguments were apparently removed in
commit 22b044877d. However, only `GetName`'s language
argument was removed but the mangling preference argument was *not* removed
(and unfortunately had a default argument). So when that commit removed all
the args it didn't just fix the build but it also changed all the mangling
preferences to 'demangled' for all `GetName` calls.

Also some `GetName` calls were outside the TARGET_OS_EMBEDDED ifdef, so
this change ended up breaking the following tests on macOS:

  lldb-api :: lang/objc/objc-static-method-stripped/TestObjCStaticMethodStripped.py
  lldb-api :: lang/objc/objc-super/TestObjCSuper.py

From what I can see f3aa9e36d9 removed 12 ePreferMangled args and this patch
re-adds 12 args with roughly the same line numbers, so this *should* restore the
old behaviour and also keep the embedded build working. On the other hand,
ObjectFileMachO::ParseSymtab is a very successful attempt at writing
the longest possible function within LLVM, so this fix is partly based
on the engineering principle known as "hoping for the best".
2020-11-20 13:31:36 +01:00
David Spickett 32541685b2 [lldb][AArch64/Linux] Show memory tagged memory regions
This extends the "memory region" command to
show tagged regions on AArch64 Linux when the MTE
extension is enabled.

(lldb) memory region the_page
[0x0000fffff7ff8000-0x0000fffff7ff9000) rw-
memory tagging: enabled

This is done by adding an optional "flags" field to
the qMemoryRegion packet. The only supported flag is
"mt" but this can be extended.

This "mt" flag is read from /proc/{pid}/smaps on Linux,
other platforms will leave out the "flags" field.

Where this "mt" flag is received "memory region" will
show that it is enabled. If it is not or the target
doesn't support memory tagging, the line is not shown.
(since majority of the time tagging will not be enabled)

Testing is added for the existing /proc/{pid}/maps
parsing and the new smaps parsing.
Minidump parsing has been updated where needed,
though it only uses maps not smaps.

Target specific tests can be run with QEMU and I have
added MTE flags to the existing helper scripts.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D87442
2020-11-20 11:21:59 +00:00
Michał Górny f0e2c5131e [lldb] [test/Register] XFAIL x86-fp-write on Darwin 2020-11-20 09:43:08 +01:00
Michał Górny 3a230101fe Revert "[LLDB] Fixing lldb/test/Shell/Register/x86-fp-write.test"
The problem is not specific to arch but to the whole Darwin platform.

Reverts: 0fd04337a1
2020-11-20 09:42:13 +01:00
shafik 0fd04337a1 [LLDB] Fixing lldb/test/Shell/Register/x86-fp-write.test
D91497 changed lldb/test/Shell/Register/x86-fp-write.test and added target-x86_64 to the REQUIRES clause.
It looks this test does not pass on this platform so removing it since it one of tests failing on the
green dragon build bot.
2020-11-19 16:29:28 -08:00