Commit Graph

28856 Commits

Author SHA1 Message Date
David Spickett
602e47c5f9
[lldb] Format Python files in scripts and utils (#66053)
Using:
black --exclude "third_party/" ./lldb/
2023-09-14 08:54:02 +01:00
Jonas Devlieghere
6ebbb1f536
[lldb] Simplify color logic in (IOHandler)Editline (NFC)
This patch simplifies the color handling logic in Editline and
IOHandlerEditline:

 - Remove the m_color_prompts property from Editline and use the prompt
   ANSI prefix and suffix as the single source of truth. This avoids
   having to redraw the prompt unnecessarily, for example when colors
   are enabled but the prompt prefix and suffix are empty.

 - Rename m_color_prompts to just m_color in IOHandlerEditline and use
   it to ensure consistency between colored prompts and colored
   auto-suggestions. Some IOHandler explicitly turn off colors (such as
   IOHandlerConfirm) and it doesn't really make sense to have one or the
   other.
2023-09-13 22:27:05 -07:00
Jonas Devlieghere
c3b3942064
[lldb] Improve comments in Editline.h (NFC)
Fix typos, add missing periods and reflow comments in the Editline
header.
2023-09-13 21:24:33 -07:00
Jonas Devlieghere
645a3855dd
[lldb] Add a setting to customize the prompt color (#66218)
Users often want to change the look of their prompt and currently the
only way to do that is by using ANSI escape codes in the prompt itself.
This is not only tedious, it also results in extra whitespace because
our Editline wrapper, when computing the cursor column, doesn't ignore
the invisible escape codes.

We already have various *-ansi-{prefix,suffix} settings that allow the
users to customize the color of auto-suggestions and progress events,
using mnemonics like ${ansi.fg.yellow}. This patch brings the same
mechanism to the prompt.

rdar://115390406
2023-09-13 20:58:12 -07:00
Jonas Devlieghere
019c8396c9
[lldb] Fix PExpectTest when using utf-8 as the encoding
PExpect 4.6, when using 'utf-8' throws a TypeError when trying to write
to the log file:

  File "llvm-project/lldb/third_party/Python/module/pexpect-4.6/pexpect/spawnbase.py", line 126, in _log
    self.logfile.write(s)
  TypeError: a bytes-like object is required, not 'str'

This looks like a bug in PExpect to me. Since the log file is only used
for tracing, work around the issue by disabling the log file when
specifying an encoding. This should fix the Debian bot [1] which runs
the test with tracing enabled (-t).

[1] https://lab.llvm.org/buildbot/#/builders/68/builds/59955
2023-09-13 20:33:47 -07:00
Jonas Devlieghere
850e90c47b
[lldb] Support Unicode in the prompt (#66312)
Account for Unicode when computing the prompt column width. Previously,
the string length (i.e. number of bytes) rather than the width of the
Glyph was used to compute the cursor position. The result was that the
cursor would be offset to the right when using a prompt containing
Unicode.
2023-09-13 20:08:05 -07:00
Augusto Noronha
705f24cdab
[lldb] Accept optional module in Value::ResolveValue (#66286)
Value::ResolveValue calls Value::GetValueAsData as part of its
implementation. The latter can receive an optional Module pointer, which
is always null when called from the former. Allow threading in the
Module in Value::ResolveValue.

rdar://115021869
2023-09-13 14:23:50 -07:00
Arthur Eubanks
377497f32a [NFC][lldb] Replace usage of deprecated llvm::makeArrayRef 2023-09-13 13:46:46 -07:00
Jonas Devlieghere
4d10b9507d
[lldb] Fix formatting and whitespace in Debugger.{h,cpp} (NFC)
This file is heavily trafficked and the various formatting and
whitespace issues make it tedious to work on.
2023-09-13 09:14:54 -07:00
David Spickett
b6f66c94bc [lldb][AArch64] Reformat register set test with black
I missed this before landing.
2023-09-13 15:52:24 +00:00
David Spickett
f8b2544c42 [lldb] Link to LLVM code style in LLDB's contributing page
So folks at least know what we are differing from.
2023-09-13 10:48:48 +01:00
David Spickett
461f859a72
[lldb] Treat user aliases the same as built-ins when tab completing (#65974)
Previously we would check all built-ins first for suggestions,
then check built-ins and aliases. This meant that if you had
an alias brkpt -> breakpoint, "br" would complete to "breakpoint".

Instead of giving you the choice of "brkpt" or "breakpoint".
2023-09-13 10:12:12 +01:00
David Spickett
11de4c724c [lldb][AArch64] Add tests for SME's SVE register state to TestArm64DynamicRegsets
SME reuses SVE's register state but adds new modes to it. Therefore
we can't check all those in the same test as the existing SVE
checks.

SME's ZA, SVG and SVCR register checks will be added to this test
in later patches.

Prior to this we didn't have any testing of writing streaming mode
SVE registers from lldb, only writing SVE registers in normal
(non-streaming) SVE mode.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D157846
2023-09-13 10:07:36 +01:00
Alex
64122580c0
[lldb][NFCI] BreakpointResolverName ctor shouldn't unnecessarily copy data (#66001)
Instead of creating a copy of the vector, we should just pass a
reference along. The only method that calls this Ctor also holds onto a
non-mutable reference to the vector of strings so a copy should be
unnecessary.
2023-09-12 15:32:06 -07:00
David Spickett
c8387a31a4
[lldb] Format more Python files with black (#65979)
By running this from lldb/

$ black --exclude "third_party/|scripts/|utils/" ./
2023-09-12 08:46:34 +01:00
David Spickett
6bf6c4762c Reland "[lldb] Improve completion tests (#65973)"
This reverts commit 8012518f60.

The x86 register write test had one that expected "\$rax" so on.
As these patterns were previously regex, the $ had to be escaped.
Now they are just plain strings to this is not needed.
2023-09-12 08:40:43 +01:00
Jason Molenda
2cab996192 Add "process metadata" Mach-O LC_NOTE for corefiles
Add a new LC_NOTE for Mach-O corefiles, "proces metadata", which is a
JSON string.  Currently there may be a `threads` key in the JSON,
and if `threads` is present, it is an array with the same number of
elements as there are LC_THREADs in the corefile.  This patch adds
support for a `thread_id` key-value for each `thread` entry, to
supply a thread ID for that LC_THREAD.

Differential Revision: https://reviews.llvm.org/D158785
rdar://113037252
2023-09-11 16:46:18 -07:00
Walter Erquinigo
a2a9918a85
[lldb-vscode] Make descriptive summaries and raw child for synthetics configurable (#65687)
"descriptive summaries" should only be used for small to medium binaries
because of the performance penalty the cause when completing types. I'm
defaulting it to false.
Besides that, the "raw child" for synthetics should be optional as well.
I'm defaulting it to false.

Both options can be set via a launch or attach config, following the
pattern of most settings. javascript extension wrappers can set these
settings on their own as well.
2023-09-11 17:00:01 -04:00
walter erquinigo
c154ba8abe [LLDB][NFC] Add the mojo language to Language::GetPrimaryLanguage
This doesn't change the current behavior of the function, but the explicit declaration looks cleaner.
2023-09-11 15:25:05 -04:00
David Spickett
8012518f60 Revert "[lldb] Improve completion tests (#65973)"
This reverts commit 2378ba632e.

I need to fix the x86 specific register tests.
2023-09-11 17:35:27 +00:00
David Spickett
2378ba632e
[lldb] Improve completion tests (#65973)
* Assert no completions for tests that should not find completions.
* Remove regex mode from complete_from_to, which was unused.

This exposed bugs in 2 of the tests, target stop-hook and
process unload. These were fixed in previous commits but
couldn't be tested properly until this patch.
2023-09-11 18:26:51 +01:00
David Spickett
6bf923d5c3 [lldb][Tests] Reformat API tests with black
These are all recent additions I think, including a few of mine
for AArch64.

Going forward the CI checks should help us fix these earlier.
2023-09-11 16:44:12 +00:00
David Spickett
3125bd4bc7
[lldb] Correctly invalidate unloaded image tokens (#65945)
Some functions in Process were using LLDB_INVALID_ADDRESS instead of
LLDB_INVALID_TOKEN.

The only visible effect of this appears to be that "process unload
<tab>" would complete to 0 even after the image was unloaded. Since the
command is checking for LLDB_INVALID_TOKEN.

Everything else worked somehow. I've added a check to the existing load
unload tests anyway.

The tab completion cannot be checked as is, but when I make them more
strict in a later patch it will be tested.
2023-09-11 17:12:09 +01:00
David Spickett
825adbe558 [lldb] Don't tab complete stop-hook delete beyond 1st argument
This already applies to enable and disable, delete was missing
a check.

This cannot be tested properly with the current completion tests,
but it will be when I make them more strict in a follow up patch.
2023-09-11 11:00:57 +00:00
David Spickett
8f2ffb1cf3 [lldb][AArch64] Add type marker to ReadAll/WriteALLRegisterValues data
While working in support for SME's ZA register, I found a circumstance
where restoring ZA after SVE, when the current SVE mode is non-streaming,
will kick the process back into FPSIMD mode. Meaning the SVE values that
you just wrote are now cut off at 128 bit.

The fix for that is to write ZA then SVE. Problem with that
is, the current ReadAll/WriteAll makes a lot of assumptions about the
saved data length.

This patch changes the format so there is a "type" written before
each data block. This tells WriteAllRegisterValues what it's looking at
without brittle checks on length, or assumptions about ordering.

If we want to change the order of restoration, all we now have to
do is change the order of saving.

This exposes a bug where the TLS registers are not restored.
This will be fixed by https://reviews.llvm.org/D156512 in some form,
depending on what lands first.

Existing SVE tests certainly check restoration and when I got this
wrong, many, many tests failed. So I think we have enough coverage
already, and more will be coming with future ZA changes.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D156687
2023-09-11 07:56:59 +01:00
Jonas Devlieghere
86f21e92ab
[lldb] Reinstate default constructor for SBCommandInterpreter
The default constructor for SBCommandInterpreter was (unintentionally)
made protected in 27b6a4e63a. The goal of the patch was to make the
constructor taking an lldb_private type protected, but due to the
presence of a default argument, this ctor also served as the default
constructor. The latter should remain public.

This commit reinstates the original behavior by removing the default
argument and having an explicit, public default constructor.
2023-09-09 20:20:04 -07:00
David Spickett
0f1a01807c
[lldb] Add test to document alias tab completion behaviour (#65760)
While looking at https://github.com/llvm/llvm-project/issues/49528 I
found that, happily, aliases can now be tab completed.

However, if there is a built-in match that will always be taken. Which
is a bit surprising, though logical if we don't want people really
messing up their commands I guess.

Meaning "b" tab completes to our built-in breakpoint alias, before it
looks at any of the aliases. "bf" doesn't match "b", so it looks through
the aliases.

I didn't find any tests for this in the obvious places, so this adds
some.
2023-09-08 17:08:02 +01:00
Author: Eddie Phillips
9ce82a10a3 Wrong link target in the documentation #62990
In the LDDB documentation you have the following sentence:

"The --format (which you can shorten to -f) option accepts a format name."

The link points to the wrong place.

I pointed it to the table that precedes the Type summary section.

Reviewed By: DavidSpickett

Differential Revision: https://reviews.llvm.org/D151668
2023-09-08 15:38:28 +01:00
David Spickett
f2b241474f [lldb][AArch64] Re-enable clone follow tests on AArch64 Linux
Fixes #49243

By unknown means, these have been fixed since the UNSUPPORTED
was added.
2023-09-08 14:10:08 +00:00
David Spickett
e067b0e4a7 [lldb][AArch64] Re-enable TestShowLocationDwarf5
Fixes #43525

For unknown reasons, this has been fixed in the time
since the issue was raised.
2023-09-08 13:04:48 +00:00
David Spickett
f98ca79c7b [lldb][Docs] Update bug report and code review links
The issues link as it was was including PRs, so I've made that
issues only and only those in an open state.

Code review is now on Gtihub so same thing, PRs only, open state,
label lldb.
2023-09-08 09:56:42 +00:00
David Spickett
3398744a61
[lldb][Docs] Additions to debuging LLDB page (#65635)
Adds the following:
* A note that you can use attaching to debug the right lldb-server
process, though there are drawbacks.
* A section on debugging the remote protocol.
* Reducing bugs, including reducing ptrace bugs to remove the need for
LLDB.

I've added a standlone ptrace program to the examples folder because:
* There's no better place to put it.
* Adding it to the page seems like wasting space, and would be harder to
update.
* I link to Eli Bendersky's classic blog on the subject, but we are
safer with our own example as well.
* Eli's example is for 32 bit Intel, AArch64 is more common these days.
* It's easier to show the software breakpoint steps in code than explain
it (though I still do that in the text).
* It was living on my laptop not helping anyone so I think it's good to
have it upstream for others, including future me.
2023-09-08 10:05:16 +01:00
Pavel Labath
d4c3c2872f [lldb] Fix Process::SyncIOHandler
D157648 broke the function because it put the blocking wait into a
critical section. This meant that, if m_iohandler_sync was not updated
before entering the function, no amount of waiting would help.

Fix that by restriciting the scope of the critical section to the
iohandler check.
2023-09-08 10:17:16 +02:00
David Spickett
b1f14d6473 Reland "[lldb] Add more ways to find split DWARF files"
This reverts commit dc3f758ddc.

Lit decided to show me the least interesting part of the
test output, but from what I gather on Mac OS the DWARF
stays in the object files (https://stackoverflow.com/a/12827463).

So either split DWARF options do nothing or they produce
files I don't know the name of that aren't .dwo, so I'm
skipping these tests on Darwin.
2023-09-08 08:15:08 +00:00
David Spickett
dc3f758ddc Revert "[lldb] Add more ways to find split DWARF files"
This reverts commit a723694321.

Tests are failing on x86_64 MacOS.
2023-09-08 08:00:38 +00:00
Jonas Devlieghere
3aa678a777
[lldb/docs] Add section links to the top of the GDB to LLDB command map
Add section links to the top of the GDB to LLDB command map. This makes
navigating the page easier.
2023-09-07 16:26:53 -07:00
Alex
140f6167b8
[lldb][NFCI] Remove typedef for TypeCategoryMap::ValueSP (#65555)
lldb already has a `ValueSP` type. This was confusing to me when reading
TypeCategoryMap, especially when `ValueSP` is not qualified. From first
glance it looks like it's referring to a
`std::shared_ptr<lldb_private::Value>` when it's really referring to a
`std::shared_ptr<lldb_private::TypeCategoryImpl>`.
2023-09-07 10:16:55 -07:00
David Spickett
a723694321 [lldb] Add more ways to find split DWARF files
Fixes #28667

There's a bunch of ways to end up building split DWARF where the
DWO file is not next to the program file. On top of that you may
distribute the program in various ways, move files about, switch
machines, flatten the directories, etc.

This change adds a few more strategies to find DWO files:
* Appending the DW_AT_COMP_DIR and DWO name to all the debug
  search paths.
* Appending the same to the binary's dir.
* Appending the DWO name (e.g. a/b/foo.dwo) to all the debug
  search paths.
* Appending the DWO name to the binary's location.
* Appending the DWO filename (e.g. foo.dwo) to the debug
  search paths.
* Appending the DWO filename to the binary's location.

They are applied in that order and some will be skipped
if the DW_AT_COMP_DIR is relative or absolute, same for
the DWO name (though that seems to always be relative).

This uses the setting target.debug-file-search-paths, which
is used for DWP files already.

The added tests likely do not cover every part of the
strategies listed, it's a best effort.

Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D157609
2023-09-07 08:19:11 +00:00
walter erquinigo
0762b2e6ca [lldb-vscode] Fix variable test
https://lab.llvm.org/buildbot/#/builders/68/builds/59499 caught a failed test introduced by cf5d8def5c.
The fix is simple. We just need to update some values.
2023-09-06 22:52:01 -04:00
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