Commit Graph

27237 Commits

Author SHA1 Message Date
Emmmer d0dcbb9b02 [LLDB][RISCV][NFC] Rewrite instruction in algebraic datatype
The old approach (dedicated ExecXXX for each instruction) is not flexible and results in duplicated code when RVC kicks in.

According to the spec, every compressed instruction can be decoded to a non-compressed one. So we can lower compressed instructions to instructions we already had, which requires a decoupling between the decoder and executor.

This patch:
- use llvm::Optional and its combinators AMAP.
- use template constraints on common instruction.
- make instructions strongly-typed (no uint32_t everywhere bc it is error-prone and burdens the developer when lowering the RVC) with the help of algebraic datatype (std::variant).

Note:
(NFC) because this is more of a refactoring in preparation for RVC.

Reviewed By: DavidSpickett

Differential Revision: https://reviews.llvm.org/D135015
2022-10-05 19:45:28 +08:00
David Spickett a9ffb47345 Fix LLDB build on old Linux kernels (pre-4.1)
These fields are guarded elsewhere, but were missing here.

Reviewed By: wallace

Differential Revision: https://reviews.llvm.org/D133778
2022-10-05 08:00:05 +00:00
David Blaikie 40501f1b41 buildbot-based-debugging a Microsoft lldb test XPASS
Let's see if it's been fixed by my recent ABI fixes...
2022-10-04 21:38:33 +00:00
Jim Ingham 2c43cd883c Turn off the warning that the undefined behavior I am using in
a test generates.  The green dragon bot compiler is treating this
warning as an error for some reason, hopefully this will calm its
worries.
2022-10-04 11:38:32 -07:00
Michael Buch 9abeb0cbd9 [lldb][test] Skip import-std-module/vector tests
These tests have begun failing starting with commit
`69a6417406a1b0316a1fa6aeb63339d0e1d2abbd`, which
added a new `import` to `ASTNodeImporter::VisitTypedefType`.
This trips an assertion in following way:
1. When creating a persistent variable for the result we call `CopyType`
   (in `DeportType`) under a `CompleteTagDeclsScope` (which is supposed to complete all
   decls newly imported in the `CopyType` call).
2. During `CopyType` we call `ASTNodeImporter::VisitTypedefType`
3. This now has a second import call on the desugared type
4. In `ASTImporterDelegate::ImportImpl` we will now try to import a decl
   that we originally got from the `std` module (which means it has no valid origin).
   But since we’re doing this under a CompleteTagDeclsScope, the
   `NewDeclListener::NewDeclImported` adds the decl to the list of decls to
   complete after the `CopyType` call. But this list shouldn’t contain decls
   with invalid origins because we assert this in `~CompleteTagDeclsScope`, which
   is where the tests crash.

We suspect that we previously didn’t see this assert trigger because by the time
we create the result variable we are using an AST whose decls all have
a valid debug-info origin (constructed with the help of the std module).
So we never expected decls from modules to be imported under
`CompleteTagDeclsScope` without a m_sema available (which is the case by
the time we get to `DeportType`). Since there is no `m_sema` available,
`CxxModuleHandler::Import` trivially returns and the decls don’t get added
to the `m_decls_to_ignore` list and count as "newly imported decls".

Skip this test for now until we have a fix or the origin tracking gets
refactored (see https://reviews.llvm.org/D101950).

Differential Revision: https://reviews.llvm.org/D135178
2022-10-04 18:38:47 +01:00
Jim Ingham 852a4bdb25 Change the Sanitizer report breakpoint callbacks to asynchronous.
The synchronous callbacks are not intended to start the target running
during the callback, and doing so is flakey.  This patch converts them
to being regular async callbacks, and adds some testing for sequential
reports that have caused problems in the field.

Differential Revision: https://reviews.llvm.org/D134927
2022-10-03 18:10:28 -07:00
Michał Górny b6c24c1619 [lldb] [gdb-remote] Move ReadPacketWithOutputSupport() to client
Move ReadPacketWithOutputSupport() from GDBRemoteCommunication
to GDBRemoteClientBase.  This function is client-specific and moving
it there simplifies followup patches that split communication into
separate thread.

Sponsored by: The FreeBSD Foundation

Differential Revision: https://reviews.llvm.org/D135028
2022-10-03 18:42:49 +02:00
Dave Lee 557a19ab0f [lldb] Remove scoped timer from high firing and fast running ExtractUnitDIENoDwoIfNeeded
Profiles show that `DWARFUnit::ExtractUnitDIENoDwoIfNeeded` is both high firing (tens of thousands of calls) and fast running (15 µs mean).

Timers like this are noise and load for profiling systems, and can be removed.

rdar://100326595

Differential Revision: https://reviews.llvm.org/D134920
2022-10-01 09:58:40 -07:00
Dave Lee 72a86a9dc4 [lldb] Remove scoped timer from high firing and fast running SymbolFileDWARF::FindFunctions
Profiles show that `SymbolFileDWARF::FindFunctions` is both high firing (many thousands of calls) and fast running (35 µs mean).

Timers like this are noise and load for profiling systems, and can be removed.

rdar://100326595

Differential Revision: https://reviews.llvm.org/D134922
2022-10-01 09:58:03 -07:00
Martin Storsjö e9e3a612ec [lldb] Fix warnings about unused variables when building without asserts. NFC. 2022-10-01 14:27:48 +03:00
Andy Yankovsky fb30324a5d Revert "[lldb] Fix member access in GetExpressionPath"
This reverts commit 14642dc74

Broke the tests on macOS -- https://reviews.llvm.org/D132734#3827245
2022-09-30 15:26:09 +00:00
Nico Weber a314a36aaa [lldb] Fix deprecation warning for using std::iterator
std::iterator was deprecated in C++17.

No behavior change.

Differential Revision: https://reviews.llvm.org/D134844
2022-09-30 10:19:08 -04:00
Jitka Plesnikova f0a25fe0b7 [lldb] Fix 'error: non-const lvalue...' caused by SWIG 4.1.0
Fix the failure caused by change in SwigValueWraper for C++11 and later
for improved move semantics in SWIG commit.

d1055f4b3d
2022-09-30 14:37:29 +02:00
Tonko Sabolčec 14642dc740 [lldb] Fix member access in GetExpressionPath
This change fixes two issues in ValueObject::GetExpressionPath method:

 1. Accessing members of struct references used to produce expression
    paths such as "str.&str.member" (instead of the expected
    "str.member"). This is fixed by assigning the flag tha the child
    value is a dereference when calling Dereference() on references
    and adjusting logic in expression path creation.

 2. If the parent of member access is dereference, the produced
    expression path was "*(ptr).member". This is incorrect, since it
    dereferences the member instead of the pointer. This is fixed by
    wrapping dereference expression into parenthesis, resulting with
    "(*(ptr)).member".

Reviewed By: werat, clayborg

Differential Revision: https://reviews.llvm.org/D132734
2022-09-30 11:25:07 +00:00
Alvin Wong fe17e02695 [lldb][Windows] Always call SetExecutableModule on debugger connected
In `ProcessWindows::OnDebuggerConnected` (triggered from
`CREATE_PROCESS_DEBUG_EVENT`), we should always call
`Target::SetExecutableModule` regardless of whether LLDB has already
preloaded the executable modules. `SetExecutableModule` has the side
effect of clearing the module list of the Target, which help make sure
that module #0 is the executable module and the rest of the modules are
listed according to the DLL load order in the process (technically this
has no real consequences but it seems to make more sense anyway.) It
also fixes an issue where the modules preloaded by LLDB will be
duplicated when the debuggee process actually loads the DLL.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D134636
2022-09-30 13:51:56 +03:00
serge-sans-paille 81fc5f7909 [lldb] Get rid of __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS
C++11 made the use of these macro obsolete, see https://sourceware.org/bugzilla/show_bug.cgi?id=15366

As a side effect this prevents https://github.com/swig/swig/issues/2193.

Differential Revision: https://reviews.llvm.org/D134877
2022-09-30 09:05:17 +02:00
Greg Clayton 4017d86df9 When there are variable errors, display an error in VS Code's local variables view.
After recent diffs that enable variable errors that stop variables from being correctly displayed when debugging, allow users to see these errors in the LOCALS variables in the VS Code UI. We do this by detecting when no variables are available and when there is an error to be displayed, and we add a single variable named "<error>" whose value is a string error that the user can read. This allows the user to be aware of the reason variables are not available and fix the issue. Previously if someone enabled "-gline-tables-only" or was debugging with DWARF in .o files or with .dwo files and those separate object files were missing or they were out of date, the user would see nothing in the variables view. Communicating these errors to the user is essential to a good debugging experience.

Differential Revision: https://reviews.llvm.org/D134333
2022-09-29 10:55:16 -07:00
Greg Clayton b3a0bed5fb [NFC] Add header documentation to the SBError::GetCString() to clarify ownwership of the returned string.
Title says it all!

Differential Revision: https://reviews.llvm.org/D134846
2022-09-29 10:54:31 -07:00
Jason Molenda 34f3e57680 Include <cmath> before using std::pow()
Not sure why this is failing for me to build tonight, but either
something in a header somewhere changed or my tools changed, and
it is failing to compile.
2022-09-28 17:35:35 -07:00
Nico Weber faaff2cdce [lldb] Fix deprecation warnings for hasValue and getValue in mac-only code paths
No behavior change.
2022-09-28 20:12:32 -04:00
Nico Weber dcb94010eb Revert "When there are variable errors, display an error in VS Code's local variables view."
This reverts commit 15f83ab775.
Doesn't build, see https://reviews.llvm.org/D134333#3822313
2022-09-28 20:07:14 -04:00
Greg Clayton 8f8935139a Track which modules have debug info variable errors.
Now that we display an error when users try to get variables, but something in the debug info is preventing variables from showing up, track this with a new bool in each module's statistic information named "debugInfoHadVariableErrors".

This patch modifies the code to track when we have variable errors in a module and adds accessors to get/set this value. This value is used in the module statistics and we added a test to verify this value gets set correctly.

Differential Revision: https://reviews.llvm.org/D134508
2022-09-28 15:39:54 -07:00
Greg Clayton 15f83ab775 When there are variable errors, display an error in VS Code's local variables view.
After recent diffs that enable variable errors that stop variables from being correctly displayed when debugging, allow users to see these errors in the LOCALS variables in the VS Code UI. We do this by detecting when no variables are available and when there is an error to be displayed, and we add a single variable named "<error>" whose value is a string error that the user can read. This allows the user to be aware of the reason variables are not available and fix the issue. Previously if someone enabled "-gline-tables-only" or was debugging with DWARF in .o files or with .dwo files and those separate object files were missing or they were out of date, the user would see nothing in the variables view. Communicating these errors to the user is essential to a good debugging experience.

Differential Revision: https://reviews.llvm.org/D134333
2022-09-28 15:38:02 -07:00
Aaron Ballman c5983963de Speculatively fix the lldb build
This should fix the issues found by:
https://lab.llvm.org/buildbot/#/builders/68/builds/40172
2022-09-28 13:39:48 -04:00
David Spickett 0c1a3da8ea [LLDB] Remove the bool + RegisterInfo& version of GetRegisterInfo
All callers have been converted to the optional version.

Depends on D134540

Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D134541
2022-09-28 12:30:34 +00:00
David Spickett c87f1f5bfb [LLDB][AArch64] Move instruction emulation to optional GetRegisterInfo
Depends on D134539

Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D134540
2022-09-28 12:26:50 +00:00
David Spickett ebe71605fa [LLDB][MIPS] Move instruction emulation to optional GetRegisterInfo
Depends on D134538

Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D134539
2022-09-28 10:59:47 +00:00
David Spickett 0a339b3aeb [LLDB][ARM] Move instruction emulation to optional GetRegisterInfo
Depends on D134537

Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D134538
2022-09-28 10:53:22 +00:00
David Spickett 247714f0a6 [LLDB] Move MIPS64/PPC64 and misc. to optional GetRegisterInfo
Depends on D134536

Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D134537
2022-09-28 10:36:31 +00:00
Alvin Wong 8a67a05e93 [lldb][COFF] Map symbols without base+complex type as 'Data' type
Both LLD and GNU ld write global/static variables to the COFF symbol
table with `IMAGE_SYM_TYPE_NULL` and `IMAGE_SYM_DTYPE_NULL` type. Map
these symbols as 'Data' type in the symtab to allow these symbols to be
used in expressions and printable.

Reviewed By: labath, DavidSpickett

Differential Revision: https://reviews.llvm.org/D134585
2022-09-28 12:57:12 +03:00
Alvin Wong acf7d08119 [lldb][COFF] Add note to forwarder export symbols in symtab
Forwarder exports do not point to a real function or variable. Instead
they point to a string describing which DLL and symbol to forward to.
Any imports which uses them will be redirected by the loader
transparently. These symbols do not have much use in LLDB, but keep them
just in case someone find it useful. Also set a synthesized name with
the forwarder string for informational purpose.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D134518
2022-09-28 12:57:11 +03:00
Alvin Wong 7ebff6ab26 [lldb][COFF] Load absolute symbols from COFF symbol table
Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D134517
2022-09-28 12:57:11 +03:00
Alvin Wong 20c2f94c3c [lldb][COFF] Match symbols from COFF symbol table to export symbols
If a symbol is the same as an export symbol, mark it as 'Additional' to
prevent the duplicated symbol from being repeated in some commands (e.g.
`disas -n func`). If the RVA is the same but exported with a different
name, only synchronize the symbol types.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D134426
2022-09-28 12:57:11 +03:00
Alvin Wong 0870afc68e [lldb][COFF] Improve info of symbols from export table
- Skip dummy/invalid export symbols.
- Make the export ordinal of export symbols visible when dumping the
  symtab.
- Stop setting the 'Debug' flag and set the 'External' flag instead to
  better match the meaning of export symbols.
- Try to guess the type (code vs data) of the symbol from section flags.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D134265
2022-09-28 12:57:10 +03:00
Alvin Wong bf0cda9ed2 [lldb][COFF] Rewrite ParseSymtab to list both export and symbol tables
This reimplements `ObjectFilePECOFF::ParseSymtab` to replace the manual
data extraction with what `COFFObjectFile` already provides. Also use
`SymTab::AddSymbol` instead of resizing the SymTab then assigning each
elements afterwards.

Previously, ParseSymTab loads symbols from both the COFF symbol table
and the export table, but if there are any entries in the export table,
it overwrites all the symbols already loaded from the COFF symbol table.
Due to the change to use AddSymbols, this no longer happens, and so the
SymTab now contains all symbols from both tables as expected.

The export symbols are now ordered by ordinal, instead of by the name
table order.

In its current state, it is possible for symbols in the COFF symbol
table to be duplicated by those in the export table. This behaviour will
be modified in a separate change.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D134196
2022-09-28 12:57:10 +03:00
Jason Molenda 1fee25629d Clear old section-to-addr entry when loading Section at new addr
SectionLoadList has a section-to-address map (m_sect_to_addr) and
an address-to-section map (m_addr_to_sect).  When the load address
of a section is updated, the old entry from m_addr_to_sect would
never be cleared, resulting in incorrect address-to-section address
lookups from that point forward.

Differential Revision: https://reviews.llvm.org/D130534
rdar://97308773
2022-09-27 16:20:26 -07:00
Jorge Gorbe Moya 1f2a21820d [NFCI] Refactor FormatterContainerPair into TieredFormatterContainer.
`FormatterContainerPair` is (as its name indicates) a very thin wrapper
over two formatter containers, one for exact matches and another one for
regex matches. The logic to decide which subcontainer to access is
replicated everywhere `FormatterContainerPair`s are used.

So, for example, when we look for a formatter there's some adhoc code
that does a lookup in the exact match formatter container, and if it
fails it does a lookup in the regex match formatter container. The same
logic is then copied and pasted for summaries, filters, and synthetic
child providers.

This change introduces a new `TieredFormatterContainer` that has two
main characteristics:

- It generalizes `FormatterContainerPair` from 2 to any number of
  subcontainers, that are looked up in priority order.
- It centralizes all the logic to choose which subcontainer to use for
  lookups, add/delete, and indexing.

This allows us to have a single copy of the same logic, templatized for
each kind of formatter. It also simplifies the upcoming addition of a
new tier of callback-based matches. See
https://discourse.llvm.org/t/rfc-python-callback-for-data-formatters-type-matching/64204
for more details about this.

The rest of the change is mostly replacing copy-pasted code with calls
to methods of the relevant `TieredFormatterContainer`, and adding some
methods to the `TypeCategoryImpl` class so we can remove some of this
copy-pasted code from `SBTypeCategory`.

Differential Revision: https://reviews.llvm.org/D133910
2022-09-27 14:28:41 -07:00
Jim Ingham 670cac7280 Rename a duplicate test, also give the test class a useful name. 2022-09-27 12:38:22 -07:00
Zequan Wu d434f43720 [LLDB][NativePDB] Add class/union layout bit size.
Missing it causes lldb to crash or give incorrect result.

Differential Revision: https://reviews.llvm.org/D134656
2022-09-27 11:41:55 -07:00
Zequan Wu a3e60044d7 [LLDB][NativePDB] Let native pdb use class layout in debug info.
Before, class layout in native pdb is not hooked up in [[https://github.com/llvm/llvm-project/blob/main/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp#L9375-L9380 | here]].
This changes hooked it up by refactoring SymbolFileNativePDB and PdbAstBuilder.
PdbIndex (corresponds to a single pdb file) is removed from PdbAstBuilder, so it
can only be accessed via SymbolFileNativePDB and we can construct PdbAstBuilder
with just TypeSystemClang.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D134509
2022-09-27 11:01:32 -07:00
Michael Buch 60eb06be6d [lldb][TypeSystemClang] Honor DW_AT_rvalue_reference when creating C++ FunctionPrototypes
Currently funciton lookup in the expression evaluator
fails to disambiguate member functions the are overloaded
on lvalue/rvalue reference-qualifiers. This happens because
we unconditionally set a `FunctionPrototype`s
`ExtProtoInfo::RefQualifier` to `RQ_None`. We lose
the ref-qualifiers in the synthesized AST and `clang::Sema`
fails to pick a correct overload candidate.

DWARF emits information about a function's ref-qualifiers
in the form of a boolean `DW_AT_rvalue_reference` (for rvalues)
and `DW_AT_reference` (for lvalues).

This patch sets the `FunctionPrototype::ExtProtoInfo::RefQualifier`
based on the DWARF attributes above.

**Testing**

* Added API test

llvm/llvm-project issue #57866

Differential Revision: https://reviews.llvm.org/D134661
2022-09-27 18:03:23 +01:00
Michael Buch 7ccfaecba6 [lldb][test] Remove failing ValueCheck on deprecated libcxx entity
A recent libcxx change renamed all internal variables starting with
`__`. As such, `std::reverse_iterator::__t` was renamed to
`std::reverse_iterator::__t_`. This breaks the `import-std-module`
tests with newer libcxx versions. Since this variable is deprecated
in libcxx anyway, this patch simply removes the explicit `ValueCheck`
on the variable name. We don't lose any interesting test-case here
since the purpose of the test is to see if we can call functions
from the `std` module.

We can now re-enable the tests on Darwin for all buildbot Clang
compiler variants.

Differential Revision: https://reviews.llvm.org/D134727
2022-09-27 14:11:02 +01:00
Michael Buch c97e5adbf7 [lldb][test] Disable TestSBValueUnsignedEnumBitField.py for old DWARF versions
With older DWARF versions we don't encode the enum's underlying
type in DWARF. In those cases LLDB sign-extends the bitfield as
a signed integer. Without the actual enum type being present in
DWARF there's not much we can do.

Differential Revision: https://reviews.llvm.org/D134734
2022-09-27 14:09:12 +01:00
Alvin Wong f4991bfa89 [lldb] Improve display of absolute symbol lookup
When running `target module lookup` command, show the name of absolute
symbols. Also fix indentation issue after printing an absolute symbol.

Reviewed By: clayborg, DavidSpickett

Differential Revision: https://reviews.llvm.org/D134516
2022-09-27 13:09:59 +03:00
Alvin Wong a426753ef0 [lldb] Add newline in output of `target modules lookup`
This adds a line break between each result address in the output of the
lldb command `target modules lookup`. Before this change, a new address
result will be printed on the same line as the summary of the last
result, making the output difficult to view.

Also adds a test for this command.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D134111
2022-09-27 13:09:45 +03:00
Adrian Prantl 79e522fb44 Revert "Skip crashing test"
This reverts commit c1ce19021da0cf1c88722024e6ff9cee7aabc7b6.
2022-09-26 17:17:47 -07:00
Michael Buch 1c6826e8fc [lldb][test] 2 - Add gmodules test category explicitly where previously done implicitly
Since we don't compile with `gmodules` implicitly via
debug-info test replication, we should mark all implicit
`gmodules` tests with the appropriate category so the API
tests get actually run as intended.

Differential Revision: https://reviews.llvm.org/D134574
2022-09-26 19:54:24 +01:00
Michael Buch 12502ee551 [lldb][test] 1 - Don't do test-replication for gmodules debug_info variant
Currently, by default LLDB runs an API test with 3 variants,
one of which, depending on platform, is `gmodules`. However,
most tests don't actually make use of any specific `gmodules`
feature since they compile a single `main.cpp` file without
imporint types from other modules.

Instead of running all tests an extra time with `-gmodules`
enabled, we plan to test `gmodules` features with dedicated
API tests that explicitly opt-into compiling with `-gmodules`.
One of the main benefits of this will be a reduction in total
API test-suite run-time (by around 1/3).

This patch adds a flag to `debug_info_categories` that indicates
whether a category is eligible to be replicated by `lldbtest`.

Keeping `gmodules` a debug-info category is desirable because
`builder.py` knows how to inject the appropriate Makefile flags
into the build command for debug-info categories already. Whereas
for non-debug-info categories we'd have to teach it how to. The
category is inferred from the test-name debug-info suffix currently.

Differential Revision: https://reviews.llvm.org/D134524
2022-09-26 19:54:24 +01:00
Dave Lee c418f00536 [lldb] Fix completion of 'settings set' values
Some time ago, a refactor (1153dc960) broke completion for assigning settings
values (`settings set`). This was most annoying for enum settings, where you'd
have to get the valid enum names separately.

This restores the logic in the post-refactor completion function, as well as
adding a test to catch future regressions.

Differential Revision: https://reviews.llvm.org/D134515
2022-09-26 11:26:13 -07:00
Felipe de Azevedo Piovezan 10a35632d5 [lldb] Skip tests incompatible with older versions of Clang
The coroutine tests require a standard library implementation of
coroutines, which was only made available some time _after_ Clang 13.
The first such Clang tested by the LLDB matrix bot is 15.0.1

The TestObjCExceptions test forces the use of the system's libcxx. For
the lldb matrix bot, the first Clang version compatible with the bot's
libraries is 13.0.

Differential Revision: https://reviews.llvm.org/D134645
2022-09-26 13:27:51 -04:00