Commit Graph

28817 Commits

Author SHA1 Message Date
Walter Erquinigo
cf5d8def5c [lldb-vscode] Show a fake child with the raw value of synthetic types (#65552)
Currently, if the user wants to inspect the raw version of a synthetic
variable, they have to go to the debug console and type `frame var
<variable>`, which is not a great experience. Taking inspiration from
CodeLLDB, this adds a `[raw]` child to every synthetic variable so that
this kind of inspection can be done visually.

Some examples:

<img width="500" alt="Screenshot 2023-09-06 at 7 56 25 PM"
src="https://github.com/llvm/llvm-project/assets/1613874/7fefb7c5-0da7-49c7-968b-78ac88348fea">
<img width="479" alt="Screenshot 2023-09-06 at 6 58 25 PM"
src="https://github.com/llvm/llvm-project/assets/1613874/6e650567-16e1-462f-9bf5-4a3a605cf6fc">
2023-09-06 20:13:48 -04:00
Walter Erquinigo
01c0a6a0a4 [lldb-vscode] Fix a GetChildAtIndex call (#65537)
We were invoking GetChildAtIndex(0) without checking the number of
children.
This was not crashing but was showing some warnings in python
formatters.
2023-09-06 17:49:12 -04:00
Walter Erquinigo
89a81ec205 [lldb-vscode] Display a more descriptive summary for containers and pointers (#65514)
We've been displaying types and addresses for containers, but that's not
very useful information. A better approach is to compose the summary of
containers with the summary of a few of its children.

Not only that, we can dereference simple pointers and references to get
the summary of the pointer variable, which is also better than just
showing an anddress.

And in the rare case where the user wants to inspect the raw address,
they can always use the debug console for that.

For the record, this is very similar to what the CodeLLDB extension
does, and it seems to give a better experience.

An example of the new output:
<img width="494" alt="Screenshot 2023-09-06 at 2 24 27 PM"
src="https://github.com/llvm/llvm-project/assets/1613874/588659b8-421a-4865-8d67-ce4b6182c4f9">

And this is the 
<img width="476" alt="Screenshot 2023-09-06 at 2 46 30 PM"
src="https://github.com/llvm/llvm-project/assets/1613874/5768a52e-a773-449d-9aab-1b2fb2a98035">
old output:
2023-09-06 17:13:27 -04:00
Daniel Paoliello
a8138c3d2f [lldb] Fix inline_sites.test
Fixes `lldb/test/Shell/SymbolFile/NativePDB/inline_sites.test` to use the correct line number now that f2f36c9b29 is causing the inline call site info to be taken into account.
2023-09-06 11:20:39 -07:00
David Spickett
ad2453a2db [lldb][Docs] Add page about debugging lldb itself (#65332)
We have docs about how to use lldb on other programs, this tells you how
to use lldb on ldlb and lldb-server.

Lacking any Mac experience I've not included any debugserver information
apart from stating it will be similar but not the same.

I plan for this page to include sections on debugging tests and other
things but this initial commit is purely about the two main binaries
involved.
2023-09-06 16:22:28 +01:00
Muhammad Omair Javaid
e82191469e [LLDB] Skip TestBSDArchives.py on windows
This fixes LLDB windows buildbot after updates to TestBSDArchives.py.
https://lab.llvm.org/buildbot/#/builders/219/builds/5408
I have marked new failing test as an expected failure on Windows.
2023-09-06 14:03:21 +05:00
David Spickett
6c3232b515 [lldb][Docs] Add simpler "automatic" cross-compile option to build docs (#65311)
The main way I cross build lldb is to point CMake at an existing host
build to get the native tablegen tools. This is what we had documented
before.

There is another option where you start from scratch and the host tools
are built for you. This patch documents that and explains which one to
choose.

Added another arm64 example which uses this. So the frst one is the
"automatic" build and the second is the traditional approach.

For ease of copy paste and understanding, I've kept the full command in
each section and noted the one difference between them.

Along the way I updated some of the preamble to explain the two
approaches and updated some language e.g. removing "just ...". Eveyone's
"just" is different, doubly so when cross-compiling.
2023-09-06 08:48:19 +01:00
Greg Clayton
d4a141ef93 Switch over to using the LLVM archive parser for BSD archives.
Our LLDB parser didn't correctly handle archives of all flavors on different systems, it currently only correctly handled BSD archives, normal and thin, on macOS, but I noticed that it was getting incorrect information when decoding a variety of archives on linux. There were subtle changes to how names were encoded that we didn't handle correctly and we also didn't set the result of GetObjectSize() correctly as there was some bad math. This didn't matter when exracting .o files from .a files for LLDB because the size was always way too big, but it was big enough to at least read enough bytes for each object within the archive.

This patch does the following:
- switch over to use LLVM's archive parser and avoids previous code duplication
- remove values from ObjectContainerBSDArchive::Object that we don't use like:
  - uid
  - gid
  - mode
- fix ths ObjectContainerBSDArchive::Object::file_size value to be correct
- adds tests to test that we get the correct module specifications

Differential Revision: https://reviews.llvm.org/D159408
2023-09-05 16:54:05 -07:00
Alex Langford
5bff905c0d [lldb][NFCI] Remove unused method TypeCategoryMap::Get(uint32_t, ValueSP &)
Differential Revision: https://reviews.llvm.org/D159387
2023-09-05 10:53:56 -07:00
Antonio Frighetto
be0e42c16b [lldb][Plugins] Reflect structure changes in ObjectContainer
Reflect recent changes made to MachO
`fileset_entry_command` struct.
2023-09-05 19:13:43 +02:00
Adrian Prantl
d227c8a120 Add missing nullptr check.
While it's the plugin's moral duty to also set the error, this code
can't depend on that.
2023-09-05 09:48:06 -07:00
David Spickett
f6b6234d14 [lldb][AArch64] Remove bool return from UpdateARM64SVERegistersInfos
This always succeeds. While I'm here, document why we check the size
of p0 against the value of VG.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D157845
2023-09-05 10:03:50 +01:00
Kazu Hirata
5dd9568717 Fix typos in documentation 2023-09-02 09:32:48 -07:00
Fangrui Song
678e3ee123 [lldb] Fix duplicate word typos; NFC
Those fixes were taken from https://reviews.llvm.org/D137338
2023-09-01 21:32:24 -07:00
walter erquinigo
2f9cd6377f [LLDB] Fix IOHandlerEditline::GetCurrentLines()
This method was working as expected if LLDB_ENABLE_LIBEDIT is false, however, if it was true, then the variable m_current_lines_ptr was always pointing to an empty list, because Editline only updates its contents once the full input has been completed (see https://github.com/llvm/llvm-project/blob/main/lldb/source/Host/common/Editline.cpp#L1576).

A simple fix is to invoke Editline::GetInputAsStringList() from GetCurrentLines(), which is already used in many places as the common way to get the full input list.
2023-09-01 20:52:00 -04:00
Jonas Devlieghere
a69f78b080 [lldb] Add syntax color highlighting for disassembly
Add support for syntax color highlighting disassembly in LLDB. This
patch relies on 77d1032516, which introduces support for syntax
highlighting in MC.

Currently only AArch64 and X86 have color support, but other interested
backends can adopt WithColor in their respective MCInstPrinter.

Differential revision: https://reviews.llvm.org/D159164
2023-09-01 14:47:45 -07:00
David Spickett
4d1cf5403f [lldb] Fix build with MSVC by using LLVM_PRETTY_FUNCTION
Fixes #65157

07c215e8a8 added some extra logging
which compiles ok with clang but not msvc. Use LLVM_PRETTY_FUNCTION
to fix that.

Fix suggested by Carlos Alberto Enciso.
2023-09-01 07:40:35 +00:00
Venkata Ramanaiah Nalamothu
dfa8a15d78 [lldb][NFC] Put disassembler test classes and methods in anonymous namespace
Reviewed By: DavidSpickett, MaskRay

Differential Revision: https://reviews.llvm.org/D158971
2023-09-01 11:49:54 +05:30
Alex Langford
764287f1ad [lldb] Add support for recognizing swift ast sections in object files
In Apple's downstream fork, there is support for understanding the swift
AST sections in various binaries. Even though the lldb on llvm.org does
not have support for debugging swift, I think it makes sense to move
support for recognizing swift ast sections upstream.

Differential Revision: https://reviews.llvm.org/D159142
2023-08-31 15:16:12 -07:00
Med Ismail Bennani
c9ecaf32f6 [lldb] Fix test failure for breakpoint_function_callback.test
This should fix the test failure in breakpoint_function_callback.test
since SBStructuredData can now display the content of SBStructuredData.

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-08-31 22:19:02 +01:00
Med Ismail Bennani
6813ef3737 Re-land "[lldb/docs] Silence warnings when generating website"
This patch re-lands f0731d5b61 with more fixes and improvements.

First, this patch removes `__eq__` implementations from classes that
didn't implemented `operator!=` on the C++ implementation.

This patch removes sphinx document generation for special members such
as `__len__`, since there is no straightforward way to skip class that
don't implement them. We also don't want to introduce a change in
behavior by implementing artifical special members for classes that are
missing them.

Finally, this patch improve the ergonomics of some classes by
implementing special members where it makes sense, i.e. `hex(SBFrame)`
is equivalent to `SBFrame.GetPC()`.

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

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-08-31 20:35:10 +01:00
Alex Langford
14d95b26ae [lldb][NFCI] Remove unneeded ConstString conversions
ConstString can be implicitly converted into a llvm::StringRef. This is
very useful in many places, but it also hides places where we are
creating a ConstString only to use it as a StringRef for the entire
lifespan of the ConstString object.

I locally removed the implicit conversion and found some of the places we
were doing this.

Differential Revision: https://reviews.llvm.org/D159237
2023-08-31 11:27:59 -07:00
Alex Langford
9ed72d4d4d [lldb][NFCI] Replace bespoke iterator check with std::next
The primary goal of this change is to change `if (pair != *(--m_dict.end()))`
to `if (std::next(iter) != m_dict.end())`. I was experimenting with
changing the underlying type of `m_dict` and found that this was an
issue. Specifically, it assumes that m_dict iterators are bidirectional.
This change should make it so we only need to assume m_dict iterators can move
forward.

Differential Revision: https://reviews.llvm.org/D159150
2023-08-31 10:55:00 -07:00
Greg Clayton
07c215e8a8 Fix shared library loading when users define duplicate _r_debug structure.
We ran into a case where shared libraries would fail to load in some processes on linux. The issue turned out to be if the main executable or a shared library defined a symbol named "_r_debug", then it would cause problems once the executable that contained it was loaded into the process. The "_r_debug" structure is currently found by looking through the .dynamic section in the main executable and finding the DT_DEBUG entry which points to this structure. The dynamic loader will update this structure as shared libraries are loaded and LLDB watches the contents of this structure as the dyld breakpoint is hit. Currently we expect the "state" in this structure to change as things happen. An issue comes up if someone defines another "_r_debug" struct in their program:
```
r_debug _r_debug;
```
If this code is included, a new "_r_debug" structure is created and it causes problems once the executable is loaded. This is because of the way symbol lookups happen in linux: they use the shared library list in the order it created and the dynamic loader is always last. So at some point the dynamic loader will start updating this other copy of "_r_debug", yet LLDB is only watching the copy inside of the dynamic loader.

Steps that show the problem are:
- lldb finds the "_r_debug" structure via the DT_DEBUG entry in the .dynamic section and this points to the "_r_debug" in ld.so
- ld.so modifies its copy of "_r_debug" with "state = eAdd" before it loads the shared libraries and calls the dyld function that LLDB has set a breakpoint on and we find this state and do nothing (we are waiting for a state of eConsistent to tell us the shared libraries have been fully loaded)
- ld.so loads the main executable and any dependent shared libraries and wants to update the "_r_debug" structure, but it now finds "_r_debug" in the a.out program and updates the state in this other copy
- lldb hits the notification breakpoint and checks the ld.so copy of "_r_debug" which still has a state of "eAdd". LLDB wants the new "eConsistent" state which will trigger the shared libraries to load, but it gets stale data and doesn't do anyhing and library load is missed. The "_r_debug" in a.out has the state set correctly, but we don't know which "_r_debug" is the right one.

The new fix detects the two "eAdd" states and loads shared libraries and will emit a log message in the "log enable lldb dyld" log channel which states there might be multiple "_r_debug" structs.

The correct solution is that no one should be adding a duplicate "_r_debug" symbol to their binaries, but we have programs that are doing this already and since it can be done, we should be able to work with this and keep debug sessions working as expected. If a user #includes the <link.h> file, they can just use the existing "_r_debug" structure as it is defined in this header file as "extern struct r_debug _r_debug;" and no local copies need to be made.

If your ld.so has debug info, you can easily see the duplicate "_r_debug" structs by doing:
```
(lldb) target variable _r_debug --raw
(r_debug) _r_debug = {
  r_version = 1
  r_map = 0x00007ffff7e30210
  r_brk = 140737349972416
  r_state = RT_CONSISTENT
  r_ldbase = 0
}
(r_debug) _r_debug = {
  r_version = 1
  r_map = 0x00007ffff7e30210
  r_brk = 140737349972416
  r_state = RT_ADD
  r_ldbase = 140737349943296
}
(lldb) target variable &_r_debug
(r_debug *) &_r_debug = 0x0000555555601040
(r_debug *) &_r_debug = 0x00007ffff7e301e0
```
And if you do a "image lookup --address <addr>" in the addresses, you can see one is in the a.out and one in the ld.so.

Adding more logging to print out the m_previous and m_current Rendezvous structures to make things more clear. Also added a log when we detect multiple eAdd states in a row to detect this problem in logs.

Differential Revision: https://reviews.llvm.org/D158583
2023-08-31 10:37:20 -07:00
Med Ismail Bennani
380c5da98e Revert "Re-land "[lldb/docs] Silence warnings when generating website""
This reverts 3 commit:
- f0731d5b61.
- 8e0a087571.
- f2f5d6fb8d.

This changes were introduced to silence the warnings that are printed
when generating the lldb module documentation for the website but it
changed the python bindings and causes test failures on the macos bot:

https://green.lab.llvm.org/green/job/lldb-cmake/59438/

We will have to consider other options to silence these warnings.
2023-08-31 16:31:10 +01:00
David Spickett
22044f0bde [lldb][AArch64] Add testing of save/restore for Linux MTE control register
This has always worked but had no coverage. Adding testing now so that
later I can refactor the save/restore code safely.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D157488
2023-08-31 12:25:08 +01:00
David Spickett
6697afe99f [lldb][AArch64] Check SIMD save/restore in SVE SIMD test
While doing some refactoring I forgot to carry over the copying in of
SIMD data in normal mode, but no tests failed.

Turns out, it's very easy for us to get the restore wrong because
even if you forget the memcopy, setting the buffer to valid may
just read the data you had before the expression evaluation.

So I've extended the SVE SIMD testing (which includes the plain SIMD mode)
to check expression save/restore. This is the only test that fails
if you forget to do `m_fpu_is_valid = true` so I take from that, that
prior to this it wasn't tested at all.

As a bonus, we now have coverage of the same thing for SVE and SSVE modes.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D157000
2023-08-31 10:21:53 +01:00
David Spickett
0407f681a7 [lldb][AArch64] Use atomics to sync threads in SVE threading test
Previously we would "process continue" then wait for the number of
threads to be 3 before proceeding with the test.

Testing this on QEMU I saw it would sometimes get stuck at this check,
with one of the threads on a breakpoint before the other had started.
We do want it to be on a breakpoint, but we need the other thread to have
at least started so lldb can interact with both.

I've also seen it timeout on the Graviton buildbot, likely the same
cause.

To fix this add 2 variables to stall either thread until the other
has started up. Then it doesn't matter which one hits its breakpoint
first, the test will just continue the one that didn't, until both
are on the expected breakpoint.

Differential Revision: https://reviews.llvm.org/D157967
2023-08-31 10:06:16 +01:00
Jason Molenda
394e52a0bb [lldb] NFC reflow comments in WatchpointLocations
Reading through this header, many of the comment
line breaks are a mess after various code reformats.
2023-08-30 17:58:44 -07:00
Jason Molenda
3621f83804 Don't enable stdin/out with a no-output test program
A followon to  https://reviews.llvm.org/D158237 ,
where this text can print stdout text when run
under address-sanitizer, and the test harness
does not expect any output, resulting in a test
failure on a sanitizer CI bot.
2023-08-30 15:12:31 -07:00
walter erquinigo
79d5d9a082 [lldb] Allow synthetic providers in C++ and fix linking problems
- Allow the definition of synthetic formatters in C++ even when LLDB is built without python scripting support.
- Fix linking problems with the CXXSyntheticChildren

Differential Revision: https://reviews.llvm.org/D158010
2023-08-30 14:14:28 -04:00
Yuxuan Shui
9a4b3fdb82 [lldb][windows] _wsopen_s does not accept bits other than _S_IREAD | _S_IWRITE
When sending file from a Linux host to a Windows remote, Linux host will try to copy the source file's permission bits, which will contain `_S_I?GRP` and `_S_I?OTH` bits. Those bits are rejected by `_wsopen_s`, causing it to return EINVAL.

This patch masks out the rejected bits.

GitHub issue: #64313

Reviewed By: jasonmolenda, DavidSpickett

Differential Revision: https://reviews.llvm.org/D156817
2023-08-30 15:53:31 +03:00
Alex Langford
5d49c9ce65 [lldb][NFCI] Remove StructuredData::Array::GetItemAtIndexAsString overloads with ConstString
This is the next step in removing ConstString from StructuredData. There
are StringRef overloads already, let's use those where we can.

Differential Revision: https://reviews.llvm.org/D152870
2023-08-29 16:02:26 -07:00
Med Ismail Bennani
f2f5d6fb8d [lldb] Fix test failures introduced by 8e0a087571
Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-08-29 16:52:30 +01:00
Med Ismail Bennani
8e0a087571 [lldb] Fix build failures introduced in f0731d5b61 (NFCI)
This patch should fix the build failures introduced by f0731d5b61.

This removes the use of the `STRING_EXTENSION_OUTSIDE` swig macro in SB
classes that don't implement a `GetDescription` method.

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-08-29 16:34:56 +01:00
Med Ismail Bennani
f0731d5b61 Re-land "[lldb/docs] Silence warnings when generating website"
This reverts commit 18f1c1ace7 and fix the
build failure issues introduced because of the `STRING_EXTENSION_OUTSIDE`
swig macros.

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

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-08-29 16:24:33 +01:00
Med Ismail Bennani
18f1c1ace7 Revert "[lldb/docs] Silence warnings when generating website"
This reverts commit 498b59e011 since it
introduces a build failure:

https://lab.llvm.org/buildbot/#/builders/68/builds/58995

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-08-29 13:57:35 +01:00
Med Ismail Bennani
498b59e011 [lldb/docs] Silence warnings when generating website
This patch does various things to silence the warnings that show up when
generating the website documentation.

First, this patch adds the missing definition for special member methods
in every SBAPI class. If the class cannot implement one of the special
member method, we just define it as a null operation (pass).

This should fix the following warnings:

```
WARNING: missing attribute __int__ in object lldb.SB*
WARNING: missing attribute __len__ in object lldb.SB*
WARNING: missing attribute __hex__ in object lldb.SB*
WARNING: missing attribute __oct__ in object lldb.SB*
WARNING: missing attribute __iter__ in object lldb.SB*
```

Then, it un-skips the various `static` methods that we didn't generate
the methods for, since it's not necessary thanks to the automod-api module.

Finally, this comments out the `_static` directory in the sphinx config,
since we don't need it anymore.

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

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-08-29 13:45:30 +01:00
walter erquinigo
bc0b569906 [LLDB] Fix tab size settings tests
They were reported in https://lab.llvm.org/buildbot/#/builders/68/builds/58956 and the fix is simple.
2023-08-28 17:55:15 -04:00
walter erquinigo
47aca7562a [LLDB][REPL] Change the default tab size
The REPL has a default tab size of 4 spaces, which seems to be a bit too much. The reason is that the REPL transforms tabs into spaces, and therefore whenever you want to manually deindent, you need to delete at least 4 characters. On the other hand, using 2 as default results in less keystrokes, without hurting readability.
2023-08-28 17:47:30 -04:00
Muhammad Omair Javaid
8e946fec04 Revert "[mlir][complex] Convert complex.abs to arith with fastmath flag"
This reverts commit 653f77690b.

This breaks lldb-aarch64-windows buildbot.
I have reproduced the issue on x86_64 Windows as well.
https://lab.llvm.org/buildbot/#/builders/219/builds/5130
2023-08-29 02:01:20 +05:00
Kazu Hirata
3a14993fa4 Fix typos in documentation 2023-08-27 00:18:14 -07:00
Med Ismail Bennani
6a2552a141 [lldb/infra] Revamp lldb.llvm.org
This patch brings a fresh coat of paint to the LLDB website.

This uses the `furo` theme from the suggested theme list, adds some
changes to the css to make it use the full browser window width and
removes the table of contents since the theme generates it automatically.

This patch also rewrites the tables for "GDB to LLDB command map" to
convert them from raw HTML to native inlined code blocks.

To generate the website, make sure you install the theme first with
`pip install furo`, enable sphinx in the cmake invocation` then run
`ninja docs-lldb-html`

Discourse: https://discourse.llvm.org/t/rfc-revamping-lldbs-website

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

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-08-26 09:54:56 +01:00
Jonas Devlieghere
a7ca1175d0 [lldb] Fix & re-enable TestVSCode_completions on Darwin
The test was expecting vector<basic_string<char>> & while the test
returned vector<string> &. Since verify_completions doesn't support
regex matching, sidestep the issue by using a custom type (baz).

Differential revision: https://reviews.llvm.org/D158893
2023-08-25 14:35:07 -07:00
Jonas Devlieghere
6bdf485887 [lldb] Re-enable TestVSCode_launch on Darwin
The test was disabled because it was supposedly flakey. I'm not able to
reproduce any flakiness. I ran the test in a look with different levels
of parallelization and load. Re-enabling the test and monitoring the
Darwin bots.
2023-08-25 13:52:45 -07:00
Jonas Devlieghere
37086cadb1 [lldb] Use Popen.wait in TestVSCode_launch 2023-08-25 12:59:52 -07:00
Jonas Devlieghere
1034688d58 [lldb] Re-enable TestVSCode_disconnect on Darwin
The test was disabled because it failed on the sanitized bot. I'm not
able to reproduce that locally. The test uses timeouts which could
explain why it was failing in the past.

Let's re-enable it and see what happens. If it fails again on
GreenDragon, rather than disabling it on Darwin altogether, we should
either increase the timeouts or skip it when run under ASan.
2023-08-25 11:02:38 -07:00
Jonas Devlieghere
50b127613a [lldb] Qualify auto in the lldb driver (NFC)
The LLVM coding guidelines say to "[u]se auto & for values and auto *
for pointers unless you need to make a copy."
2023-08-25 07:40:37 -07:00
Jonas Devlieghere
7bd6328958 [lldb-vscode] Update package.json
- Update license, display name, repository and keywords
 - Add homepage, issue page
 - Fix formatting and typos

Differential revision: https://reviews.llvm.org/D158801
2023-08-24 22:36:53 -07:00
Kai Sasaki
653f77690b [mlir][complex] Convert complex.abs to arith with fastmath flag 2023-08-25 12:10:43 +09:00