Commit Graph

24452 Commits

Author SHA1 Message Date
Med Ismail Bennani 36eab4634f [lldb/Interpreter] Add `interpreter.repeat-previous-command` setting
This patch introduces a new interpreter setting to prevent LLDB from
re-executing the previous command when passing an empty command.

This can be very useful when performing actions that requires a long
time to complete.

To preserve the original behaviour, the setting defaults to `true`.

rdar://74983516

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-03-05 19:33:32 +01:00
Dave Lee e7361c8ecc [lldb] Rename QueueFundamentalPlan to QueueBasePlan (NFC)
Minor change for naming consistency.

Differential Revision: https://reviews.llvm.org/D97985
2021-03-04 21:46:49 -08:00
Med Ismail Bennani c16fef19f6 [lldb/Interpreter] Make OptionGroupPythonClassWithDict options non-required
When using `OptionGroupPythonClassWithDict` options in an `OptionGroup`
with other `Options`, it can happen that the combinaison of some options
of each group makes the command invalid.

To solve that issue, this patch adds a bitmask argument to the
`OptionGroupPythonClassWithDict` constuctor that is used to mark each
option as required (or not).

If the `required_options` bitmask isn't passed to the constructor, the
class will keep its default behaviour, making the `--script-class` and
`--python-function` required.

rdar://65508855

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-03-04 20:24:26 +01:00
Pavel Labath bf3ac994c4 [lldb] Apply gdb-remote timeout to platform connections as well
We have a plugin.process.gdb-remote.packet-timeout setting, which can be
used to control how long the lldb client is willing to wait before
declaring the server side dead. Our test suite makes use of this
feature, and sets the setting value fairly high, as the low default
value can cause flaky tests, particularly on slower bots.

After fixing TestPlatformConnect (one of the few tests exercising the
remote platform capabilities of lldb) in 4b284b9ca, it immediately
started being flaky on the arm bots. It turns out this is because the
packet-timeout setting is not being applied to platform connections.

This patch makes the platform connections also respect the value of this
setting. It also adds a test which checks that the timeout value is
being honored.

Differential Revision: https://reviews.llvm.org/D97769
2021-03-04 14:46:02 +01:00
Jonas Devlieghere 3dcbfa27d4 [debugserver] Fix more compiler warnings on arm64
This fixes the following two warnings in code that's only compiled on
arm64:

 - warning: cast from 'const void *' to 'unsigned char *' drops const
   qualifier [-Wcast-qual]
 - warning: embedding a directive within macro arguments has undefined
   behavior [-Wembedded-directive]
2021-03-03 23:12:12 -08:00
Jason Molenda 266bb78f7d LanguageRuntime for 0th frame unwind, simplify getting pc-for-symbolication
Add calls into LanguageRuntime when finding the unwind method to
use out of the 0th (currently executing) stack frame.

Allow for the LanguageRuntimes to indicate if this stack frames
should be treated like a zeroth-frame -- symbolication should be
done based on the saved pc address, not decremented like normal ABI
function calls.

Add methods to RegisterContext and StackFrame to get a pc value
suitable for symbolication, to reduce the number of places in lldb
where we decrement the saved pc values before symbolication.

<rdar://problem/70398009>
Differential Revision: https://reviews.llvm.org/D97644
2021-03-03 19:29:40 -08:00
Raphael Isemann 820a846609 [lldb][NFC] Delete unused AddressResolverName
That's all just dead code that hasn't been changed in years.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D97760
2021-03-03 13:30:02 +01:00
Andy Yankovsky 3b47bd32f9 [lldb] Fix handling of `DW_AT_decl_file` according to D91014 (attempt #2)
Apply changes from https://reviews.llvm.org/D91014 to other places where DWARF entries are being processed.

Test case is provided by @jankratochvil.
The test is marked to run only on x64 and exclude Windows and Darwin, because the assembly is not OS-independent.

(First attempt https://reviews.llvm.org/D96778 broke the build bots)

Reviewed By: jankratochvil

Differential Revision: https://reviews.llvm.org/D97765
2021-03-03 10:27:35 +01:00
Jonas Devlieghere db8b1598b7 [lldb] Inline objc_opt->version >= 14 to avoid dealing with bool type 2021-03-02 16:41:44 -08:00
Jonas Devlieghere c85d47f7b8 [lldb] Add more logging to __lldb_apple_objc_v2_get_dynamic_class_info 2021-03-02 16:24:59 -08:00
Jonas Devlieghere f46a441b1c [lldb] Extend Python convenience variable table with equivalent APIs
Add a column to the table of convenience variables with the equivalent
API to get to the current debugger, target, process, etc.

We often get asked to make convenience variables available outside of
the interactive interpreter. After explaining why that's not possible, a
common complaint is that it's hard to find out how to get to these
variables in a non-interactive context, for example how to get to the
current frame when given a thread. This patch aims to alleviate that by
including the APIs to navigate between these instances in the table.

Differential revision: https://reviews.llvm.org/D97778
2021-03-02 16:13:55 -08:00
Neal (nealsid) 5826aa48f0 Migrate to llvm::unique_function instead of static member functions for callbacks
A few cleanups suggested in another patch review's comments:

1. Use llvm:unique_function for storing & invoking callbacks from
   Editline to IOHandler
2. Change return type of one of the callback setters from bool to void,
   since it's return value was never used
3. Moved the callback setters inline & made them nonstatic, since that's
   more consistent with other setter definitions
4. Removed the baton parameter since we no longer need it anymore

Differential revision: https://reviews.llvm.org/D50299
2021-03-02 16:13:54 -08:00
Adrian Prantl 14ccba26bd Promote scalars to load addresses when dereferencing them.
This is a follow-up to 188b0747c1. This
is a very narrow fix to a more general problem. LLDB should be better
at distinguishing between implict and memory location descriptions.

rdar://74902042
2021-03-02 14:30:39 -08:00
Jan Kratochvil 1b8fdaacf4 [nfc] [lldb] DWARFDebugInfoEntry::Extract(): reindent 2021-03-02 16:44:07 +01:00
Jan Kratochvil 61c29321b3 [lldb] DWARFDebugInfoEntry::Extract(): Print an error for unsupported DW_FORM_* 2021-03-02 16:39:04 +01:00
Jan Kratochvil 4096ae06f4 [lldb] Support DWARF-5 DW_FORM_line_strp (used by GCC)
LLDB has been failing on binaries produced by new GCC 11.0 with -gdwarf-5.

Differential Revision: https://reviews.llvm.org/D97721
2021-03-02 15:17:23 +01:00
Muhammad Omair Javaid 536783170f Support GDB remote g packet partial read
GDB remote protocol does not specify length of g packet for register read. It depends on remote to include all or exclude certain registers from g packet. In case a register or set of registers is not included as part of g packet then we should fall back to p packet for reading all registers excluded from g packet by remote. This patch adds support for above feature and adds a test-case for the same.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D97498
2021-03-02 17:21:48 +05:00
Raphael Isemann 1432ab171f [lldb] Add missing include to Cloneable.h
This header is using make_shared so it needs to include <memory>.
2021-03-02 11:01:08 +01:00
Pavel Labath a63daf693c [lldb] Remote leftover _llgs from TestGdbRemoteConnection.py
the suffix will be added when the test is instantiated for llgs and
debugserver.
2021-03-02 10:59:25 +01:00
Kazu Hirata 4fd3347d6e [lldb] Fix typos in documentation (NFC) 2021-03-01 23:40:29 -08:00
Yuanfang Chen 5de2d189e6 [Diagnose] Unify MCContext and LLVMContext diagnosing
The situation with inline asm/MC error reporting is kind of messy at the
moment. The errors from MC layout are not reliably propagated and users
have to specify an inlineasm handler separately to get inlineasm
diagnose. The latter issue is not a correctness issue but could be improved.

* Kill LLVMContext inlineasm diagnose handler and migrate it to use
  DiagnoseInfo/DiagnoseHandler.
* Introduce `DiagnoseInfoSrcMgr` to diagnose SourceMgr backed errors. This
  covers use cases like inlineasm, MC, and any clients using SourceMgr.
* Move AsmPrinter::SrcMgrDiagInfo and its instance to MCContext. The next step
  is to combine MCContext::SrcMgr and MCContext::InlineSrcMgr because in all
  use cases, only one of them is used.
* If LLVMContext is available, let MCContext uses LLVMContext's diagnose
  handler; if LLVMContext is not available, MCContext uses its own default
  diagnose handler which just prints SMDiagnostic.
* Change a few clients(Clang, llc, lldb) to use the new way of reporting.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D97449
2021-03-01 15:58:37 -08:00
Med Ismail Bennani 36254f1a0f
[lldb] Revert ScriptedProcess patches
This patch reverts the following commits:
- 5a9c34918b
- 46796762af
- 2cff3dec11
- 182f0d1a34
- d62a53aaf1

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-03-01 23:23:27 +00:00
Jonas Devlieghere 6dbea3efc5 [lldb] Add scoped timer to HostInfoMacOSX::GetXcodeSDKPath 2021-03-01 14:57:42 -08:00
Stella Stamenova 801067f4c0 [mlir][lldb] Fix several gcc warnings in mlir and lldb
These warnings are raised when compiling with gcc due to either having too few or too many commas, or in the case of lldb, the possibility of a nullptr.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D97586
2021-03-01 13:48:22 -08:00
Med Ismail Bennani 5a9c34918b [lldb/Plugins] Fix SWIGPythonBridge build issue
This patch should fi the build issue on the windows bots:
https://lab.llvm.org/buildbot/#/builders/83/builds/4214/steps/5/logs/stdio

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-03-01 22:37:36 +01:00
Med Ismail Bennani 46796762af [lldb/Plugins] Add ScriptedProcess Process Plugin
This patch introduces Scripted Processes to lldb.

The goal, here, is to be able to attach in the debugger to fake processes
that are backed by script files (in Python, Lua, Swift, etc ...) and
inspect them statically.

Scripted Processes can be used in cooperative multithreading environments
like the XNU Kernel or other real-time operating systems, but it can
also help us improve the debugger testing infrastructure by writting
synthetic tests that simulates hard-to-reproduce process/thread states.

Although ScriptedProcess is not feature-complete at the moment, it has
basic execution capabilities and will improve in the following patches.

rdar://65508855

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-03-01 21:13:32 +01:00
Med Ismail Bennani 2cff3dec11 [lldb/bindings] Add Python ScriptedProcess base class to lldb module
In order to facilitate the writting of Scripted Processes, this patch
introduces a `ScriptedProcess` python base class in the lldb module.

The base class holds the python interface with all the - abstract -
methods that need to be implemented by the inherited class but also some
methods that can be overwritten.

This patch also provides an example of a Scripted Process with the
`MyScriptedProcess` class.

rdar://65508855

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-03-01 21:13:32 +01:00
Med Ismail Bennani 182f0d1a34 [lldb/Interpreter] Add ScriptInterpreter Wrapper for ScriptedProcess
This patch adds a ScriptedProcess interface to the ScriptInterpreter and
more specifically, to the ScriptInterpreterPython.

This interface will be used in the C++ `ScriptProcess` Process Plugin to
call the script methods.

At the moment, not all methods are implemented, they will upstreamed in
upcoming patches.

This patch also adds helper methods to the ScriptInterpreter to
convert `SBAPI` Types (SBData & SBError) to `lldb_private` types
(DataExtractor & Status).

rdar://65508855

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-03-01 21:13:31 +01:00
Med Ismail Bennani d62a53aaf1 [lldb/Commands] Add command options for ScriptedProcess to ProcessLaunch
This patch adds a new command options to the CommandObjectProcessLaunch
for scripted processes.

Among the options, the user need to specify the class name managing the
scripted process. The user can also use a key-value dictionary holding
arbitrary data that will be passed to the managing class.

This patch also adds getters and setters to `SBLaunchInfo` for the
class name managing the scripted process and the dictionary.

rdar://65508855

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-03-01 21:13:31 +01:00
Med Ismail Bennani 103ad3f907 [lldb/Commands] Fix short option collision for `process launch`
This patch changes the short option used in `CommandOptionsProcessLaunch`
for the `-v|--environment` command option to `-E|--environment`.

The reason for that is, that it collides with the `-v|--structured-data-value`
command option generated by `OptionGroupPythonClassWithDict` that
I'm using in an upcoming patch for the `process launch` command.

The long option `--environment` remains the same.

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-03-01 21:13:31 +01:00
Jan Kratochvil 011e7bcaa3 Revert "[lldb] Fix handling of `DW_AT_decl_file` according to D91014"
This reverts commit 7ec7876fed.

Non-x86_64 non-Linux bots broke by the testcase.
2021-03-01 20:45:30 +01:00
Shoaib Meenai 015d78a25e [lldb] Remove XPCServices symlinking
This is a downstream change that was accidentally included upstream.

Reviewed By: vsk

Differential Revision: https://reviews.llvm.org/D97701
2021-03-01 11:23:46 -08:00
David Blaikie 776be16ba0 Fix virtual-dtor warning a different way, since a virtual dtor is not required for this use case. 2021-03-01 09:25:26 -08:00
David Blaikie e913a75414 Fix a warning about named return value not being moved-from.
The use of an rvalue reference here was using reference lifetime
extension needlessly - the code is simpler and more efficient without
it.
2021-03-01 09:25:26 -08:00
Michał Górny 95a1305fb4 [lldb] [test] Skip AVX lldb-server test on non-x86 architectures
Skip the AVX-related lldb-server test on non-x86 architectures, as they
do not support AVX.  While technically the test worked on Linux because
the AVX check would simply return false, other platforms do not provide
such a straightforward way of checking for AVX (especially remotely),
and the results of such check may need to be interpreted specially
for the platform in question.

Differential Revision: https://reviews.llvm.org/D97450
2021-03-01 16:23:36 +01:00
Michał Górny 15f067f1c7 [lldb] [test] Workaround symlink-related test failures
Use realpath() when spawning the executable create_after_attach
to workaround a FreeBSD plugin (and possibly others) problem.
If the executable is started via a path containing a symlink, it is
added to the module list twice -- via the real and apparent path.
This in turn cases the requested breakpoint to resolve twice.

Use realpath() for main program path in lldb-vscode breakpoint tests
to workaround a similar problem.  If the passed path does not match
the realpath, lldb-vscode does not report the breakpoints as verified
and causes tests to fail.

Since the underlying problems are non-trivial to fix and the purpose
of these tests is not to reproduce symlink problems, let's apply
trivial workarounds to make them pass.

Differential Revision: https://reviews.llvm.org/D97230
2021-03-01 16:23:36 +01:00
Michał Górny c41372c8a1 [lldb] Rename NativeRegisterContext{Watchpoint => DBReg}_x86
Differential Revision: https://reviews.llvm.org/D97210
2021-03-01 16:23:36 +01:00
Andy Yankovsky 7ec7876fed [lldb] Fix handling of `DW_AT_decl_file` according to D91014
Apply changes from https://reviews.llvm.org/D91014 to other places where DWARF entries are being processed.

Differential Revision: https://reviews.llvm.org/D96778
2021-03-01 16:01:11 +01:00
Benjamin Kramer 99c24f7aa8 [lldb/Interpreter] Pacify -Wnon-virtual-dtor 2021-03-01 11:20:14 +01:00
Tatyana Krasnukha 1d6a6f3b0c [lldb/Target] Remove outdated code
Arg0 callback does work.
2021-02-28 19:23:27 +03:00
Tatyana Krasnukha f0f183ee4a [lldb/Interpreter] Fix deep copying for OptionValue classes
Some implementations of the DeepCopy function called the copy constructor that copied m_parent member instead of setting a new parent. Others just leaved the base class's members (m_parent, m_callback, m_was_set) empty.
One more problem is that not all classes override this function, e.g. OptionValueArgs::DeepCopy produces OptionValueArray instance, and Target[Process/Thread]ValueProperty::DeepCopy produces OptionValueProperty. This makes downcasting via static_cast invalid.

The patch implements idiom "virtual constructor" to fix these issues.
Add a test that checks DeepCopy for correct copying/setting all data members of the base class.

Differential Revision: https://reviews.llvm.org/D96952
2021-02-28 19:23:25 +03:00
Tatyana Krasnukha ef447fe008 [lldb] OptionValueProperties::Get[Set]PropertyAtIndexAsArgs should handle OptionValueArgs 2021-02-28 19:23:22 +03:00
Tatyana Krasnukha b2faf30189 [lldb][NFC] Make OptionValueArgs::GetArgs constant 2021-02-28 19:23:20 +03:00
Tatyana Krasnukha 8cdcd41e38 [lldb/Interpreter][NFC] Remove explicit default initialization of members and base classes
According to clang-tidy's readability-redundant-member-init.
2021-02-28 19:23:18 +03:00
Tatyana Krasnukha 54d03a4985 [lldb/Interpreter][NFC] Replace default constructors/destructors bodies with "=default" 2021-02-28 19:23:16 +03:00
Tatyana Krasnukha 9182117861 [lldb/Interpreter][NFC] Remove more deleted const char* overloads
A follow-up commit to D96861.
2021-02-28 19:23:14 +03:00
Dave Lee 3a677b29a3 [lldb] Add deref support to libc++ unique_ptr synthetic
Add frame variable dereference suppport to libc++ `std::unique_ptr`.

This change allows for commands like `v *thing_up` and `v thing_up->m_id`. These commands now work the same way they would with raw pointers, and as they would with expression. This is done by adding an unaccounted for child member named `$$dereference$$`.

Without this change, the command would have to be written as `v *thing_up.__value_` or v thing_up.__value_->m_id` which exposes internal structure and is more clumsy to type.

Additionally, the existing tests were updated. See also https://reviews.llvm.org/D97165 which added deref support for `std::shared_ptr`.

Differential Revision: https://reviews.llvm.org/D97524
2021-02-26 07:39:01 -08:00
Med Ismail Bennani b889ef4214 [lldb/Core] Change large function threshold variable into a setting.
This patch replaces the static large function threshold variable with a
global debugger setting (`stop-disassembly-max-size`).

The default threshold is now set to 32KB (instead of 8KB) and can be modified.

rdar://74726362

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-02-25 22:35:04 +01:00
Raphael Isemann 86c267233f [lldb][NFC] Document ClangASTImporter 2021-02-25 13:25:34 +01:00
Raphael Isemann 2d6b767c1d [lldb][NFC] Remove some obsolete comments in ClangASTImporter.cpp
The first two comments are incomplete and reference obsolete code. The
last one is just commented out code (that also doesn't look correct).
2021-02-25 11:44:19 +01:00
Raphael Isemann 7cfa6e1cc6 [lldb] Let ClangASTImporter assert that the target AST has an external source
This prevents people from accidentially using this code outside the
intended setup.
2021-02-25 11:42:14 +01:00
Harmen Stoppels a54f160b3a Prefer /usr/bin/env xxx over /usr/bin/xxx where xxx = perl, python, awk
Allow users to use a non-system version of perl, python and awk, which is useful
in certain package managers.

Reviewed By: JDevlieghere, MaskRay

Differential Revision: https://reviews.llvm.org/D95119
2021-02-25 11:32:27 +01:00
Jonas Devlieghere 011a8e218e [debugserver] Fix logic to extract app bundle from file path
Fix the logic to find the app bundle in a path by correctly accounting
for paths containing multiple occurrences of `.app`. The new logic will
correctly extract `com.app.Foo.app` from `com.app.Foo.app/com.app.Foo`.

rdar://74666208

Differential revision: https://reviews.llvm.org/D97441
2021-02-24 23:08:42 -08:00
Jonas Devlieghere 38dfb235db [lldb] Support debugging utility functions
LLDB uses utility functions to run code in the inferior for its own
internal purposes, such as reading classes from the Objective-C runtime
for example. Because these expressions should be transparent to the
user, we ignore breakpoints and unwind the stack on errors, which
makes them hard to debug.

This patch adds a new setting target.debug-utility-expression that, when
enabled, changes these options to facilitate debugging. It enables
breakpoints, disables unwinding and writes out the utility function
source code to disk so it shows up in the source view.

Differential revision: https://reviews.llvm.org/D97249
2021-02-24 11:36:01 -08:00
Raphael Isemann 6201017d54 [lldb] Prevent double new lines behind errors/warning/messages from LLDB commands
The current API for printing errors/warnings/messages from LLDB commands
sometimes adds newlines behind the messages for the caller. However, this
happens unconditionally so when the caller already specified a trailing newline
in the error message (or is trying to print a generated error message that ends
in a newline), LLDB ends up printing both the automatically added newline and
the one that was in the error message string. This leads to all the randomly
appearing new lines in error such as:

```
(lldb) command a
error: 'command alias' requires at least two arguments
(lldb) apropos a b
error: 'apropos' must be called with exactly one argument.

(lldb) why is there an empty line behind the second error?
```

This code adds a check that only appends the new line if the passed message
doesn't already contain a trailing new line.

Also removes the AppendRawWarning which had only one caller and doesn't serve
any purpose now.

Reviewed By: #lldb, mib

Differential Revision: https://reviews.llvm.org/D96947
2021-02-24 14:42:01 +01:00
Raphael Isemann 0512b01ebe [lldb][NFC] Move trivial ValueObject getters/setters to the header
NFC refactoring that moves the definitions of all the trivial getters/setters to the header file
which is what we usually do in LLVM.

Reviewed By: #lldb, JDevlieghere

Differential Revision: https://reviews.llvm.org/D97298
2021-02-24 14:04:01 +01:00
Raphael Isemann 4631afdeb3 [lldb][NFC] Rename the second ValueObjectManager to ValueObjectUpdater and remove the dead code
`ValueObject.h` contains the `ValueObject::ValueObjectManager` type which is
just a typedef for the ClusterManager that takes care of the whole ValueObject
memory management. However, there is also `ValueObjectManager` defined in the
same header which is only used in the curses UI implementation and consists
mostly of dead and completely untested code.

This code been around since a while (it was added in 2016 as
8369b28da0), so I think we shouldn't just revert
the whole patch.

Instead this patch just moves the class to its own header that it isn't just
hiding in the ValueObject header and renames it to `ValueObjectUpdater` that it
at least has a unique name (which I hope also slightly better reflects the
purpose of this class). I also deleted all the dead code branches and functions.

Reviewed By: #lldb, mib, JDevlieghere

Differential Revision: https://reviews.llvm.org/D97287
2021-02-24 13:58:01 +01:00
Raphael Isemann 2105912ee0 [lldb] Add asserts that prevent construction of cycles in the decl origin tracking
LLDB tracks where any imported `clang::Decl` originally came from via a simple
map from 'imported decl' to 'original decl'. That information is used to later
complete parts of the Decl when more information is requested about a certain
Decl (e.g., via the ExternalASTSource interface from Clang).

When finding the 'original decl' for a given decl, the ASTImporterDelegate
essentially just recursively follows the previously mentioned map from
'imported' to 'original decl' until it can find any further 'original decl'. The
final found decl is then the one that will be imported. The recursion is
necessary as in LLDB we don't just import decls from one ASTContext to another,
but also from one ASTContext to another via a (potentially temporary)
ASTContext. For example, the expression parser creates a temporary ASTContext
for parsing the current expression.

The problem with the recursion is however that if we somehow get a cycle into
our mapping, then the ASTImporterDelegate will just infinite recurse. As the
infinite recursion usually happens after the cycle was already created in a code
path such as completing a type, the crash backtraces we get for these bugs are
not very useful. However having the backtrace where the faulty map entry is
created usually makes the code trivial to fix (as there should be some rogue
CopyType call or something similar nearby. See for example D96366).

This patch tries to make these issues easier to track down by putting a bunch of
sanity asserts in the code that fills out the map. All the asserts are just
checking that there is no direct cycle (ASTContext maps to itself) when updating
the origin tracking map.

The assert in the ASTImportDelegate constructor is an `lldbassert` (which also
is getting checked in release builds with disabled asserts) as the code path
there is pretty cold and we can reliably detect a rogue CopyType call from
there.

I also had to update some code in
`ClangASTImporter::ASTImporterDelegate::Imported`. This code already had a
safety check for creating a cycle in the origin tracking map, but it still
constructed an ASTImporter while checking for the cycle (by requesting a
delegate via `GetDelegate` and passing two identical ASTContexts which looks
like a rogue CopyType call to the checks).

Reviewed By: shafik

Differential Revision: https://reviews.llvm.org/D97300
2021-02-24 13:25:49 +01:00
Jorge Gorbe Moya 979ca1c05f Defer the decision whether to use the CU or TU index until after reading the unit header.
In DWARF v4 compile units go in .debug_info and type units go in
.debug_types. However, in v5 both kinds of units are in .debug_info.
Therefore we can't decide whether to use the CU or TU index just by
looking at which section we're reading from. We have to wait until we
have read the unit type from the header.

Differential Revision: https://reviews.llvm.org/D96194
2021-02-23 13:26:11 -08:00
Dave Lee 0ac42fd26d [lldb] Add deref support and tests to shared_ptr synthetic
Add `frame variable` dereference suppport to libc++ `std::shared_ptr`.

This change allows for commands like `v *thing_sp` and `v thing_sp->m_id`. These
commands now work the same way they do with raw pointers. This is done by adding an
unaccounted for child member named `$$dereference$$`.

Also, add API tests for `std::shared_ptr`, previously there were none.

Differential Revision: https://reviews.llvm.org/D97165
2021-02-23 09:03:46 -08:00
Michał Górny 6c06b0aa5a [lldb] [test] Un-XFAIL TestBuiltinTrap on FreeBSD/aarch64 2021-02-23 14:35:34 +01:00
Michał Górny 2f75363a9e [lldb] [test] Un-XFAIL a test that no longer fail on FreeBSD 2021-02-23 14:35:34 +01:00
Raphael Isemann bea2d5e478 [lldb][NFC] Remove unused ValueObject::LogValueObject functions
Those functions aren't called anywhere. For debugging purposes we usually
have Dump() methods (which already exist in some semi-functional form in
ValueObject).
2021-02-23 12:10:40 +01:00
Raphael Isemann bda83ba0d2 [lldb][NFC] Clean up ValueObject comments
* Remove commented out code.
* Doxygenify comments that serve as documentation.
* Use the LLVM comment style where possible.
2021-02-23 12:02:36 +01:00
Raphael Isemann 03310c1e95 [lldb][NFC] Give CompilerType's IsArrayType/IsVectorType/IsBlockPointerType out-parameters default values
We already do this for most functions that have out-parameters, so let's do
the same here and avoid all the `nullptr, nullptr, nullptr` in every call.
2021-02-23 11:15:31 +01:00
Raphael Isemann d77e3c6aec [lldb][NFC] Don't inherit from UserID in ValueObject
ValueObject inherits from UserID which is just a bad idea:

* The inheritance gives ValueObject some member functions that are at best
  misleading (such as `Clear()` which doesn't clear any value beside `id`).

* It allows passing ValueObject to the overloaded operators for UserID (such as
  `==` or `<<` which won't actually compare or print anything in the ValueObject).

* It exposes the `SetID` and `Clear` which both allow users to change the
  internal id value.

Similar to D91699 which did the same for Process

Reviewed By: #lldb, JDevlieghere

Differential Revision: https://reviews.llvm.org/D97205
2021-02-23 10:15:42 +01:00
Raphael Isemann 8f63cf5da3 [lldb][NFC] Cleanup ValueObject construction code
Just code cleanup for ValueObject constructors:

* Use default member initializers where possible.
* Doxygenify the comments for membersa nd constructors where needed.
* Delete the default constructor which isn't defined.
* Initialize the bitfields via a utility struct instead of doing this in the
  different constructors.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D97199
2021-02-23 09:39:18 +01:00
Richard Howell 389955c69a [lldb] add check for libcxx runtime
When enabling LLDB tests with `LLVM_ENABLE_RUNTIMES=libcxx` CMake will
fail with:

```
LLDB test suite requires libc++, but it is currently disabled.
```

The issue is that the targets in LLVM_ENABLE_RUNTIMES are configured
after the targets in LLVM_ENABLE_PROJECTS, so at this point the check
for the `cxx` target will fail. CMake will add a dependency for a target
that does not exist yet however, so by first checking for `libcxx` in
LLVM_ENABLE_RUNTIMES we ensure that the `cxx` target will be present at
build time.

Tested with:
```
% cmake -G Ninja \
    -C ~/local/llvm-project/lldb/cmake/caches/Apple-lldb-macOS.cmake \
    -DLLVM_ENABLE_PROJECTS="clang;lldb" -DLLVM_ENABLE_RUNTIMES="libcxx" \
    -DLIBCXX_INCLUDE_TESTS=NO ~/local/llvm-project/llvm
% ninja check-lldb
```

Reviewed By: smeenai, JDevlieghere

Differential Revision: https://reviews.llvm.org/D97227
2021-02-22 17:53:54 -08:00
Jonas Devlieghere 5d2850161e [lldb] Reinstate support for LLDB_VERSION_STRING
Reinstate support for specifying -DLLDB_VERSION_STRING="best-lldb"
which seems to have gotten accidentally removed in the past.

rdar://38983903

Differential revision: https://reviews.llvm.org/D97235
2021-02-22 16:56:00 -08:00
Shafik Yaghmour 50542d504d Modify TypePrinter to differentiate between anonymous struct and unnamed struct
Currently TypePrinter lumps anonymous classes and unnamed classes in one group "anonymous" this is not correct and can be confusing in some contexts.

Differential Revision: https://reviews.llvm.org/D96807
2021-02-22 14:16:43 -08:00
António Afonso 878d82c4f2 Revert "[lldb-vscode] Emit the breakpoint changed event on location resolved"
This reverts commit 1f21d488bd.
2021-02-21 13:08:06 -08:00
Michał Górny 7850bb5f2a [lldb] [docs] Update platform support status
Update supported features on FreeBSD, and supported platform list
on FreeBSD, Linux and NetBSD.

Differential Revision: https://reviews.llvm.org/D97114
2021-02-21 21:47:48 +01:00
Martin Storsjö ae14f3fdbf [LLDB] [docs] Update the list of supported architectures on Windows
Differential Revision: https://reviews.llvm.org/D96840
2021-02-21 22:23:55 +02:00
Pavel Labath 3ca7b2d03c Reapply "[lldb/test] Automatically find debug servers to test"
This reapplies 7df4eaaa93/D96202, which was reverted due to issues on
windows. These were caused by problems in the computation of the liblldb
directory, which was fixed by D96779.

The original commit message was:
Our test configuration logic assumes that the tests can be run either
with debugserver or with lldb-server. This is not entirely correct,
since lldb server has two "personalities" (platform server and debug
server) and debugserver is only a replacement for the latter.

A consequence of this is that it's not possible to test the platform
behavior of lldb-server on macos, as it is not possible to get a hold of
the lldb-server binary.

One solution to that would be to duplicate the server configuration
logic to be able to specify both executables. However, that seems
excessively redundant.

A well-behaved lldb should be able to find the debug server on its own,
and testing lldb with a different (lldb-|debug)server does not seem very
useful (even in the out-of-tree debugserver setup, we copy the server
into the build tree to make it appear "real").

Therefore, this patch deletes the configuration altogether and changes
the low-level server retrieval functions to be able to both lldb-server
and debugserver paths. They do this by consulting the "support
executable" directory of the lldb under test.

Differential Revision: https://reviews.llvm.org/D96202
2021-02-21 20:47:47 +01:00
António Afonso b19d3b092d Revert "Make sure the interpreter module was loaded before making checks against it"
This reverts commit a83a825e99.
2021-02-21 10:38:25 -08:00
António Afonso 1f21d488bd [lldb-vscode] Emit the breakpoint changed event on location resolved
VSCode was not being informed whenever a location had been resolved (after being initated as non-resolved), so even though it was actually resolved, the IDE would show a hollow dot (instead of a red dot) because it didn't know about the change.

Differential Revision: https://reviews.llvm.org/D96680
2021-02-21 09:46:29 -08:00
António Afonso a83a825e99 Make sure the interpreter module was loaded before making checks against it
This issue was introduced in https://reviews.llvm.org/D92187.
The guard I'm changing were is supposed to act when linux is loading the linker for the second time (due to differences in paths like symlinks).
This is done by checking `module_sp != m_interpreter_module.lock()` however this will be true when `m_interpreter_module` wasn't initialized, making linux unload the linker module (the most visible result here is that lldb will stop getting notified about new modules loaded by the process, because it can't set the rendezvous breakpoint again after the stepping over it once).
The `m_interpreter_module` is not getting initialize when it goes through this path: dbfdb139f7/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp (L332), which happens when lldb was able to read the address from the dynamic section of the executable.

What I'm not sure about though, is if when we go through this path if we still load the linker twice on linux. If that's the case then it means we need to somehow set the m_interpreter_module instead of the fix I provide here. I've only tested this on Android.

Differential Revision: https://reviews.llvm.org/D96637
2021-02-21 09:28:04 -08:00
Dave Lee b0186c25c6 [lldb] Refine ThreadPlan::ShouldAutoContinue
Adjust `ShouldAutoContinue` to be available to any thread plan previous to the plan that
explains a stop, not limited to the parent to the plan that explains the stop.

Before this change, `Thread::ShouldStop` did the following:

1. find the plan that explains the stop
2. if it's not a master plan, continue processing previous (aka parent) plans
3. first, call `ShouldAutoContinue` on the immediate parent of the explaining plan
4. then loop over previous plans, calling `ShouldStop` and `MischiefManaged`

Of note, the iteration in step 4 does not call `ShouldAutoContinue`, so again only the
plan just prior to the explaining plan is given the opportunity to override whether to
continue or stop.

This commit changes the loop call `ShouldAutoContinue`, giving each plan the opportunity
to override `ShouldStop` of previous plans.

Why? This allows a plan to do the following:

1. mark itself done and be popped off the stack
2. allow parent plans to finish their work, and to also be popped off the stack
3. and finally, have the thread continue, not stop

This is useful for stepping into async functions. A plan will would step far enough
enough to set a breakpoint on the async target, and then use `ShouldAutoContinue` to
unwind the necessary stepping, and then have the calling thread continue.

Differential Revision: https://reviews.llvm.org/D97076
2021-02-20 17:25:31 -08:00
Dave Lee 9d3b9e5799 [lldb] Rename {stop,run}_vote to report_{stop,run}_vote
Rename `stop_vote` and `run_vote` to `report_stop_vote` and `report_run_vote`
respectively. These variables are limited to logic involving (event) reporting only.
This naming is intended to make their context more clear.

Differential Revision: https://reviews.llvm.org/D96917
2021-02-19 13:04:53 -08:00
Jan Kratochvil 08331281af [lldb/Commands] Fix help text typo for 'breakpoint set' -a|--address. 2021-02-19 14:33:42 +01:00
Jason Molenda d82ecb0ac7 LanguageRuntime can provide an UnwindPlan for special occasions
Add a facility in the LanguageRuntime to provide a special
UnwindPlan based on the register values in a RegisterContext,
instead of using the return-pc to find a function and use its
normal UnwindPlans.

Needed when the runtime has special stack frames that we want
to show the user, but aren't actually on the real stack.
Specifically for Swift asynchronous functions.

With feedback from Greg Clayton, Jonas Devlieghere, Dave Lee

<rdar://problem/70398009>

Differential Revision: https://reviews.llvm.org/D96839
2021-02-18 23:23:15 -08:00
Shafik Yaghmour 9068dab1fd Revert "Modify TypePrinter to differentiate between anonymous struct and unnamed struct"
I missed clangd test suite and may need some time to get those working, so reverting for now.

This reverts commit ecb90b5545.
2021-02-18 18:17:24 -08:00
Shafik Yaghmour 080ba851c6 Revert "Fix for Modify TypePrinter to differentiate between anonymous struct and unnamed struct"
I missed clangd test suite and may need some time to get those working, so reverting for now.

This reverts commit 1e08193956.
2021-02-18 18:17:24 -08:00
Shafik Yaghmour 1e08193956 Fix for Modify TypePrinter to differentiate between anonymous struct and unnamed struct
One of the lldb tests needed additional fixes.
2021-02-18 17:57:40 -08:00
Shafik Yaghmour ecb90b5545 Modify TypePrinter to differentiate between anonymous struct and unnamed struct
Currently TypePrinter lumps anonymous classes and unnamed classes in one group "anonymous" this is not correct and can be confusing in some contexts.

Differential Revision: https://reviews.llvm.org/D96807
2021-02-18 17:44:45 -08:00
Jonas Devlieghere 31fa76fd24 [lldb] Check that files exists before handing them off to FileCollector
The FileCollector asserts that paths passed to addDirectory are indeed
directories. For that to work, the file needs to actually exist. In the
downstream Swift fork we have tests that remove files during testing,
which resulted in this assertion getting triggered.
2021-02-18 16:16:15 -08:00
Jonas Devlieghere 612384f6e0 [lldb] Remove unused code in ScriptInterpreterPython
Remove the unused code I noticed when working on d6e80578fc and do
some other minor cleanups in the vicinity.
2021-02-18 10:38:54 -08:00
Pavel Labath 1b8d2ec071 [lldb] Un-XFAIL TestFormatters on windows
The test passes after D96779.
2021-02-18 18:47:20 +01:00
Pavel Labath 004a264f8c [lldb] Fix shared library directory computation on windows
Our code for locating the shared library directory works via dladdr (or
the windows equivalent) to locate the path of an address known to reside
in liblldb. This works great for C++ programs, but there's a catch.

When (lib)lldb is used from python (like in our test suite), this dladdr
call will return a path to the _lldb.so (or such) file in the python
directory. To compensate for this, we have code which attempts to
resolve this symlink, to ensure we get the canonical location. However,
here's the second catch.

On windows, this file is not a symlink (but a copy), so this logic
fails. Since most of our other paths are derived from the liblldb
location, all of these paths will be wrong, when running the test suite.
One effect of this was the failure to find lldb-server in D96202.

To fix this issue, I add some windows-specific code to locate the
liblldb directory. Since it cannot rely on symlinks, it works by
manually walking the directory tree -- essentially doing the opposite of
what we do when computing the python directory.

To avoid python leaking back into the host code, I implement this with
the help of a callback which can be passed to HostInfo::Initialize in
order to assist with the directory location. The callback lives inside
the python plugin.

I also strenghten the existing path test to ensure the returned path is
the right one.

Differential Revision: https://reviews.llvm.org/D96779
2021-02-18 15:37:52 +01:00
Raphael Isemann fb1dc77bfd [lldb][NFC] Silence missing case warnings in TypeSystemClang::GetTypeBitAlign due to new RISC-V V types
Those types were added in D92715. This just silences the warning but doesn't
actually add support for those types to LLDB.
2021-02-18 09:03:18 +01:00
Jason Molenda fcdef15d77 Add a new Row setting to mark all un-declared regs as Undefined
Add a new state for UnwindPlan::Row which indicates that any
register not listed is not defined, and should not be found in
stack frames newer than this one and passed up the stack.  Mostly
intended for use with architectural default unwind plans that are
used for jitted stack frames, where we have no unwind information
or start address.  lldb has no way to tell if registers were
spilled in the jitted frame & overwritten, so passing register
values up the stack is not safe to show the user.

Architectural default unwind plans are also used as a fast unwind
plan on x86_64 in particular, and are used as the fallback unwind
plans when lldb thinks it may be able to work around a problem
which causes the unwinder to stop walking the stack early.

For fast unwind plans, when we don't find a register location in
the arch default unwind plan, we fall back to computing & using
the full unwind plan. One small part of this patch is to know that
a register marked as Undefined in the fast unwind plan is a special
case, and we should continue on to the full unwind plan to find what
the real unwind rule is for this register.

Differential Revision: https://reviews.llvm.org/D96829
<rdar://problem/70398009>
2021-02-17 23:52:28 -08:00
Jonas Devlieghere d6e80578fc [lldb] Improve error message for modules with dots or dashes
LLDB does not like to import Python files with dashes or dots in their
name. While the former are technically allowed, it is discouraged. Dots
are allowed for subpackages but not in module names. This patch improves
the user experience by printing a useful error.

Before this patch:

  error: module importing failed: SyntaxError('invalid syntax',
  ('<string>', 1, 11, 'import foo-bar\n'))

After this patch:

  error: module importing failed: Python discourages dashes in module
  names: foo-bar

rdar://74263511

[1] https://www.python.org/dev/peps/pep-0008/#package-and-module-names

Differential revision: https://reviews.llvm.org/D96833
2021-02-17 10:00:29 -08:00
Raphael Isemann 8bcc03767e [lldb][NFC] Delete deleted const char* overloads of SetValueFromString
This came up during the review of D96817 because those deleted overloads force
the caller to explicitly create a StringRef when passing a string literal.

It seems they were added as some kind of help while migrating the code base to
StringRef in D24847, but I don't think they have any use these days and make
these functions awkward to use.

This patch just removes all the deleted overloads.

Reviewed By: tatyana-krasnukha

Differential Revision: https://reviews.llvm.org/D96861
2021-02-17 16:13:20 +01:00
Michał Górny 9f38001bf0 [lldb] [Process/FreeBSD] Ensure that errors are always handled
Ensure that the llvm::Error instances are always considered handled
by replacing LLDB_LOG with LLDB_LOG_ERROR.

Differential Revision: https://reviews.llvm.org/D96558
2021-02-16 22:21:37 +01:00
Pavel Labath 901ea29662 [lldb] Delete superfluous semicolon 2021-02-16 21:07:58 +01:00
Pavel Labath 1db2888e70 [lldb] Remove some nanosleep preprocessor magic
It's obsolete, as we use (portable) std::this_thread::sleep_for now.
2021-02-16 21:07:57 +01:00
Raphael Isemann f88b502d9b [FileCollector] Fix that the file system case-sensitivity check was inverted
real_path returns an `std::error_code` which evaluates to `true` in case an
error happens and `false` if not. This code was checking the inverse, so
case-insensitive file systems ended up being detected as case sensitive.

Tested using an LLDB reproducer test as we anyway need a real file system and
also some matching logic to detect whether the respective file system is
case-sensitive (which the test is doing via some Python checks that we can't
really emulate with the usual FileCheck logic).

Fixes rdar://67003004

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D96795
2021-02-16 20:21:32 +01:00
Pavel Labath 85f025e5b3 [lldb/test] Test lldb-server named pipe functionality on windows
lldb-server can use a named pipe to communicate the port number it is
listening on. This windows bits of this are already implemented, but we
did not have a test for that, most likely because python does not have
native pipe functionality.

This patch implements the windows bits necessary to test this. I'm using
the ctypes package to call the native APIs directly to avoid a
dependency to non-standard python packages. This introduces some amount
of boilerplate, but our named pipe use case is fairly limited, so we
should not end up needing to wrap large chunks of windows APIs.

Surprisingly to changes to lldb-server were needed to make the test
pass.

Differential Revision: https://reviews.llvm.org/D96260
2021-02-16 15:47:39 +01:00
Jonas Devlieghere 71811048c0 [debugserver] Correctly pass argv[0] to execl
The execl function takes both the executable and argv[0].
2021-02-15 18:42:21 -08:00
Dave Lee 4946f37d84 [lldb] Remove very old misleading comment (NFC) 2021-02-15 18:14:57 -08:00
Dave Lee 22f0aa0d9e [lldb] Remove unused ThreadPlan tracer utilities (NFC)
Delete unused `EnableTracer()` and `SetTracer()` functions on `Thread`. By deleting
these, their `ThreadPlan` counterparts also become unused.

Then, by deleting `ThreadPlanStack::EnableTracer`, `EnableSingleStep` becomes unused.
With no more callers to `EnableSingleStep`, the value `m_single_step` is always true and
can be removed as well.

Differential Revision: https://reviews.llvm.org/D96666
2021-02-15 17:59:25 -08:00
Dave Lee 2a2464eb76 [lldb] Lower GetRealStopInfo into ThreadPlanCallFunction (NFC)
`GetRealStopInfo` has only one call site, and in that call site a reference to the
concrete thread plan is available (`ThreadPlanCallUserExpression`), from which
`GetRealStopInfo` can be called.

Differential Revision: https://reviews.llvm.org/D96687
2021-02-15 17:59:24 -08:00
Dave Lee 65d91b40ae [lldb] Minor refinements to ThreadPlan::RestoreThreadState (NFC)
Correct `RestoreThreadState` to a `void` return type. Also, update the signature of its
callee, `Thread::RestoreThreadStateFromCheckpoint`, by updating it to a `void` return
type, and making it non-`virtual`.

Differential Revision: https://reviews.llvm.org/D96688
2021-02-15 17:57:13 -08:00
Muhammad Omair Javaid c2123a82cd [LLDB] Skip TestMultipleTargets.py on Arm/AArch64 Linux
TestMultipleTargets.py fails randomly on Arm/AArch64 Linux buildbot with
no reasonable clues. I am marking it skipped for avoiding LLDB buildbot
failures due to this test.
2021-02-16 01:28:16 +05:00
Michał Górny bee4d6efe1 [lldb] Rename FreeBSDRemote to FreeBSD (NFC)
Differential Revision: https://reviews.llvm.org/D96557
2021-02-15 13:04:11 +01:00
Michał Górny cd44339856 [lldb] Remove the legacy FreeBSD plugin
The new FreeBSDRemote plugin has reached feature parity with the legacy
plugin, so we can finally remove the latter.  The new plugin will
be renamed to FreeBSD in a separate commit to avoid confusion.

Differential Revision: https://reviews.llvm.org/D96555
2021-02-15 13:04:11 +01:00
Michał Górny 011791dda4 [lldb] [Process/FreeBSDRemote] Fix clang-formatting on ppc commit 2021-02-14 22:34:25 +01:00
Fangrui Song 135d07fb0d [lldb][test] Fix Shell/SymbolFile/symbol-binding.test 2021-02-13 11:10:29 -08:00
Benjamin Kramer 2dbe88db58 [lldb] Fix up SysV ABI implementations after 057efa9916 2021-02-13 01:34:00 +01:00
Adrian Prantl 188b0747c1 Support dereferencing a DWARF scalar stack value
Swift async functions receive function arguments inside a
heap-allocated data structure, similar to how ObjC block captures or
C++ coroutine arguments are implement. In DWARF they are described
relative to an entry value that produces a pointer into that heap
object. At typical location looks like

DW_OP_entry_value [ DW_OP_reg14 ] DW_OP_deref DW_OP_plus_uconst 32 DW_OP_deref

This allows the unwinder (which has special ABI knowledge to restore
the contents of r14) to push the base address onto the stack thus
allowing the deref/offset operations to continue. The result of the
entry value is a scalar, because DW_OP_reg14 is a register location —
as it should be since we want to restore the pointer value contained
in r14 at the beginning of the function and not the historical memory
contents it was pointing to. The entry value should restore the
address, which is still valid, not the contents at function entry.

To make this work, we need to allow LLDB to dereference Scalar stack
results like load addresses, which is what this patch
does. Unfortunately it is difficult to test this in isolation, since
the DWARFExpression unit test doesn't have a process.

Differential Revision: https://reviews.llvm.org/D96549
2021-02-12 16:12:32 -08:00
Adrian Prantl 057efa9916 Make the error condition in Value::ValueType explicit (NFC)
The comment for ValueType claims that all values <1 are errors, but
not all switch statements take this into account. This patch
introduces an explicit Error case and deletes all default: cases, so
we get warned about incomplete switch coverage.

https://reviews.llvm.org/D96537
2021-02-12 16:12:31 -08:00
Shafik Yaghmour 9f175998de [LLDB] Fix LLDB_LOG calls to use correct formatting
It looks like a previous change switched these from LLDB_LOGF but did not update the format strings.

Differential Revision: https://reviews.llvm.org/D96550
2021-02-12 11:09:39 -08:00
Raphael Isemann 0c118831a3 [lldb] Let TestPExpectTest test the right test class
This test supposed to check the test base we are using for pexpect tests, but instead it used the normal TestBase
class we use for all other tests. TestBase already had the substrs type check since D88792 so this
test was passing because of that.

This just changes the test base of the test to the pexpect one so that the `expect` calls find their intended
target function. Also moves the check to the very start so that we can check the argument without
actually having to start a terminal and all that jazz.

(I found this by accident as D88792 got somehow reverted in a downstream branch so this test started
failing).

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D96556
2021-02-12 09:56:43 +01:00
Jonas Devlieghere 732534ed64 [lldb] s/TARGET_OS_EMBEDDED/TARGET_OS_IPHONE/
TARGET_OS_EMBEDDED is deprecated, use TARGET_OS_IPHONE and/or
TARGET_OS_SIMULATOR instead.
2021-02-11 20:40:59 -08:00
Jonas Devlieghere 4d3a061c32 [lldb] Fix 'r' and 'run' aliases on Apple Silicon
The 'r' and 'run' aliases were different based on the target
architecture. I suspect the intention was to disable shell expansion on
embedded devices. This fixes TestCustomShell.test on AS.
2021-02-11 20:23:53 -08:00
Peter Collingbourne c314f5ede8 ObjectFileELF: Test whether reloc_header is non-null instead of asserting.
It is possible for the GetSectionHeaderByIndex lookup to fail because
the previous FindSectionContainingFileAddress lookup found a segment
instead of a section. This is possible if the binary does not have
a PLT (which means that lld will in some circumstances set DT_JMPREL
to 0, which is typically an address that is part of the ELF headers
and not in a section) and may also be possible if the section headers
have been stripped. To handle this possibility, replace the assert
with an if.

Differential Revision: https://reviews.llvm.org/D93438
2021-02-11 15:05:18 -08:00
Dave Lee a5ab1dc4ad [lldb] Add step target to ThreadPlanStepInRange constructor
`QueueThreadPlanForStepInRange` accepts a `step_into_target`, but the constructor for
`ThreadPlanStepInRange` does not. Instead, a caller would optionally call
`SetStepInTarget()` in a separate statement.

This change adds `step_into_target` as a constructor argument. This simplifies
construction of `ThreadPlanSP`, by avoiding a subsequent downcast and conditional
assignment. This constructor is already used in downstream repos.

Differential Revision: https://reviews.llvm.org/D96539
2021-02-11 14:57:20 -08:00
Jonas Devlieghere 876e7714dc [lldb] Disable x86-multithread-write.test with reproducers
This test is failing on GreenDragon. Disabling it until I have bandwidth
to investigate why the register values are different during replay.
2021-02-11 13:17:30 -08:00
Pavel Labath 3cad308ce5 Revert "[lldb/test] Automatically find debug servers to test"
The commit 7df4eaaa93 appears to
break the windows bot. Revert while I investigate.
2021-02-11 20:26:05 +01:00
Stella Stamenova ed98676fa4 Support multi-configuration generators correctly in several config files
Multi-configuration generators (such as Visual Studio and Xcode) allow the specification of a build flavor at build time instead of config time, so the lit configuration files need to support that - and they do for the most part. There are several places that had one of two issues (or both!):

1) Paths had %(build_mode)s set up, but then not configured, resulting in values that would not work correctly e.g. D:/llvm-build/%(build_mode)s/bin/dsymutil.exe
2) Paths did not have %(build_mode)s set up, but instead contained $(Configuration) (which is the value for Visual Studio at configuration time, for Xcode they would have had the equivalent) e.g. "D:/llvm-build/$(Configuration)/lib".

This seems to indicate that we still have a lot of fragility in the configurations, but also that a number of these paths are never used (at least on Windows) since the errors appear to have been there a while.

This patch fixes the configurations and it has been tested with Ninja and Visual Studio to generate the correct paths. We should consider removing some of these settings altogether.

Reviewed By: JDevlieghere, mehdi_amini

Differential Revision: https://reviews.llvm.org/D96427
2021-02-11 09:32:20 -08:00
Raphael Isemann 71536fd031 [lldb] Fix that running a top level expression without a process fails with a cryptic error
Right now when running `expr --top-level -- void foo() {}`, LLDB just prints a cryptic
`error: Couldn't find $__lldb_expr() in the module` error. The reason for that is
that if we don't have a running process, we try to set our execution policy to always use the
IR interpreter (ExecutionPolicyNever) which works even without a process. However
that code didn't consider the special ExecutionPolicyTopLevel which we use for
top-level expressions. By changing the execution policy to ExecutionPolicyNever,
LLDB thinks we're actually trying to interpret a normal expression inside our
`$__lldb_expr` function and then fails when looking for it.

This just adds an exception for top-level expressions to that code and a bunch of tests.

Reviewed By: shafik

Differential Revision: https://reviews.llvm.org/D91723
2021-02-11 17:07:11 +01:00
Raphael Isemann 19b4d3ce27 [lldb] Don't emit a warning when using Objective-C getters in expressions
Clang emits a warning when accessing an Objective-C getter but not using the result.
This gets triggered when just trying to print a getter value in the expression parser (where
Clang just sees a normal expression like `obj.getter` while parsing).

This patch just disables the warning in the expression parser (similar to what we do with
the C++ equivalent of just accessing a member variable but not doing anything with it).

Reviewed By: kastiglione

Differential Revision: https://reviews.llvm.org/D94307
2021-02-11 16:48:41 +01:00
Raphael Isemann e87b8e4498 [lldb] Log the actual expression result in UserExpression::Evaluate
This used to be a LLDB_LOGF call that used the printf %s syntax.
0ab109d43d changed it to LLDB_LOG but didn't
update this format string to use formatv's syntax so this just printed '%s'.
2021-02-11 16:15:01 +01:00
Pavel Labath 7df4eaaa93 [lldb/test] Automatically find debug servers to test
Our test configuration logic assumes that the tests can be run either
with debugserver or with lldb-server. This is not entirely correct,
since lldb server has two "personalities" (platform server and debug
server) and debugserver is only a replacement for the latter.

A consequence of this is that it's not possible to test the platform
behavior of lldb-server on macos, as it is not possible to get a hold of
the lldb-server binary.

One solution to that would be to duplicate the server configuration
logic to be able to specify both executables. However, that seems
excessively redundant.

A well-behaved lldb should be able to find the debug server on its own,
and testing lldb with a different (lldb-|debug)server does not seem very
useful (even in the out-of-tree debugserver setup, we copy the server
into the build tree to make it appear "real").

Therefore, this patch deletes the configuration altogether and changes
the low-level server retrieval functions to be able to both lldb-server
and debugserver paths. They do this by consulting the "support
executable" directory of the lldb under test.

Differential Revision: https://reviews.llvm.org/D96202
2021-02-11 14:43:53 +01:00
Adrian Prantl 585e7a359d Diagnose unhandled cases in DW_OP_deref 2021-02-10 17:27:02 -08:00
Dave Lee 309d40f052 [lldb] Use internal_dict name over dict in python examples
Follow up to https://reviews.llvm.org/rG483ec136da7193de781a5284f1c37929cc27c05c
2021-02-10 15:11:00 -08:00
Dave Lee 606c3be85d [lldb] Minor cleanups to ThreadPlan.h (NFC)
While learning about ThreadPlan, I did a bit of cleanup:

* Remove unused code
* Move functions to protected where applicable
* Remove virtual for functions that are not overridden

Differential Revision: https://reviews.llvm.org/D96277
2021-02-10 13:36:38 -08:00
Pavel Labath d77b04e4ed [lldb/test] Move and improve TestPlatformProcessConnect.py
Although it is located under tools/lldb-server, this test is very
different that other lldb-server tests. The most important distinction
is that it does not test lldb-server directly, but rather interacts with
it through the lldb client. It also tests the relevant client
functionality (the platform connect command, which is even admitted in
the test name). The fact that this test is structured as a lldb-server
test means it cannot access most of the goodies available to the
"normal" lldb tests (the runCmd function, which it reimplements; the
run_break_set_by_symbol utility function; etc.).

This patch makes it a full-fledged lldb this, and rewrites the relevant
bits to make use of the standard features. I also move the test into the
"commands" subtree to better reflect its new status.
2021-02-10 21:01:26 +01:00
Jim Ingham 483ec136da Use internal_dict everywhere we refer to the python session dict in docs. 2021-02-09 17:48:47 -08:00
Shafik Yaghmour 4f14c17df7 [LLDB] Remove uneeded CopyType from BlockPointerSyntheticFrontEnd
BlockPointerSyntheticFrontEnd does a CopyType which results in it copying the type
back into its own context. This will result in a call to ASTImporterDelegate::setOrigin
with &decl->getASTContext() == origin.ctx this can result in an infinite recursion
later on in ASTImporter since it will attempt to find the decl in its origin which will be itself.

Differential Revision: https://reviews.llvm.org/D96366
2021-02-09 16:11:28 -08:00
Jim Ingham ffd7be65d0 Remove trailing spaces after \ in comments. 2021-02-09 16:06:47 -08:00
Jim Ingham 365b186c24 Add documentation for the extra_args parameter to breakpoint commands.
Differential Revision: https://reviews.llvm.org/D96368
2021-02-09 15:33:36 -08:00
Michał Górny bd03f6df51 [lldb] [Process/FreeBSDRemote] Introduce powerpc support
Introduce a minimal support for the 32-bit powerpc platform.  This
includes support for GPR and FPR registers.  I also needed to add
software breakpoint opcode for PPC32/PPC64 (big endian), and to fix
offsets in RegisterInfos_powerpc.h (used only by FreeBSD register
context to be globally unique rather than relative to each struct).

Differential Revision: https://reviews.llvm.org/D95947
2021-02-09 21:10:45 +01:00
Dave Lee 2309392449 [lldb] Inline invariant params to AppleThreadPlanStepThrough (NFC)
These two `AppleThreadPlanStepThrough` thread plans have parameterized behavior
that is unutilized. To make their interface and implementation simpler, this
change inlines those outside parameters.

Differential Revision: https://reviews.llvm.org/D96276
2021-02-09 08:03:51 -08:00
Dave Lee 7dc324aafa [lldb] Fix crash in FormatEntity for mangled-name
Check a `Block` pointer before dereferencing.

Using `function.mangled-name` led to a crash for a frame where the symbol
context had no block info. In my case, the frame's function was a system frame.

Differential Revision: https://reviews.llvm.org/D96307
2021-02-08 18:38:08 -08:00
Michał Górny 8244fc505d [lldb] [Process/FreeBSDRemote] Introduce mips64 support
Introduce mips64 support to match the legacy FreeBSD plugin. Similarly
to the legacy plugin, the code does not support FPU registers at the
moment.  The support for them will be submitted separately as it
requires changes to the register context shared by both plugins.

This also includes software single-stepping support that is moved from
the Linux plugin into a common Utility class.  The FreeBSD code also
starts explicitly ignoring EINVAL from PT_CLEARSTEP since this is easier
to implement than checking whether hardware single-stepping were used.

Differential Revision: https://reviews.llvm.org/D95802
2021-02-08 18:27:26 +01:00
Frederik Gossen 5a63045fe7 [LLDB] Fix `Wunused-result` warning 2021-02-08 18:10:08 +01:00
Tatyana Krasnukha 05d7d6949c [lldb/tests] Removed add_test_categories decorator for python API tests, NFC
There is a .categories file in the python_api directory that makes all nested tests
belong to the category "pyapi". The decorator is unnecessary for these tests.
2021-02-08 15:10:48 +03:00
Tatyana Krasnukha f9c5e1664e [lldb/tests] Un-skip TestGuiBasicDebug.py on Arm and AArch64
The test was timing out because of https://reviews.llvm.org/D92164, it should pass now.
2021-02-08 15:09:09 +03:00
Tatyana Krasnukha 36de94cf54 Reland "[lldb] Make CommandInterpreter's execution context the same as debugger's one" 2021-02-08 15:09:09 +03:00
Tatyana Krasnukha a39bcbca92 [lldb] Debugger: reuse ExecutionContextRef to create ExecutionContext from Target
The Debugger didn't take the Process's run lock, that causes deadlocks and races
after applying https://reviews.llvm.org/D92164 revision. Since ExecutionContextRef
does the same job correctly, Debugger::GetSelectedExecutionContext just can use it
to build execution context upon the selected target.
2021-02-08 15:09:08 +03:00
Muhammad Omair Javaid d813c37fc7 [LLDB] Fix buildbot regression in symbol-binding.test
This patch fixes regression in symbol-binding.test due to change in
symbol order.
2021-02-08 15:20:39 +05:00
Muhammad Omair Javaid 8561ad9296 Use remote regnums in expedited list, value regs and invalidate regs
Native register descriptions in LLDB specify lldb register numbers in
value_regs and invalidate_regs lists. These register numbers may not
match with Process gdb-remote register numbers which are generated by
native process after counting all registers in its register sets.

It was coincidentally not causing any problems as we never came across
a native target with dynamically changing register sets and register
numbers generated by counter matched with LLDB native register numbers.
This came up while testing target AArch64 SVE which can choose register
sets based on underlying hardware.

This patch fixes this behavior and always tries to use remote register
numbers while reading/writing registers over gdb-remote protocol.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D77043
2021-02-08 14:09:15 +05:00
Muhammad Omair Javaid bec6b5e3ce [LLDB] Disable TestExprsChar.py, still fails on Arm/Linux
TestExprsChar.py was enabled on Arm as it passes on apple silicon but
still fails on Arm/Linux.
2021-02-08 14:05:36 +05:00
Djordje Todorovic 9abd8c1a4c [elf-core] Improve reading memory from core file
This patch tries to improve memory-read from core files
(in order to improve disassembly functionality).

I am using RHEL 7.7 (linux kernel 3.10) and for a lot of cases,
I was not able to disassemble some functions from backtrace when
debugging crashes from core files. It outputs some dummy code.

The cause of the problem was the fact we are returning all the zeros
from ProcessElfCore::ReadMemory() that is being called within
Disassembler::ParseInstructions() and it disassembles some dummy
opcodes from the buffer returned. Therefore, we are removing zero
bytes filling (padding) completely.

Differential Revision: https://reviews.llvm.org/D93939
2021-02-08 00:14:32 -08:00
Dave Lee 3cc3762292 [lldb] Use assertIn/NotIn over assertTrue/False (NFC)
For improved failure messages, use `assertIn` over `assertTrue`.

Differential Revision: https://reviews.llvm.org/D96095
2021-02-06 11:52:01 -08:00
Jonas Devlieghere 28c6b1e552 [lldb] Re-enable TestExprsChar on arm64
This test passes on arm64 (Apple Silicon). I assume that "aarch64" still
ensures this gets skipped on Linux. I don't have access to such and
environment so I'll have to rely on the bot complaining.
2021-02-05 15:21:24 -08:00
Jonas Devlieghere ac1242bce3 [debugserver] Fix more warnings in DNBArchImplARM64 2021-02-05 15:21:24 -08:00
Jonas Devlieghere e5228ef556 [lldb] Emit type annotation in SWIG generated Python code.
The Python code generated by SWIG is compatible with both Python 2 and
Python 3. The -py3 option enables Python 2 incompatible features such as
function annotations and abstract base classes.

Differential revision: https://reviews.llvm.org/D96096
2021-02-05 08:51:22 -08:00
Raphael Isemann 6e1afd8587 [lldb][NFC] Minor comment and inlining fixes for Args
The element count getter can just be in the header. Also doxygenify some of the
comments and document m_argv's terminating nullptr element that the other
comments keep mentioning.
2021-02-05 10:17:16 +01:00
Pavel Labath b90c4907ae [lldb/cmake] Reduce duplication in generation lldb-dotest
Use indirection to avoid duplicated long lists of variables.

Depends on D95261.

Differential Revision: https://reviews.llvm.org/D96034
2021-02-05 08:44:10 +01:00
Pavel Labath 98d9f2dcac [lldb/test] Reduce API test tools configuration boilerplate
Replace the dotest command line options and various cmake variables,
which are used for passing the locations of llvm tools to the API tests
with a single variable, which points to the directory these tools are
placed in. Besides reducing repetition, this also makes things more
similar to how "normal" llvm tests are configured.

Differential Revision: https://reviews.llvm.org/D95261
2021-02-05 08:44:08 +01:00
Adrian Prantl 644ef58073 Print the "no plugin" warning only when there is no plugin
... and not when the typesystem failed to initialize.

rdar://72562341

Differential Revision: https://reviews.llvm.org/D95992
2021-02-04 11:06:10 -08:00
Walter Erquinigo 36496cc299 [lldb-vscode] correctly use Windows macros
@mstorsjo found a mistake that I made when trying to fix some Windows
compilation errors encountered by @stella.stamenova.

I was incorrectly using the LLVM_ON_UNIX macro. In any case, proper use
of

  #if defined(_WIN32)

should be the actual fix.

Differential Revision: https://reviews.llvm.org/D96060
2021-02-04 11:03:33 -08:00
Jonas Devlieghere 727bd89b60 [lldb] Simplify the logic to detect compiler flag support
This patch effectively does the following 3 things:

 - Centralize the logic to figure out if a compiler flag is supported.
 - Stop sanity checking whether the compiler works at all. While useful,
   that's not the decorator's responsibility.
 - Invoke the compiler with xcrun on Darwin so we know where to find the
   sysroot.

On my macOS Big Sur system, the clang invocation couldn't find libSystem
and would fail the sanity check in the decorator. This meant that the
test suite would always try to run the ASan/UBSan/TSan tests, regardless
of whether compiler-rt was built.

Differential revision: https://reviews.llvm.org/D95995
2021-02-04 08:52:56 -08:00
Pavel Labath aa56b30014 [lldb] Make TestLocalVariables.py compatible with the new pass manager
The new PM is more aggressive at inlining, which breaks assumptions in
the test => slap some __attribute__((noinlines)) to prevent that.
2021-02-04 11:27:08 +01:00
Dave Lee 0ed758b260 [lldb] Convert more assertTrue to assertEqual (NFC)
Follow up to D95813, this converts multiline assertTrue to assertEqual.

Differential Revision: https://reviews.llvm.org/D95899
2021-02-03 21:15:08 -08:00
Jonas Devlieghere e3bb1c80fe [lldb] Rollback to using i386 for the watch simulator
I switched the watch simulator test from i386 to using x86_64, but
apparently that's not supported on the bots. Rollback to using i386 and
solve the original issue by passing the target, similar to what I did
in TestSimulatorPlatform.py.
2021-02-03 16:32:55 -08:00
Jonas Devlieghere b3901ef09c [lldb] Check for both Lua 5.3 and 5.4 error messages in the tests. 2021-02-03 13:46:00 -08:00
Jonas Devlieghere 98e50a7d4c [lldb] Honor the CPU type & subtype when launching on macOS
Honor the CPU type (and subtype) when launching the inferior on macOS.

Part of this functionality was thought to be no longer needed and
removed in 85bd436961, however it's still
needed, for example to launch binaries under Rosetta 2 on Apple Silicon.

This patch will use posix_spawnattr_setarchpref_np if available and
fallback to posix_spawnattr_setbinpref_np if not.

Differential revision: https://reviews.llvm.org/D95922
2021-02-03 13:42:00 -08:00
Jonas Devlieghere 5580fa10db [lldb] Fix debugserver-entitlements.plist path 2021-02-03 10:42:36 -08:00
Med Ismail Bennani 608ee55a31
[lldb/test] Stop recording fundamental return types (NFC)
It seems that recording fundamental return type is bogus.

This can trigger asserts when running a test with reproducers so this
patch updates the `SBTarget::IsLoaded` test to stop recording them.

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-02-03 02:57:26 +01:00
Dave Lee 619e2e095f [lldb] Convert assertTrue(a == b) to assertEqual(a, b)
Convert `assertTrue(a == b)` to `assertEqual(a, b)` to produce better failure messages.

These were mostly done via regex search & replace, with some manual fixes.

Differential Revision: https://reviews.llvm.org/D95813
2021-02-02 12:39:03 -08:00
Jonas Devlieghere 39047f6c2e [debugserver] Fix -Wmissing-field-initializers warnings on arm64 2021-02-02 10:29:09 -08:00
Jonas Devlieghere ec6815a72d [debugserver] Fix -Wsign-compare warnings on arm64 2021-02-02 10:23:57 -08:00
Jonas Devlieghere 9a62b7242a [debugserver] Fix -Wunused-function warnings on arm64 2021-02-02 10:20:11 -08:00
Jonas Devlieghere 870a58a758 [debugserver] Fix -Winconsistent-missing-override warnings on arm64 2021-02-02 09:41:18 -08:00
Raphael Isemann 0f2be195d5 Revert "[lldb] Use current execution context in SBDebugger"
This reverts commit 754ab803b8.

As pointed out in https://reviews.llvm.org/D95761, this patch could lead to
having the wrong execution context in some situations (thanks Jim!).

D92164 is addressing the same issue and will replace this patch, so I'll
revert this one.
2021-02-02 14:41:48 +01:00
Fangrui Song 45db9d4594 [test] Fix unused FileCheck prefixes in lldb 2021-02-01 21:45:51 -08:00
Nathan Hawes ecb00a7762 [VFS] Add support to RedirectingFileSystem for mapping a virtual directory to one in the external FS.
Previously file entries in the -ivfsoverlay yaml could map to a file in the
external file system, but directories had to list their contents in the form of
other file entries or directories. Allowing directory entries to map to a
directory in the external file system makes it possible to present an external
directory's contents in a different location and (in combination with the
'fallthrough' option) overlay one directory's contents on top of another.

rdar://problem/72485443
Differential Revision: https://reviews.llvm.org/D94844
2021-02-02 14:56:17 +10:00
Jonas Devlieghere fbd5507178 [lldb] Use the host architecture in TestAppleSimulatorOSType.py 2021-02-01 16:18:31 -08:00
Med Ismail Bennani ee562e2315 [lldb/test] Skip `SBTarget::IsLoaded` test on windows (NFC)
This patch skips the test for the SBTarget::IsLoaded method on windows
since the logic is different.

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-02-01 14:09:50 +01:00
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