Commit Graph

7044 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
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
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
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
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
a902015f54
[lldb] Fix grammar in error message emitted by IRExecutionUnit
The error message "Couldn't lookup symbols" emitted from IRExecutionUnit
is grammatically incorrect. "Lookup" is noun when spelled without a
space. Update the error message to use the verb "look up" instead.
2023-08-24 14:11:30 -07:00
Med Ismail Bennani
a6c97a1a30 [lldb/test] Fix Crashlog/no-args.test on ASAN builds (NFC)
This should fix the Sanitizer Green Dragon LLDB Bot:
https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake-sanitized/4633

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-08-23 07:32:35 -07:00
walter erquinigo
7822e5dbf1 [LLDB] Allow expression evaluators to set arbitrary timeouts
59237bb52c changed the behavior of the `SetTimeout` and `GetTimeout` methods of `EvaluateExpressionOptions`, which broke the Mojo REPL and related services (https://docs.modular.com/mojo/) because it relies on having infinite timeouts. That's a necessity because developers often use the REPL for executing extremely long-running numeric jobs. Having said that, `EvaluateExpressionOptions` shouldn't be that opinionated on this matter anyway. Instead, it should be the responsibility of the evaluator to define which timeout to use for each specific case.

Differential Revision: https://reviews.llvm.org/D157764
2023-08-22 17:41:14 -04:00
Med Ismail Bennani
4c4f0d81f4 [lldb/crashlog] Add support for Last Exception Backtrace
This patch adds support to the "Last Exception Backtrace" to the
`crashlog` command.

This metadata is homologous to the "Application Specific Backtrace",
however the format is closer to a regular stack frame.

Since the thread that "contains" the "Last Exception Backtrace" doesn't
really exist, this information is displayed when requesting an extended
backtrace of the crashed thread, similarly to the "Application Specific
Backtrace".

To achieve that, this patch includes some refactors and fixes to the
existing "Application Specific Backtrace" handling.

rdar://113046509

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

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-08-18 20:50:39 +01:00
Med Ismail Bennani
eef5eadbe6 [lldb/crashlog] Replace deprecated optparse by argparse (NFC)
This patch replace the deprecated `optparse` module used for the
`crashlog`& `save_crashlog` commands with the new `argparse` from the
python standard library. This provides many benefits such as showing the
default values for each option in the help description, but also greatly
improve the handling of position arguments.

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

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-08-18 20:50:39 +01:00
Med Ismail Bennani
7602641d7b [lldb/crashlog] Add test for 8f75c4d01e (NFC)
Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-08-18 20:50:39 +01:00
David Spickett
4139461d4e [lldb] Fix REQUIRES for DWO relative path test
This was "x86-registered-target" which seems to be false in this test
suite despite me having the x86 backend enabled. The other tests use just "x86"
and with that the test passes on my AArch64 machine fine.
2023-08-17 14:19:27 +00:00
Vladimir Makaev
e84751a215 [lldb] Add basic support to Rust enums in TypeSystemClang
LLDB doesn't yet have a TypeSystemRust implemented however it is used to debug Rust applications. Most of the types map well enough to Clang types and there are python formatters implemented to display those types reasonably well in a debugger.

However, Rust enums are completely ignored by LLDB as Clang never emits DW_TAG_variant_part inside DW_TAG_structure_type

This diff adds a parser for DW_TAG_variant_part (Rust-only) that creates a matching valid Clang declaration to the Rust enum. As long as there is enough information and all fields have correct offsets synthetic/summary providers can be implemented to display it correctly when debugging Rust code

Differential Revision: https://reviews.llvm.org/D149213
2023-08-17 02:34:35 +01:00
Jim Ingham
d268ba3808 Test follow-up to 2e7aa2ee34
The TestEvents.py test I added for ShadowListeners fails on Windows.
Since there's no reason to believe the ShadowListeners feature has
different behavior from the other event-based tests here, I copied
the skips & expected_flakey's from the other tests in that file to
this one.
2023-08-16 12:19:07 -07:00
Jim Ingham
2e7aa2ee34 Replace the singleton "ShadowListener" with a primary and N secondary Listeners
Before the addition of the process "Shadow Listener" you could only have one
Listener observing the Process Broadcaster.  That was necessary because fetching the
Process event is what switches the public process state, and for the execution
control logic to be manageable you needed to keep other listeners from causing
this to happen before the main process control engine was ready.

Ismail added the notion of a "ShadowListener" - which allowed you ONE
extra process listener.  This patch inverts that setup by designating the
first listener as primary - and giving it priority in fetching events.

Differential Revision: https://reviews.llvm.org/D157556
2023-08-16 10:35:32 -07:00
Pavel Kosov
83695d45d6 [lldb][gui] Update TreeItem children's m_parent on move
Before this patch, any time TreeItem is copied in Resize method, its
parent is not updated, which can cause crashes when, for example, thread
window with multiple hierarchy levels is updated. Makes TreeItem
move-only, removes TreeItem's m_delegate extra self-assignment by making
it a pointer, adds code to fix up children's parent on move constructor
and operator=
Patch prepared by NH5pml30

~~~

Huawei RRI, OS Lab

Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D157960
2023-08-16 11:10:00 +03:00
Jason Molenda
ebf249066a [lldb] SBTarget::AddModule do all searches by UUID, set Target arch
Make SBTarget::AddModule possibly call out to an external program to
find the binary by UUID if it can't be found more easily, the same
way `target modules add -u ...` works from the commandline.

If the Target does not have an architecture set yet, use the
Module's Arch to initialize it.  Allows an API writer to create
a target with no arch, and inherit it from the first binary they
load with AddModules.

Differential Revision: https://reviews.llvm.org/D157659
rdar://113657555
2023-08-11 14:20:38 -07:00
Michael Buch
487ab39a50 [lldb][test] Remove tests relying on deprecated std::char_traits specializations
(motivated by test failures after D157058)

With D157058 the base template for `std::char_traits` was removed from
libc++. Quoting the release notes:

```
The base template for ``std::char_traits`` has been removed. If you are using
``std::char_traits`` with types other than ``char``, ``wchar_t``, ``char8_t``,
``char16_t``, ``char32_t`` or a custom character type for which you
specialized ``std::char_traits``, your code will no longer work.
```

This patch simply removes all such instantiations to make sure the
tests that run against the latest libc++ version pass.

One could try testing the existence of this base template from within
the test source files but this doesn't seem like something we want
support.

Differential Revision: https://reviews.llvm.org/D157636
2023-08-10 19:48:44 +01:00
Jason Molenda
57cbd26a68 Flag for LoadBinaryWithUUIDAndAddress, to create memory image or not
DynamicLoader::LoadBinaryWithUUIDAndAddress can create a Module based
on the binary image in memory, which in some cases contains symbol
names and can be genuinely useful.  If we don't have a filename, it
creates a name in the form `memory-image-0x...` with the header address.

In practice, this is most useful with Darwin userland corefiles
where the binary was stored in the corefile in whole, and we can't
find a binary with the matching UUID.  Using the binary out of
the corefile memory in this case works well.

But in other cases, akin to firmware debugging, we merely end up
with an oddly named binary image and no symbols.

Add a flag to control whether we will create these memory images
and add them to the Target or not; only set it to true when working
with a userland Mach-O image with the "all image infos" LC_NOTE for
a userland corefile.

Differential Revision: https://reviews.llvm.org/D157167
2023-08-07 15:19:45 -07:00
Jonas Devlieghere
17226c976e
[lldb] Make TSan errors fatal when running the test suite
Set the halt_on_error runtime flag to make TSan errors fatal when
running the test suite. For the API tests the environment variables are
set conditionally on whether the TSan is enabled. The Shell and Unit
tests don't have that logic but setting the environment variable is
harmless. For consistency, I've also mirrored the ASAN option
(detect_stack_use_after_return=1) for the Shell tests.

Differential revision: https://reviews.llvm.org/D157152
2023-08-07 13:20:38 -07:00
Eymen Ünay
aa2784876a [lldb] Fix typo in comments and in test
Reviewed By: DavidSpickett

Differential Revision: https://reviews.llvm.org/D157214
2023-08-07 12:56:55 +00:00
David Spickett
91a0e832d4 [lldb] Make IR interpreter timeout test more loose
This has failed once in a while on our Windows on Arm bot:
https://lab.llvm.org/buildbot/#/builders/219/builds/4688

Traceback (most recent call last):
  File "C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\...
    self.assertGreaterEqual(duration_sec, 1)
AssertionError: 0.9907491207122803 not greater than or equal to 1

We're not here to check that Python/the C++ lib/the OS implemented
timers correctly, so accept anything 0.95 or greater.
2023-08-07 09:42:26 +00:00
Jonas Devlieghere
ecbe78c124
[lldb] Fix Python test formatting (NFC)
All Python files in the LLVM repository were reformatted with Black [1].
Files inside the LLDB subproject were reformatted in 2238dcc393. This
patch updates a handful of tests that were added or modified since then
and weren't formatted with Black.

[1] https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style/68257
2023-08-04 14:36:13 -07:00
Jonas Devlieghere
e0053bc04e
[lldb] Bump SWIG minimum version to 4
SWIG 4 was released in 2019 and has been the de-facto standard for a
while now. All bots are running SWIG 4.0 or later.

This was motivated by #64279 which discovered that 662548c broke the
LLDB build with SWIG 3 on Windows.

Differential revision: https://reviews.llvm.org/D156804
2023-08-04 14:34:01 -07:00
Tom Yang
786bab4334 Display PC instead of <unknown> for stack trace in vscode
It isn't useful for users to see "<unknown>" as a stack trace when lldb fails to symbolicate a stack frame. I've replaced "<unknown>" with the value of the program counter instead.

Test Plan:

To test this, I opened a target that lldb fails to symbolicate in
VSCode, and observed in the CALL STACK section that instead of being
shown as "<unknown>", those stack frames are represented by their
program counters.

I added a new test case, `TestVSCode_stackTraceMissingFunctionName` that
exercises this feature.

I also ran `lldb-dotest -p TestVSCode` and saw that the tests passed.

Differential Revision: https://reviews.llvm.org/D156732
2023-08-04 11:07:27 -07:00
David Spickett
27a0a743cf Revert "[lldb][lldb-vscode] Skip disassembler test on Arm"
This reverts commit 54458c525a.

The timeouts we were seeing have been fixed by 9a3f0cd717
and I think this was experiencing the same issue.
2023-08-04 09:26:40 +00:00
David Spickett
6239227172 [lldb][AArch64] Save/restore TLS registers around expressions
Previously lldb was storing them but not restoring them. Meaning that this function:
```
void expr(uint64_t value) {
  __asm__ volatile("msr tpidr_el0, %0" ::"r"(value));
}
```
When run from lldb:
```
(lldb) expression expr()
```
Would leave tpidr as `value` instead of the original value of the register.

A check for this scenario has been added to TestAArch64LinuxTLSRegisters.py,
which covers tpidr and the SME excluisve tpidr2 register when it's present.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D156512
2023-08-03 12:33:49 +00:00
David Spickett
43ad521f2f [lldb][AArch64] Add reading of TLS tpidr register from core files
7e229217f4 did live processes, this does
core files. Pretty simple, there is an NT_ARM_TLS note that contains
at least tpidr, and on systems with the Scalable Matrix Extension (SME), tpidr2
as well.

tpidr2 will be handled in future patches for SME support.

This NT_ARM_TLS note has always been present but it seems convenient to
handle it as "optional" inside of LLDB. We'll probably want the flexibility
when supporting tpidr2.

Normally the C library would set tpidr but all our test sources build
without it. So I've updated the neon test program to write to tpidr
and regenerated the corefile.

I've removed the LLDB_PTRACE_NT_ARM_TLS that was unused, we get
what we need from llvm's defs instead.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D156118
2023-08-03 12:06:06 +00:00
Augusto Noronha
5f45a87bf0 [lldb] Print hint if object description is requested but not implemented
Lots of users use "po" as their default print command. If the type
doesn't implement the description function the output is often not what
the user wants. Print a hint telling the user that they might prefer
using "p" instead.

Differential Revision: https://reviews.llvm.org/D153489
2023-08-02 15:33:32 -07:00
Jonas Devlieghere
61af957aea
[lldb] Make IR interpretation interruptible
Check the interrupt flag while interpreting IR expressions and allow the
user to interrupt them.

Differential revision: https://reviews.llvm.org/D156822
2023-08-02 13:56:24 -07:00
David Spickett
54458c525a [lldb][lldb-vscode] Skip disassembler test on Arm
This is failing and/or causing time outs (hard to tell which ) on
our Arm Linux bot:
https://lab.llvm.org/buildbot/#/builders/17/builds/41108
2023-08-02 14:36:24 +00:00
Michael Buch
5ce7831b40 [lldb][test] Skip *-dbg-info-content API tests
These tests started failing on the public build-bots recently
with following error:
```
AssertionError: 'error: Couldn't lookup symbols:
  __ZNSt3__122__libcpp_verbose_abortEPKcz
' is not success
```

We've seen this previously when the SDKs we used to compile the
`std` module differ from the test program.
(see D146714, rdar://107052293, D139361, rdar://102427461)

Skip these tests on older MacOS versions for now.

This is possibly related to the recent `std` module changes in D144322.

rdar://113227172

Differential Revision: https://reviews.llvm.org/D156827
2023-08-01 23:43:24 +02:00
Wanyi Ye
ca76281917 [lldb] Fix test TestBSDArchives.py properly
The previous patch D156367 introduced a test debugging thin archive with one of the linked object file missing. It actually failed on green dragon build bots. I put up a speculative fix (4520cc066b) that only fixed the symptom of it.

The actual root cause was that the timestamps were set to 0 when creating the thin archive
Makefile command
```
llvm-ar -rcsDT libfoo-thin.a a.o b.o
```
Where the flag "[D] - use zero for timestamps and uids/gids (default)" according to the llvm-ar help
Use "[U] - use actual timestamps and uids/gids" fixed the timestamp

Now the test is actually getting error from missing object file linked to the thin archive instead of the mismatched timestamp.
This means removing one of the object file a.o should only result in failure breaking at `a()`; breaking at `b()` should work just fine.

Test Plan:

All 4 test cases passed
```
▶ ./bin/llvm-lit -vv ../llvm-project/lldb/test/API/functionalities/archives/TestBSDArchives.py
llvm-lit: /Users/wanyi/local/llvm-project/lldb/test/API/lit.cfg.py:173: warning: Could not set a default per-test timeout. Requires the Python psutil module but it could not be found. Try installing it via pip or via your operating system's package manager.
-- Testing: 1 tests, 1 workers --
PASS: lldb-api :: functionalities/archives/TestBSDArchives.py (1 of 1)

Testing Time: 8.07s
  Passed: 1

1 warning(s) in tests
```

Differential Revision: https://reviews.llvm.org/D156564
2023-08-01 16:38:58 -04:00
Jonas Devlieghere
59237bb52c
[lldb] Use a time-based timeout in IRInterpreter
At the moment the IRInterpreter will stop interpreting an expression
after a hardcoded 4096 instructions. After it reaches the limit it will
stop interpreting and leave the process in whatever state it was when
the timeout was reached.

This patch changes the instruction limit to a timeout and uses the
user-specified expression timeout value for this. The main motivation is
to allow users on targets where we can't use the JIT to run more
complicated expressions if they really want to (which they can do now by
just increasing the timeout).

The time-based approach also seems much more meaningful than the
arbitrary (and very low) instruction limit. 4096 instructions can be
interpreted in a few microseconds on some setups but might take much
longer if we have a slow connection to the target. I don't think any
user actually cares about the number of instructions that are executed
but only about the time they are willing to wait for a result.

Based off an original patch by Raphael Isemann.

Differential revision: https://reviews.llvm.org/D102762
2023-08-01 10:50:49 -07:00
John Harrison
ca71dc1b54 [lldb-vscode] Adding support for the "disassemble" request.
Instead of creating psuedo source files for each stack frame this change adopts the new DAP “disassemble” request, allowing clients to inspect assembly instructions of files with debug info in addition to files without debug info.

[[ https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Disassemble | spec ]]

See attached screenshot of the disassembly view. {F28473848}

Reviewed By: wallace

Differential Revision: https://reviews.llvm.org/D156493
2023-07-31 12:44:23 -04:00
Jonas Devlieghere
12f3d97fc6
[lldb] Support recursive record types in CTF
Support recursive record types in CTF, for example a struct that
contains a pointer to itself:

  struct S {
    struct S *n;
  };

We are now more lazy when creating LLDB types. When encountering a
record type (struct or union) we create a forward declaration and only
complete it when requested.

Differential revision: https://reviews.llvm.org/D156498
2023-07-29 22:32:24 -07:00
Jonas Devlieghere
b9867df64a
[lldb] Fix CTF parsing of large structs
Fix parsing of large structs. If the size of a struct exceeds a certain
threshold, the offset is encoded using two 32-bit integers instead of
one.

Differential revision: https://reviews.llvm.org/D156490
2023-07-29 19:37:08 -07:00
Jonas Devlieghere
9c70a3d917
[lldb] Support CTF forward declarations
Add support for parsing CTF forward declarations and converting them
into LLDB types.

Differential revision: https://reviews.llvm.org/D156483
2023-07-28 19:10:36 -07:00
Jonas Devlieghere
0a5e0d3fad
[lldb] Split CTF parsing and type creation (NFC)
Separate parsing CTF and creating LLDB types. This is a prerequisite to
parsing forward references and recursive types.

Differential revision: https://reviews.llvm.org/D156447
2023-07-28 09:41:47 -07:00
Wanyi Ye
4520cc066b [lldb] Fix TestBSDArchives failure
This is a speculative fix for the lldb API test suite
Build bot failures see: https://green.lab.llvm.org/green/view/LLDB/job/as-lldb-cmake/3262/
2023-07-27 17:30:16 -04:00
Wanyi Ye
4b9eed9c64 [BSDArchive] NULL check the child object file ptr before accessing its member
Recently we've observed lldb crashes caused by missing object file linked to a thin archive (.a) files. The crash is due to a missing NULL check in the code when looking for child object file referred by the thin archive. Malformed archive file should not crash LLDB. Instead, it should report the error and continue.

New error message will look like the following

```
error: libfoo.a(__objects__/foo/barAppDelegate.mm.o) failed to load objfile for path/to/libfoo.a.
Debugging will be degraded for this module.
```

Test Plan:

llvm-lit test
```
./bin/llvm-lit -sv ../llvm-project/lldb/test/API/functionalities/archives/TestBSDArchives.py
```

Test without code change will error out with LLDB crash
```
--
Command Output (stderr):
--
PASS: LLDB (~/llvm-upstream/Debug/bin/clang-arm64) :: test (TestBSDArchives.BSDArchivesTestCase)
PASS: LLDB (~/llvm-upstream/Debug/bin/clang-arm64) :: test_frame_var_errors_when_archive_missing (TestBSDArchives.BSDArchivesTestCase)
FAIL: LLDB (~/llvm-upstream/Debug/bin/clang-arm64) :: test_frame_var_errors_when_mtime_mistmatch_for_object_in_archive (TestBSDArchives.BSDArchivesTestCase)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      HandleCommand(command = "b a")
1.      HandleCommand(command = "breakpoint set --name 'a'")
Fatal Python error: Segmentation fault

Current thread 0x00000001f7b99e00 (most recent call first):
  File "~/llvm-upstream/Debug/bin/LLDB.framework/Resources/Python/lldb/__init__.py", line 3270 in HandleCommand
  File "~/llvm-upstream/llvm-project/lldb/packages/Python/lldbsuite/test/lldbtest.py", line 2070 in runCmd
  File "~/llvm-upstream/llvm-project/lldb/packages/Python/lldbsuite/test/lldbtest.py", line 2421 in expect
  File "~/llvm-upstream/llvm-project/lldb/test/API/functionalities/archives/TestBSDArchives.py", line 156 in test_frame_var_errors_when_thin_archive_malformed
...
```

Differential Revision: https://reviews.llvm.org/D156367
2023-07-27 13:21:31 -04:00
David Spickett
efa43d785e [lldb][AArch64] Add the tpidr2 TLS register that comes with SME
This changes the TLS regset to not only be dynamic in that it could
exist or not (though it always does) but also of a dynamic size.

If SME is present then the regset is 16 bytes and contains both tpidr
and tpidr2.

Testing is the same as tpidr. Write from assembly, read from lldb and
vice versa since we have no way to predict what its value should be
by just running a program.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D154930
2023-07-26 10:34:13 +01:00
David Spickett
03d8cd1d72 [lldb][AArch64] Add support for SME's SVE streaming mode registers
The Scalable Matrix Extension (SME) adds a new Scalable Vector mode
called "streaming SVE mode".

In this mode a lot of things change, but my understanding overall
is that this mode assumes you are not going to move data out of
the vector unit very often or read flags.

Based on "E1.3" of "Arm® Architecture Reference Manual Supplement,
The Scalable Matrix Extension (SME), for Armv9-A".

https://developer.arm.com/documentation/ddi0616/latest/

The important details for debug are that this adds another set
of SVE registers. This set is only active when we are in streaming
mode and is read from a new ptrace regset NT_ARM_SSVE.
We are able to read the header of either mode at all times but
only one will be active and contain register data.

For this reason, I have reused the existing SVE state. Streaming
mode is just another mode value attached to that state.

The streaming mode registers do not have different names in the
architecture, so I do not plan to allow users to read or write the
inactive mode's registers. "z0" will always mean "z0" of the active
mode.

Ptrace does allow reading inactive modes, but the data is of little
use. Writing to inactive modes will switch to that mode which would
not be what a debugger user would expect. So lldb will do neither.

Existing SVE tests have been updated to check streaming mode and
mode switches. However, we are limited in what we can check given
that state for the other mode is invalidated on mode switch.

The only way to know what mode you are in for testing purposes would
be to execute a streaming only, or non-streaming only instruction in
the opposite mode. However, the CPU feature smefa64 actually allows
all non-streaming mode instructions in streaming mode.

This is enabled by default in QEMU emulation and rather than mess
about trying to disable it I'm just going to use the pseduo streaming
control register added in a later patch to make these tests more
robust.

A new test has been added to check SIMD read/write from all the modes
as there is a subtlety there that needs noting, though lldb
doesn't have to make extra effort to do so.

If you are in streaming mode and write to v0, when you later exit
streaming mode that value may not be in the non-streaming state.
This can depend on how the core works but is a valid behaviour.

For example, say I am stopped here:
mov x0, v0.d[0]

And I want to update v0 in lldb. "register write v0 ..." should update
the v0 that this instruction is about to see. Not the potential other
copy of v0 in the non-streaming state (which is what I attempted in
earlier versions of this patch).

Not to mention, switching out of streaming mode here would be unexpected
and difficult to signal to the user.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D154926
2023-07-26 09:36:50 +01:00
David Spickett
cf2f433458 [lldb] Remove Windows XFAIL for TestDollarInVariable.py
Since 5d66f9fd8e this test has
been upassing on Linaro's Windows on Arm lldb bot:
https://lab.llvm.org/buildbot/#/builders/219/builds/4320

I can't explain exactly how that happened, but I do see a bunch
of QEnvironment packets going by in that test. It is very likely
that the order would have been different on Windows.

Indeed, when it was xfailed back in df9051e7cf
the reason was not known either.
2023-07-24 13:25:34 +00:00
Fangrui Song
5d66f9fd8e [gdb-remote] Sort entries in QEnvironment*
Similar to ae316ac66f for
QEMU_(UN)SET_ENV.
The iteration order of StringMap is not guaranteed to be deterministic.
Sort the entries to give deterministic packets for the tests added by
D108018.
2023-07-22 16:45:32 -07:00
Med Ismail Bennani
57bd882343 [lldb] Convert script native types to StructuredData counterpart
This patch adds the ability to pass native types from the script
interpreter to methods that use a {SB,}StructuredData argument.

To do so, this patch changes the `ScriptedObject` struture that holds
the pointer to the script object as well as the originating script
interpreter language. It also exposes that to the SB API via a new class
called `SBScriptObject`.

This structure allows the debugger to parse the script object and
convert it to a StructuredData object. If the type is not compatible
with the StructuredData types, we will store its pointer in a
`StructuredData::Generic` object.

This patch also adds some SWIG typemaps that checks the input argument to
ensure it's either an SBStructuredData object, in which case it just
passes it throught, or a python object that is NOT another SB type, to
provide some guardrails for the user.

rdar://111467140

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

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-07-21 18:47:46 -07:00
Jeffrey Tan
49b3c3355f [lldb][x86_64] Support fs_base/gs_base register in Linux
Summary:
[lldb][x86_64] This patch adds fs_base/gs_base support for Linux x86_64.

Originally, I plan to split the diff into two parts, one to refactoring lldb_xxx_x86_64 => x86_64::lldb_xxx across code base and the other one for adding fs_base/gs_base, but it turns out to be a non-trivial effort to split and very error prone so I decided to keep a single diff to get feedback.

GDB supports fs_base/gs_base registers while LLDB does not. Since both linux coredump note section and ptrace
supports them it is a missing feature.

For context, this is a required feature to support getting pthread pointer on linux from both live and dump debugging.
See thread below for details:
https://discourse.llvm.org/t/how-to-get-pthread-pointer-from-lldb/70542/2?u=jeffreytan81

Implementation wise, we have initially tried `#ifdef` approach to reuse the code but it is introducing very tricky bugs and proves
hard to maintain. Instead the diff completely separates the registers between x86_64 and x86_64_with_base so that non-linux related
implementations can use x86_64 registers while linux uses x86_64_with_base.
Here are the list of changes done in the patch:
* Registers in lldb-x86-register-enums.h are separated into two: x86_64 and x86_64_with_base
* fs_base/gs_base are added into x86_64_with_base
* All linux files are change to use x86_64::lldb_xxx => x86_64_with_base::lldb_xxx
* Support linux elf-core:
	* A new RegisterContextLinuxCore_x86_64 class is added for ThreadElfCore
	* RegisterContextLinuxCore_x86_64 overrides and uses its own register set supports fs_base/gs_base
	* RegisterInfos_x86_64_with_base/RegisterInfos_x86_64_with_base_shared ared added to provide g_contained_XXX/g_invalidate_XXX and RegInfo related code sharing.
* `RegisterContextPOSIX_x86 ::m_gpr_x86_64` seems to be unused so I removed it.
* `NativeRegisterContextDBReg_x86::GetDR()` is overridden in `NativeRegisterContextLinux_x86_64` to make watchpoint work.

Reviewers:clayborg,labath,jingham,jdoerfert,JDevlieghere,kusmour,GeorgeHuyubo

Subscribers:

Tasks:

Tags:

Differential Revision: https://reviews.llvm.org/D155256
2023-07-20 16:32:47 -07:00
Felipe de Azevedo Piovezan
8b19d13fde [lldb] Make frame var --regex always search globals
Currently frame var --regex sometimes searches globals, sometimes it doesn't.
This happens because `StackFrame::GetVariableList` always returns the biggest
list it has, regardless of whether only globals were requested or not. In other
words, if a previous call to `GetVariableList` requested globals, all subsequent
calls will see them.

The implication here is that users of `StackFrame::GetVariableList` are expected
to filter the results of this function. This is what we do for a vanilla
`frame var` command. But it is not what we do when `--regex` is used. This
commit solves the issue by:

1. Making `--regex` imply `--globals`. This matches the behavior of `frame var
<some_name>`, which will also search the global scope.
2. Making the `--regex` search respect the command object options.

See the added test for an example of the oddities this patch addresses. Without
the patch, the test fails. However it could be made to pass by calling a plain
`frame var` before calling `frame var --regex A::`.

Differential Revision: https://reviews.llvm.org/D155334
2023-07-19 17:11:21 -04:00
John Harrison
3d1f89c2e3 [lldb-vscode] Creating a new flag for adjusting the behavior of evaluation repl expressions to allow users to more easily invoke lldb commands.
This adds a new flag and lldb runtime command to allow users to manage the behavior of the lldb-vscode evaluate repl request.

When evaluating a repl context this now has runtime managed flag for control how the repl behaviors with the follow values:

* `variable` - the existing behavior, with this mode requests are evaluted in the current frame context as variable expressions. To trigger a lldb command prefix an expression with ` and it will be evaluted as an lldb command.
* `command` - all expressions are evaluated as lldb commands.
* `auto` - An alternative mode that will attempt to determine if the expression is an lldb command or a variable expression. Based off the intepreted results the expression will be evaluted either as a command or an expression.

Additionally, I enabled completions and ensured they work with the new repl expression behavior to provide auto-completes.

This commit includes updates to the tests to verify the new behavior after the previous failures from submitting https://reviews.llvm.org/D154030.

Differential Revision: https://reviews.llvm.org/D155248
2023-07-19 21:04:12 +00:00
David Spickett
865b1190e6 [lldb] XFAIL command-disassemble-mixed.c on Windows
Either clang-cl has different assembly output or we're not mapping
source to assembly properly on Windows. We (Linaro) will find out which.

https://lab.llvm.org/buildbot/#/builders/219/builds/4195
2023-07-19 09:04:56 +00:00
Pavel Labath
b71ac7eea4 [lldb/test] Fix command-disassemble-mixed.c
Add it to lit.local.cfg so that it's actually run, and change it to
(properly) use the %clang_host substitution.
2023-07-18 10:17:09 +02:00
Jim Ingham
b9541b6707 Fix the root directory completion test.
It was implicitly assumning that "/" would have no files in it, only
directories.  That's not true, for instance on macOS if you've navigated
to the root directory in the Finder...

Since we're assuming everything we check against is a directory, then we
need to filter the completion for that coming in.
2023-07-17 10:52:29 -07:00
David Spickett
fdf36c3d4b [lldb][AArch64] Fix flakiness in TestSVEThreadedDynamic
This test runs to a breakpoint on thread 0. Thread 0 then starts
thread 2 and 3, which both have breakpoints in them.

In https://lab.llvm.org/buildbot/#/builders/96/builds/41674
I think that we managed to do the first check on thread 2 before
thread 3 had started. Therefore "thread continue 3" failed.

So wait for all three to startup before we check their status.

I considered putting a timeout on the while like the wait_for... methods,
but the test itself already has a global timeout. Plus, I'd rather
not be tuning a timeout per piece of hardware this runs on.

99% of the time we will already have 3 threads when the check is done.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D154705
2023-07-17 08:11:15 +00:00
Kazuki Sakamoto
43b9d62018 [lldb][Windows] Fix TestLocateModuleCallback
D153735 added the tests but it is failing due to POSIX path vs Windows path.
https://lab.llvm.org/buildbot/#/builders/219/builds/4084

Fix it.
- MODULE_PLATFORM_PATH is POSIX path.
- Normalize self.input_dir, FileSpec and SymbolFileSpec fullpath.

Differential Revision: https://reviews.llvm.org/D155124
2023-07-14 10:36:57 -07:00
Jonas Devlieghere
b716d4e585
[lldb] Move decorators to test method
Make sure TestCTF only run on Darwin when ctfconvert and llvm-objdump
are available.
2023-07-13 15:43:59 -07:00
Jonas Devlieghere
0e285a13eb
[lldb] Support compressed CTF
Add support for compressed CTF data. The flags in the header can
indicate whether the CTF body is compressed with zlib deflate. This
patch supports inflating the data before parsing.

Differential revision: https://reviews.llvm.org/D155221
2023-07-13 15:10:25 -07:00
Jonas Devlieghere
ee44310a48
[lldb] Support Compact C Type Format (CTF)
Add support for the Compact C Type Format (CTF) in LLDB. The format
describes the layout and sizes of C types. It is most commonly consumed
by dtrace.

We generate CTF for the XNU kernel and want to be able to use this in
LLDB to debug kernels for which we don't have dSYMs (anymore). CTF is a
much more limited debug format than DWARF which allows is to be an order
of magnitude smaller: a 1GB dSYM can be converted to a handful of
megabytes of CTF. For XNU, the goal is not to replace DWARF, but rather
to have CTF serve as a "better than nothing" debug info format when
DWARF is not available.

It's worth noting that the LLVM toolchain does not support emitting CTF.
XNU uses ctfconvert to generate CTF from DWARF which is used for
testing.

Differential revision: https://reviews.llvm.org/D154862
2023-07-13 11:30:52 -07:00
Kazuki Sakamoto
f03dbdb70a [lldb][LocateModuleCallback] Implement API, Python interface
RFC https://discourse.llvm.org/t/rfc-python-callback-for-target-get-module/71580

Use SWIG for the locate module callback the same as other Python callbacks.
TestLocateModuleCallback.py verifies the functionalities.

Differential Revision: https://reviews.llvm.org/D153735
2023-07-12 11:33:51 -07:00
Kazuki Sakamoto
c4fa6fafc4 [lldb][LocateModuleCallback] Update SBFileSpec/SBModuleSpec
RFC https://discourse.llvm.org/t/rfc-python-callback-for-target-get-module/71580

SBFileSpec and SBModuleSpec will be used for locate module callback as Python
function arguments. This diff allows these things.
- Can be instantiated from SBPlatform.
- Can be passed to/from Python.
- Can be accessed for object offset and size.

Differential Revision: https://reviews.llvm.org/D153733
2023-07-12 11:11:18 -07:00
Ted Woodward
ded1bad64a Fix mixed disassembly showing source lines for "line 0"
"line 0" in a DWARF linetable means something that doesn't have associated
source. The code for mixed disassembly has a comment indicating that
"line 0" should be skipped, but the wrong value was returned. Fix the return
value and add a test to check that we don't incorrectly show source lines
from the beginning of the file.

Reviewed By: jasonmolenda

Differential Revision: https://reviews.llvm.org/D112931
2023-07-12 11:39:11 -05:00
Jonas Devlieghere
fb10b01cca
[lldb] Prevent crash when completing ambiguous subcommands
Fix a crash when trying to complete an ambiguous subcommand. Take `set s
tar` for example: for the subcommand `s` there's ambiguity between set
and show. Pressing TAB after this input currently crashes LLDB. The
problem is that we're trying to complete `tar` but give up at `s`
because of the ambiguity. LLDB doesn't expect the completed string to be
shorter than the current string and crashes when trying to eliminate the
common prefix.

rdar://111848598

Differential revision: https://reviews.llvm.org/D154643
2023-07-10 14:50:40 -07:00
Jim Ingham
c1885d2dfa "settings set -g target.load-script-from-symbol-file" shouldn't crash.
-g is specified by passing in nullptr ExecutionContext, but in some
load-script-from-symbol-file specific code, the ExecutionContext was
asked for its Target w/o checking whether the pointer was null.

Fix that and add a test.
2023-07-10 14:40:18 -07:00
Felipe de Azevedo Piovezan
6890ad3f41 [lldb] Disable TestNamespaceLookup in DWARF 5 + dSYM setting
The ordering in which functions are presented to the expression evaluator in
this test setting triggers a known bug in LLDB.

Differential Revision: https://reviews.llvm.org/D154843
2023-07-10 10:10:15 -04:00
David Spickett
fd8929904d [lldb] Fix crash when completing register names after program exit
Previously the following would crash:
(lldb) run
Process 2594053 launched: '/tmp/test.o' (aarch64)
Process 2594053 exited with status = 0 (0x00000000)
(lldb) register read <tab>

As the completer assumed that the execution context would always
have a register context. After a program has finished, it does not.

Split out the generic parts of the test from the x86 specific tests,
and added "register info" to both.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D154413
2023-07-06 08:35:04 +00:00
David Spickett
9b37bfa15e [lldb][AArch64] Handle different default vector length in SVE testing
This test previously ran on QEMU or A64FX both of which can/do have
512 bit SVE by default.

Graviton 3 has 256 bit SVE so the first part of the test failed.

To fix this, probe the supported vector lengths before starting
the test. The first check will use the default vector length and
the rest use either 256 or 128 bit.

Therefore this test will be skipped on a machine with only 128 bit SVE.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D154208
2023-07-04 11:17:54 +01:00
David Spickett
8e76093ae8 [lldb][AArch64] Fix tagged watch test on Graviton 3
During __do_global_dtors_aux glibc sets a flag that is right
next to the global variable. This is done using a store byte.

On QEMU the watchpoints are handled with a finer granularity
than real hardware, so this wasn't a problem. On Graviton 3
(and Mountain Jade, though this test won't run there) watchpoints
look at larger chunks of memory.

This means that the final continue actually stops in  __do_global_dtors_aux
instead of exiting.

We could fix this by padding the global to be away from the flag,
but that is fiddly and it is easier just to remove the watchpoint
before the final continue. We have already verified it worked by that
point.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D154201
2023-07-04 11:16:07 +01:00
David Spickett
518320fd98 [lldb][AArch64] Account for extra libc frames in PAC unwind test
Running this on Amazon Ubuntu the final backtrace is:
```
(lldb) thread backtrace
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
  * frame #0: 0x0000aaaaaaaa07d0 a.out`func_c at main.c:10:3
    frame #1: 0x0000aaaaaaaa07c4 a.out`func_b at main.c:14:3
    frame #2: 0x0000aaaaaaaa07b4 a.out`func_a at main.c:18:3
    frame #3: 0x0000aaaaaaaa07a4 a.out`main(argc=<unavailable>, argv=<unavailable>) at main.c:22:3
    frame #4: 0x0000fffff7b373fc libc.so.6`___lldb_unnamed_symbol2962 + 108
    frame #5: 0x0000fffff7b374cc libc.so.6`__libc_start_main + 152
    frame #6: 0x0000aaaaaaaa06b0 a.out`_start + 48
```
This causes the test to fail because of the extra ___lldb_unnamed_symbol2962 frame
(an inlined function?).

To fix this, strictly check all the frames in main.c then for the rest
just check we find __libc_start_main and _start in that order regardless
of other frames in between.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D154204
2023-07-04 11:15:18 +01:00
Jonas Devlieghere
51944e78bb
[lldb] Add two-level caching in the source manager
We recently saw an uptick in internal reports complaining that LLDB is
slow when sources on network file systems are inaccessible. I looked at
the SourceManger and its cache and I think there’s some room for
improvement in terms of reducing file system accesses:

 1. We always resolve the path.
 2. We always check the timestamp.
 3. We always recheck the file system for negative cache hits.

D153726 fixes (1) but (2) and (3) are necessary because of the cache’s
current design. Source files are cached at the debugger level which
means that the source file cache can span multiple targets and
processes. It wouldn't be correct to not reload a modified or new file
from disk.

We can however significantly reduce the number of file system accesses
by using a two level cache design: one cache at the debugger level and
one at the process level:

 - The cache at the debugger level works the way it does today. There is
   no negative cache: if we can't find the file on disk, we'll try again
   next time the cache is queried. If a cached file's timestamp changes
   or if its path remapping changes, the cached file is evicted and we
   reload it from disk.
 - The cache at the process level is design to avoid accessing the file
   system. It doesn't check the file's modification time. It caches
   negative results, so if a file didn't exist, it doesn't try to reread
   it from disk. Checking if the path remapping changed is cheap
   (doesn't involve checking the file system) and is the only way for a
   file to get evicted from the process cache.

The result of this patch is that LLDB will not show you new content if a
file is modified or created while a process is running. I would argue
that this is what most people would expect, but it is a change from how
LLDB behaves today.

For an average stop, we query the source cache 4 times. With the current
implementation, that's 4 stats to get the modification time, If the file
doesn't exist on disk, that's an additional 4 stats. Before D153726, if
the path starts with a ~ there are another additional 4 calls to
realpath. When debugging sources on a slow (network) file system, this
quickly adds up.

In addition to the two level caching, this patch also adds a source
logging channel and synchronization to the source file cache. The
logging was helpful during development and hopefully will help us triage
issues in the future. The synchronization isn't a new requirement: as
the cache is shared across targets, there is no guarantees that it can't
be accessed concurrently. The patch also fixes a bug where we would only
set the source remapping ID if the un-remapped file didn't exist, which
led to the file getting evicted from the cache on every access.

rdar://110787562

Differential revision: https://reviews.llvm.org/D153834
2023-07-03 14:12:39 -07:00
Felipe de Azevedo Piovezan
379b59d1b0 [lldb] Skip apple accelerator table test in DWARF 5 mode
D68678 added a test that ensures an Apple accelerator lookup is done
efficiently. Since these tables are not used for DWARF 5, we should decorate the
test appropriately.

Differential Revision: https://reviews.llvm.org/D154268
2023-07-03 08:35:55 -04:00
David Spickett
dfbe3a79e2 [lldb] Check that qLaunchGDBServer packet does not return an error
While looking at https://github.com/llvm/llvm-project/issues/61955
I noticed that when we send qLaunchGDBServer we check that we got a response
but not what kind of response it was.

I think this was why the bug reporter saw:
(lldb) run
error: invalid host:port specification: '[192.168.64.2]'

The missing port is because we went down a path we only should have
chosen if the operation succeeded. Since we didn't check, we went ahead
with an empty port number.

To test this I've done the following:
* Make a temporary copy of lldb-server.
* Run that as a platform.
* Remove the copy.
* Attempt to create and run a target.

This fails because the running lldb-server will try to invoke itself
and it no longer exists.

Reviewed By: jasonmolenda

Differential Revision: https://reviews.llvm.org/D153513
2023-06-30 09:12:30 +00:00
Jason Molenda
623e845591 Recognize BSS-only DATA segments as sections that need to be slid
ObjectFileMachO::SetLoadAddress() should allow for a DATA segment
that has no file content to be slid in the vmaddr, it is valid
to have such a section.

Differential Revision: https://reviews.llvm.org/D154037
rdar://99744343
2023-06-29 17:51:41 -07:00
John Harrison
227b2180eb Creating a startDebugging reverse DAP request handler in lldb-vscode.
Adds support for a reverse DAP request to startDebugging. The new request can be used to launch child processes from lldb scripts, for example it would be start forward to configure a debug configuration for a server and a client allowing you to launch both processes with a single debug configuraiton.

Reviewed By: wallace, ivanhernandez13

Differential Revision: https://reviews.llvm.org/D153447
2023-06-29 14:45:57 -04:00
David Spickett
728101f972 Reland "[LLDB] Fix the use of "platform process launch" with no extra arguments"
This reverts commit 3254623d73.

One test has been updated to add the "-s" flag which along with
86fd957af9 should fix the tests on MacOS.

An assert on hijack listener added in that patch was removed, it seems
to be correct on MacOS but not on Linux.
2023-06-29 08:21:42 +00:00
David Spickett
3254623d73 Revert "[LLDB] Fix the use of "platform process launch" with no extra arguments"
This reverts commit cc0fc35854 due to a failure
reported on MacOS.
2023-06-27 14:04:41 +00:00
David Spickett
cc0fc35854 [LLDB] Fix the use of "platform process launch" with no extra arguments
This fixes #62068.

After 8d1de7b34a the following issue appeared:
```
$ ./bin/lldb /tmp/test.o
(lldb) target create "/tmp/test.o"
Current executable set to '/tmp/test.o' (aarch64).
(lldb) platform process launch -s
error: Cannot launch '': Nothing to launch
```

Previously would call target->GetRunArguments when there were no extra
arguments, so we could find out what target.run-args might be.

Once that change started relying on the first arg being the exe,
the fact that that call clears the existing argument list caused the bug.

Instead, have it set a local arg list and append that to the existing
one. Which in this case will just contain the exe name.

Since there's no existing tests for this command I've added a new file
that covers enough to check this issue.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D153636
2023-06-27 07:41:18 +00:00
Jim Ingham
f05e2fb013 Don't allow SBValue::Cast to cast from a smaller type to a larger,
as we don't in general know where the extra data should come from.

Differential Revision: https://reviews.llvm.org/D153657
2023-06-26 16:02:01 -07:00
Jonas Devlieghere
d49caf4afc
[lldb] Add source cache dump and source cache clear subcommand
Add two new source subcommands: source cache dump and source cache
clear. As the name implies the first one dumps the source cache while
the later clears the cache.

This patch was motivated by a handful of (internal) bug reports related
to sources not being available. Right now those issues can be hard to
diagnose. The new commands give users, as well as us as developers, more
insight into and control over the source cache.

Differential revision: https://reviews.llvm.org/D153685
2023-06-26 10:40:08 -07:00
Alex Langford
28fb39f16a [lldb] Adjust for changes in objc runtime
The Objective-C runtime and the shared cache has changed slightly.
Given a class_ro_t, the baseMethods ivar is now a pointer union and may
either be a method_list_t pointer or a pointer to a relative list of
lists. The entries of this relative list of lists are indexes that refer
to a specific image in the shared cache in addition to a pointer offset
to find the accompanying method_list_t. We have to go over each of these
entries, parse it, and then if the relevant image is loaded in the
process, we add those methods to the relevant clang Decl.

In order to determine if an image is loaded, the Objective-C runtime
exposes a symbol that lets us determine if a particular image is loaded.
We maintain a data structure SharedCacheImageHeaders to keep track of
that information.

There is a known issue where if an image is loaded after we create a
Decl for a class, the Decl will not have the relevant methods from that
image (i.e. for Categories).

rdar://107957209

Differential Revision: https://reviews.llvm.org/D153597
2023-06-22 16:42:22 -07:00
Med Ismail Bennani
d10a61c8d2 [lldb/test] Disable TestStackCoreScriptedProcess.py
This patch disables TestStackCoreScriptedProcess.py since it times out
non deterministicly.

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-06-21 14:05:55 -07:00
Med Ismail Bennani
0c5b632071 [lldb] Fix failure in TestStackCoreScriptedProcess on x86_64
This patch should address the failure of TestStackCoreScriptedProcess
that is happening specifically on x86_64.

It turns out that in 1370a1cb5b, I changed the way we extract integers
from a `StructuredData::Dictionary` and in order to get a stop info from
the scripted process, we call a method that returns a `SBStructuredData`
containing the stop reason data.

TestStackCoreScriptedProcess` was failing specifically on x86_64 because
the stop info dictionary contains the signal number, that the `Scripted
Thread` was trying to extract as a signed integer where it was actually
parsed as an unsigned integer. That caused `GetValueForKeyAsInteger` to
return the default value parameter, `LLDB_INVALID_SIGNAL_NUMBER`.

This patch address the issue by extracting the signal number with the
appropriate type and re-enables the test.

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

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-06-21 10:57:13 -07:00
David Spickett
bcfe5a52a3 [lldb] Add register field tables to the "register info" command
This teaches DumpRegisterInfo to generate a table from the register
flags type. It just calls a method on RegisterFlags.

As such, the extra tests are minimal and only show that the intergration
works. Exhaustive formatting tests are done with RegisterFlags itself.

Example:
```
(lldb) register info cpsr
       Name: cpsr
       Size: 4 bytes (32 bits)
    In sets: general (index 0)

| 31 | 30 | 29 | 28 | 27-26 | 25  | 24  | 23  | 22  | 21 | 20 | 19-13 |  12  | 11-10 | 9 | 8 | 7 | 6 | 5 |  4  | 3-2 | 1 | 0  |
|----|----|----|----|-------|-----|-----|-----|-----|----|----|-------|------|-------|---|---|---|---|---|-----|-----|---|----|
| N  | Z  | C  | V  |       | TCO | DIT | UAO | PAN | SS | IL |       | SSBS |       | D | A | I | F |   | nRW | EL  |   | SP |
```

LLDB limits the max terminal width to 80 chars by default.
So to get that full width output you will need to change the "term-width"
setting to something higher.

Reviewed By: jasonmolenda

Differential Revision: https://reviews.llvm.org/D152918
2023-06-21 10:50:31 +00:00
David Spickett
ba85f206fe [lldb] Add "register info" command
This adds a new command that will show all the information lldb
knows about a register.
```
(lldb) register info s0
       Name: s0
       Size: 4 bytes (32 bits)
Invalidates: v0, d0
  Read from: v0
    In sets: Floating Point Registers (index 1)
```

Currently it only allows a single register, and we get the
information from the RegisterInfo structure.

For those of us who know the architecture well, this information
is all pretty obvious. For those who don't, it's nice to have it
at a glance without leaving the debugger.

I hope to have more in depth information to show here in the future,
which will be of wider use.

Reviewed By: jasonmolenda

Differential Revision: https://reviews.llvm.org/D152916
2023-06-21 08:48:18 +00:00
Jaroslav Sevcik
a18b17b1be [lldb] Make the test for D153043 linux-only 2023-06-20 07:57:47 +02:00
Jaroslav Sevcik
7ac0ff562a [lldb] Make test for D153043 independent of external symbols
This removes dependence on the libc abort function.
2023-06-20 07:28:30 +02:00
David Spickett
7e229217f4 [lldb][AArch64] Add thread local storage tpidr register
This register is used as the pointer to the current thread
local storage block and is read from NT_ARM_TLS on Linux.

Though tpidr will be present on all AArch64 Linux, I am soon
going to add a second register tpidr2 to this set.

tpidr is only present when SME is implemented, therefore the
NT_ARM_TLS set will change size. This is why I've added this
as a dynamic register set to save changes later.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D152516
2023-06-19 12:51:58 +01:00
Jonas Devlieghere
ab855530f7
[lldb] Fix Python test formatting (NFC)
All Python files in the LLVM repository were reformatted with Black [1].
Files inside the LLDB subproject were reformatted in 2238dcc393. This
patch updates a handful of tests that were added or modified since then
and weren't formatted with Black.

[1] https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style/68257
2023-06-16 14:51:14 -07:00
Jaroslav Sevcik
af35be55c0 [lldb] Remove unused directive from test for D153043 2023-06-16 12:46:21 +02:00
Jaroslav Sevcik
07b9e6ed0d [lldb] Fix handling of cfi_restore in the unwinder
Currently, lldb's unwinder ignores cfi_restore opcodes for registers
that are not set in the first row of the unwinding info. This prevents
unwinding of failed assertion in Chrome/v8 (https://github.com/v8/v8).
The attached test is an x64 copy of v8's function that failed to unwind
correctly (V8_Fatal).

This patch changes handling of cfi_restore to reset the location if
the first unwind table row does not map the restored register.

Differential Revision: https://reviews.llvm.org/D153043
2023-06-16 08:01:29 +02:00
Adrian Prantl
27fac4a72a Add support for __debug_line_str in Mach-O
This patch resolves an issue that currently accounts for the vast
majority of failures on the matrix bot.

Differential Revision: https://reviews.llvm.org/D152872
2023-06-14 08:37:08 -07:00
Med Ismail Bennani
68d964d024 Revert "[lldb] Fix failure in TestStackCoreScriptedProcess on x86_64"
This reverts commit 4177b49035, since I
landed it by mistake.
2023-06-13 13:45:59 -07:00
Med Ismail Bennani
4177b49035 [lldb] Fix failure in TestStackCoreScriptedProcess on x86_64
This patch should address the failure of TestStackCoreScriptedProcess
that is happening specifically on x86_64.

It turns out that in 1370a1cb5b, I changed the way we extract integers
from a `StructuredData::Dictionary` and in order to get a stop info from
the scripted process, we call a method that returns a `SBStructuredData`
containing the stop reason data.

TestStackCoreScriptedProcess` was failing specifically on x86_64 because
the stop info dictionary contains the signal number, that the `Scripted
Thread` was trying to extract as a signed integer where it was actually
parsed as an unsigned integer. That caused `GetValueForKeyAsInteger` to
return the default value parameter, `LLDB_INVALID_SIGNAL_NUMBER`.

This patch address the issue by extracting the signal number with the
appropriate type and re-enables the test.

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-06-13 13:44:51 -07:00
Augusto Noronha
f94c7ffe46 [lldb] Never print children if the max depth has been reached
When formatting a variable, the max depth would potentially be ignored
if the current value object failed to print itself. Change that to
always respect the max depth, even if failure occurs.

rdar://109855463

Differential Revision: https://reviews.llvm.org/D152409
2023-06-13 11:03:04 -07:00
Michael Buch
fae704bad9 [lldb][test] Re-XFAIL prefer-debug-over-eh-frame.test
This was un-XFAILed in `83cb2123be487302070562c45e6eb4955b22c2b4`
due to D144999. Since then D152540 fixed emission of eh_frame's
on Darwin, causing this test to fail again.

Differential Revision: https://reviews.llvm.org/D152806
2023-06-13 15:08:21 +01:00
Adrian Prantl
59b5581833 Speculative fix for windows test 2023-06-12 14:51:24 -07:00
Michael Buch
73927d574f [lldb][test] incomplete-tag-type.cpp: fix expected error message
Follow up to 133c3eaac0

Differential Revision: https://reviews.llvm.org/D152590
2023-06-12 19:33:10 +01:00
Adrian Prantl
133c3eaac0 Streamline expression parser error messages.
Currently the expression parser prints a mostly useless generic error before printing the compiler error:

  (lldb) p 1+x)
  error: expression failed to parse:
  error: <user expression 18>:1:3: use of undeclared identifier 'x'
  1+x)
     ^

This is distracting and as far as I can tell only exists to work
around the fact that the first "error: " is unconditionally injected
by CommandReturnObject. The solution is not very elegant, but the
result looks much better.

(Partially addresses rdar://110492710)

Differential Revision: https://reviews.llvm.org/D152590
2023-06-12 10:29:48 -07:00
Augusto Noronha
b1ebfc5de3 [lldb] Unconditionally increment depth when printing children
The `target.max-children-depth` setting and `--depth` flag would be
ignored if treating pointer as arrays, fix that by always incrementing
the current depth when printing a new child.

rdar://109855463

Differential Revision: https://reviews.llvm.org/D151950
2023-06-08 13:30:30 -07:00
Vy Nguyen
83cb2123be [lldb][NFC]Update debug (eh-frame) tests to work with new dwarwin MC changes
Details:

D144999 potentially changes the debug format (from compact-unwind to dwarf).
Updated this test to no longer prefer debug-frame over eh-frame to be compatible with the new behaviour

Differential Revision: https://reviews.llvm.org/D152449
2023-06-08 13:11:34 -04:00
Med Ismail Bennani
0dd62ace2e [lldb] Disable variable watchpoints when going out of scope
If we use a variable watchpoint with a condition using a scope variable,
if we go out-of-scope, the watpoint remains active which can the
expression evaluator to fail to parse the watchpoint condition (because
of the missing varible bindings).

This was discovered after `watchpoint_callback.test` started failing on
the green dragon bot.

This patch should address that issue by setting an internal breakpoint
on the return addresss of the current frame when creating a variable
watchpoint. The breakpoint has a callback that will disable the watchpoint
if the the breakpoint execution context matches the watchpoint execution
context.

This is only enabled for local variables.

This patch also re-enables the failing test following e1086384e5.

rdar://109574319

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

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-06-07 16:52:11 -07:00
Med Ismail Bennani
bcfd85a258 [lldb/test] Fix target-label.test on Fuchsia
This shell test also checks some SBAPI functionalities and thus requires
python support.

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-06-06 17:42:09 -07:00
Med Ismail Bennani
431f082a55 [lldb] Disable some tests on windows
This patch skips both `test_completion_target_create_from_root_dir`
introduced in `e896612` and  `target-label.test` introduced in `1e82b20`
since I don't have a windows machine to try to accomodate the filesystem
path style differences for these tests to pass.

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-06-06 16:10:05 -07:00
Jonas Devlieghere
a10019a496
[lldb] Fix "NameError: name 'self' is not defined" when using crashlog -c
This fixes a regression introduced by 27f27d15f6 that results in a
NameError: (name 'self' is not defined) when using crashlog with the -c
option.

rdar://110007391
2023-06-06 15:20:53 -07:00
Med Ismail Bennani
e8966125e2 [lldb/Commands] Fix disk completion from root directory
This patch should fix path completion starting from the root directory.

To do so, this patch adds a special case when setting the search
directory when the completion buffer points to the root directory.

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

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-06-06 10:58:34 -07:00
Med Ismail Bennani
6a9c3e6115 [lldb/Commands] Add support to auto-completion for user commands
This patch should allow the user to set specific auto-completion type
for their custom commands.

To do so, we had to hoist the `CompletionType` enum so the user can
access it and add a new completion type flag to the CommandScriptAdd
Command Object.

So now, the user can specify which completion type will be used with
their custom command, when they register it.

This also makes the `crashlog` custom commands use disk-file completion
type, to browse through the user file system and load the report.

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

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-06-06 10:58:34 -07:00
Med Ismail Bennani
1e82b20118 [lldb/Target] Add ability to set a label to targets
This patch add the ability for the user to set a label for a target.

This can be very useful when debugging targets with the same executables
in the same session.

Labels can be set either at the target creation in the command
interpreter or at any time using the SBAPI.

Target labels show up in the `target list` output, following the target
index, and they also allow the user to switch targets using them.

rdar://105016191

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

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-06-06 10:58:34 -07:00
Zequan Wu
cb9a7c22ee [LLDB][PDB] Fix age field in UUID in PDB file.
There are two age fields in a PDB file. One from the PDB Stream and another one
from the DBI stream.

According to https://randomascii.wordpress.com/2011/11/11/source-indexing-is-underused-awesomeness/#comment-34328,
The age in DBI stream is used to against the binary's age. `Pdbstr.exe` is used
to only increment the age from PDB stream without changing the DBI age. I
also verified this by manually changing the DBI age of a PDB file and let
`windbg.exe` to load it. It shows the following logs before and after changing:

Before:
```
SYMSRV:  BYINDEX: 0xA
         c:\symbols*https://msdl.microsoft.com/download/symbols
         nlaapi.pdb
         D72AA69CD5ABE5D28C74FADB17DE3F8C1
SYMSRV:  PATH: c:\symbols\nlaapi.pdb\D72AA69CD5ABE5D28C74FADB17DE3F8C1\nlaapi.pdb
SYMSRV:  RESULT: 0x00000000
*** WARNING: Unable to verify checksum for NLAapi.dll
DBGHELP: NLAapi - public symbols
        c:\symbols\nlaapi.pdb\D72AA69CD5ABE5D28C74FADB17DE3F8C1\nlaapi.pdb
...
```

After:
```
SYMSRV:  BYINDEX: 0xA
         c:\symbols*https://msdl.microsoft.com/download/symbols
         nlaapi.pdb
         D72AA69CD5ABE5D28C74FADB17DE3F8C1
SYMSRV:  PATH: c:\symbols\nlaapi.pdb\D72AA69CD5ABE5D28C74FADB17DE3F8C1\nlaapi.pdb
SYMSRV:  RESULT: 0x00000000
DBGHELP: c:\symbols\nlaapi.pdb\D72AA69CD5ABE5D28C74FADB17DE3F8C1\nlaapi.pdb - mismatched pdb
SYMSRV:  BYINDEX: 0xB
         c:\symbols*https://chromium-browser-symsrv.commondatastorage.googleapis.com
         nlaapi.pdb
         D72AA69CD5ABE5D28C74FADB17DE3F8C1
SYMSRV:  PATH: c:\symbols\nlaapi.pdb\D72AA69CD5ABE5D28C74FADB17DE3F8C1\nlaapi.pdb
SYMSRV:  RESULT: 0x00000000
DBGHELP: c:\symbols\nlaapi.pdb\D72AA69CD5ABE5D28C74FADB17DE3F8C1\nlaapi.pdb - mismatched pdb
SYMSRV:  BYINDEX: 0xC
         c:\src\symbols*https://msdl.microsoft.com/download/symbols
         nlaapi.pdb
         D72AA69CD5ABE5D28C74FADB17DE3F8C1
SYMSRV:  PATH: c:\src\symbols\nlaapi.pdb\D72AA69CD5ABE5D28C74FADB17DE3F8C1\nlaapi.pdb
SYMSRV:  RESULT: 0x00000000
*** WARNING: Unable to verify checksum for NLAapi.dll
DBGHELP: NLAapi - public symbols
        c:\src\symbols\nlaapi.pdb\D72AA69CD5ABE5D28C74FADB17DE3F8C1\nlaapi.pdb
```

So, `windbg.exe` uses the DBI age to detect mismatched pdb, but it still loads
the pdb even if the age mismatched. Probably lldb should do the same and give
some warnings.

This fixes a bug that lldb can't load some windows system pdbs due to mismatched
uuid.

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D152189
2023-06-06 11:24:50 -04:00
Jim Ingham
df1bb2e65b Restrict the test from 22667e3220
I fixed some long-standing failures in SBTarget::FindGlobalVariables
but the fix is in the the accelerator table lookups.  I fixed it in
the DWARF mappable tables but not everyone uses those, so I had to
restrict the test to systems I know did.
2023-06-01 18:45:45 -07:00
Med Ismail Bennani
78ecb428d5 [lldb/crashlog] Add test for non-symbolicated report crash
Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-06-01 17:50:55 -07:00
Jim Ingham
22667e3220 Fix regex & startsWith name lookup in SBTarget::FindGlobalVariables
There were two bugs here.

eMatchTypeStartsWith searched for "symbol_name" by adding ".*" to the
end of the symbol name and treating that as a regex, which isn't
actually a regex for "starts with". The ".*" is in fact a no-op.  When
we finally get to comparing the name, we compare against whatever form
of the name was in the accelerator table. But for C++ that might be
the mangled name. We should also try demangled names here, since most
users are going the see demangled not mangled names.  I fixed these
two bugs and added a bunch of tests for FindGlobalVariables.

This change is in the DWARF parser code, so there may be a similar bug
in PDB, but the test for this was already skipped for Windows, so I
don't know about this.

You might theoretically need to do this Mangled comparison in

DWARFMappedHash::MemoryTable::FindByName

except when we have names we always chop them before looking them up
so I couldn't see any code paths that fail without that change. So I
didn't add that to this patch.

Differential Revision: https://reviews.llvm.org/D151940
2023-06-01 16:15:06 -07:00
Jim Ingham
620dc1224f Add EXC_SYSCALL to the set of ignorable mach exceptions.
Add some more tests of what exceptions we accept and don't accept.

Differential Revision: https://reviews.llvm.org/D151843
2023-06-01 10:20:47 -07:00
David Blaikie
ed7be0d4d1 lldb: Fix cross-cu-reference test to explicitly request that feature 2023-06-01 00:35:39 +00:00
Timm Bäder
f63155aaa6 [clang] Show line numbers in diagnostic code snippets
Show line numbers to the left of diagnostic code snippets and increase
the numbers of lines shown from 1 to 16.

Differential Revision: https://reviews.llvm.org/D147875
2023-05-31 07:26:03 +02:00
Jim Ingham
14186773e7 Fix SBValue::FindValue for file static variables
This was just a thinko. The API StackFrame::GetVariableList takes a
bool for "get_file_globals" which if true will also find file statics
and file globals. But we only were passing that as true if the
ValueType was eValueTypeVariableGlobal, which meant that we never find
file statics. It's okay if we cast too wide a net when we do
GetVariableList as later on we check against the ValueType to filter
globals from statics.

There was a test that had a whole bunch of globals and tested
FindValue on all of them, but had no statics. So I just made one of
the globals a file static, which verifies the fix.

Differential Revision: https://reviews.llvm.org/D151392
2023-05-30 17:12:35 -07:00
Dave Lee
061a839033 [lldb] Prevent dwim-print from showing kNoResult error
Expression evaluation for `void` valued expressions sets an error using the `kNoResult`
code. Like the `expression` command, `dwim-print` should also not print such errors.

Before:

```
(lldb) dwim-print (void)printf("hi\n")
hi
Error: 'unknown error'
```

After:

```
(lldb) dwim-print (void)printf("hi\n")
hi
```

rdar://109746544

Differential Revision: https://reviews.llvm.org/D151351
2023-05-30 15:38:42 -07:00
Dave Lee
c7eb1b0747 [lldb] Consult summary provider before printing children of root references
When printing the root of a value, if it's a reference its children are unconditionally
printed - in contrast to pointers whose children are only printed if a sufficient
pointer depth is given.

However, the children are printed even when there's a summary provider that says not to.
If a summary provider exists, this change consults it to determine if children should be
printed.

For example, given a variable of type `std::string &`, this change has the following
effect:

Before:

```
(lldb) p string_ref
(std::string &) string_ref = "one two three four five six seven eight nine ten": {
  __r_ = {
    std::__1::__compressed_pair_elem<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__rep, 0, false> = {
      __value_ = {
         = {
          __l = (__data_ = "one two three four five six seven eight nine ten", __size_ = 48, __cap_ = 64, __is_long_ = 1)
          __s = (__data_ = "@\0p\U00000001\0`\0\00\0\0\0\0\0\0\0@", __padding_ = "\x80t<", __size_ = '\0', __is_long_ = '\x01')
          __r = {
            __words ={...}
          }
        }
      }
    }
  }
}
```

After:

```
(lldb) p string_ref
(std::string &) string_ref = "one two three four five six seven eight nine ten"
```

rdar://73248786

Differential Revision: https://reviews.llvm.org/D151748
2023-05-30 15:35:03 -07:00
Muhammad Omair Javaid
898b880308 [LLDB] Update AArch64/Windows XFAIl decorators on TestNamespace.py 2023-05-30 13:06:09 +04:00
Muhammad Omair Javaid
7fb60b0123 [LLDB] Add XFAIL on AArch64/Windows to TestNamespace.py 2023-05-29 18:53:42 +04:00
tcwg
ab05d9134d Revert "[LLDB] Add/Remove xfail for some API tests on Windows"
This reverts commit 6ea1a0d4fc.

It again marks XFAIL LLDB tests failing after
c384fcd3ea
2023-05-29 17:39:36 +04:00
Muhammad Omair Javaid
f2a866170c [LLDB] Fix TestVarPath.py for AArch64 Windows
Since 44bb442 LLDB TestVarPath.py crashes on AArch64 Windows.
GetValueForVariablePath function seems to be triggering the crash.
This patch disable parts of this test causing the crash.

Bug reported upstream:
https://github.com/llvm/llvm-project/issues/62983
2023-05-29 16:17:13 +04:00
Muhammad Omair Javaid
d093111ab1 [LLDB] Remove XFAIL on Windows decorator XPASSes
Following tests are now passing on LLDB AArch64 Windows buildbot:
  lldb-api :: commands/expression/deleting-implicit-copy-constructor/TestDeletingImplicitCopyConstructor.py
  lldb-api :: functionalities/data-formatter/data-formatter-categories/TestDataFormatterCategories.py
  lldb-api :: lang/cpp/constructors/TestCppConstructors.py
  lldb-api :: lang/cpp/namespace/TestNamespace.py
  lldb-api :: lang/cpp/this_class_type_mixing/TestThisClassTypeMixing.py

https://lab.llvm.org/buildbot/#/builders/219/builds/3012

This patch removes XFAIL decorator from all of the above.

Differential Revision: https://reviews.llvm.org/D151268
2023-05-29 12:13:16 +04:00
Jason Molenda
f32d24d577 Revert "[lldb] Disable variable watchpoints when going out of scope"
Reverting https://reviews.llvm.org/D151366 until Ismail has a chance
to look at the ubuntu CI test failures and can reland.

This reverts commit 7c847ac4bd.
2023-05-26 15:32:10 -07:00
Jonas Devlieghere
c0d1128f42
[lldb] Skip instead of XFAIL TestInteractiveScriptedProcess
The test is failing on x86_64 but passing on arm64. Skip until Ismail
can investigate this further.
2023-05-26 13:13:18 -07:00
Daniel Thornburgh
b22965df13 [lldb] Pass CMAKE_SYSROOT through to LLDB shell tests
This allows the LLDB Shell tests to succeed in (e.g. CI) environments where
system libraries are provided hermetically as a sysroot.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D151269
2023-05-26 11:30:33 -07:00
Jonas Devlieghere
a731c5f01d
[lldb] Remove reproducer test suite (NFC)
The reproducer feature as well as the ability to capture or replay tests
with reproducers was removed. This removes the corresponding CMake
target.
2023-05-26 09:33:40 -07:00
Jonas Devlieghere
e31f994642
[lldb] Improve error message when evaluating expression when not stopped
When trying to run an expression after a process has existed, you
currently are shown the following error message:

  (lldb) p strlen("")
  error: Can't make a function caller while the process is running

This error is wrong and pretty uninformative. After this patch, the
following error message is shown:

  (lldb) p strlen("")
  error: unable to evaluate expression while the process is exited: the
  process must be stopped because the expression might require
  allocating memory.

rdar://109731325

Differential revision: https://reviews.llvm.org/D151497
2023-05-26 08:49:58 -07:00
Jason Molenda
c9ee631381 TestStackCoreScriptedProcess.py is timing out, skip it
The x86_64 macOS CI bot is failing because this test
times out.  It was marked as expectedFail earlier today,
but that's not considered a fail so the CI runs are
red.  Skipping it on Darwin for now until Ismail can
look into it.
2023-05-25 19:13:16 -07:00
Med Ismail Bennani
7c847ac4bd [lldb] Disable variable watchpoints when going out of scope
If we use a variable watchpoint with a condition using a scope variable,
if we go out-of-scope, the watpoint remains active which can the
expression evaluator to fail to parse the watchpoint condition (because
of the missing varible bindings).

This was discovered after `watchpoint_callback.test` started failing on
the green dragon bot.

This patch should address that issue by setting an internal breakpoint
on the return addresss of the current frame when creating a variable
watchpoint. The breakpoint has a callback that will disable the watchpoint
if the the breakpoint execution context matches the watchpoint execution
context.

This is only enabled for local variables.

This patch also re-enables the failing test following e1086384e5.

rdar://109574319

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

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-05-25 15:07:09 -07:00
Med Ismail Bennani
0e90ac9c94 Re-revert "[lldb] Move PassthroughScriptedProcess to lldb.scripted_process module"
This reverts commit 429e748395 since it
didn't address the test failures on GreenDragon.

This patch will mark the tests as expected to fail until I can reproduce
the issue and find a solution.

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-05-25 14:00:11 -07:00
Jonas Devlieghere
2238dcc393
[NFC][Py Reformat] Reformat python files in lldb
This is an ongoing series of commits that are reformatting our Python
code. Reformatting is done with `black` (23.1.0).

If you end up having problems merging this commit because you have made
changes to a python file, the best way to handle that is to run `git
checkout --ours <yourfile>` and then reformat it with black.

RFC: https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style

Differential revision: https://reviews.llvm.org/D151460
2023-05-25 12:54:09 -07:00
Med Ismail Bennani
e1086384e5 [lldb] Disable watchpoint_callback.test temporarily on darwin
This test started failing on the green-dragon bot, but after some
investigation, it doesn't have anything to do with Lua.

If we use a variable watchpoint with a condition using a scope variable,
if we go out-of-scope, the watpoint remains active which can the
expression evaluator to fail to parse the watchpoint condition (because
of the missing varible bindings).

For now, we should disable this test until we come up with a fix for it.

rdar://109574319

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-05-24 10:58:40 -07:00
Michael Buch
44bb442fd5 [lldb][DataFormatter] Add dereference support to libstdcpp std::shared_ptr formatter
This mimicks the implementation of the libstdcpp std::unique_ptr
formatter.

This has been attempted several years ago in
`0789722d85cf1f1fdbe2ffb2245ea0ba034a9f94` but was reverted in
`e7dd3972094c2f2fb42dc9d4d5344e54a431e2ce`.

The difference to the original patch is that we now maintain
a `$$dereference$$` member and we only store weak pointers
to the other children inside the synthetic frontend. This is
what the libc++ formatters do to prevent the recursion mentioned
in the revert commit.
2023-05-24 13:01:11 +01:00
Med Ismail Bennani
429e748395 Revert "[lldb] Move PassthroughScriptedProcess to lldb.scripted_process module"
This reverts commit 273a2d337f, since it
might be the cause for `TestStackCoreScriptedProcess` and
`TestInteractiveScriptedProcess` failures on GreenDragon:

https://green.lab.llvm.org/green/job/lldb-cmake/55460/`
2023-05-23 16:03:34 -07:00
Med Ismail Bennani
273a2d337f [lldb] Move PassthroughScriptedProcess to lldb.scripted_process module
This patch moves the `PassthroughScriptedProcess` & `PassthroughScriptedThread`
classes from the `interactive_scripted_process.py` test implementation
to the `lldb.scripted_process` python module.

This class is very versatile so it makes more sense to ship it with the
python module to make it easier for our adopters to derive their class
from it instead of copying it.

During the "migration", I've also noticed some bugs in the
`PassthroughScriptedThread` creation and update, so I also fixed that as
part of this patch.

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

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-05-22 16:14:00 -07:00
Med Ismail Bennani
8f407b8e63 [lldb] Add "Trace" stop reason in Scripted Thread
This patch adds support to eStopReasonTrace to Scripted Threads.

This is necessary when using a Scrited Process with a Scripted Thread
Plan to report a special thread stop reason to the thread plan.

rdar://109425542

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

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-05-22 16:14:00 -07:00
Med Ismail Bennani
1370a1cb5b [lldb] Add support for negative integer to {SB,}StructuredData
This patch refactors the `StructuredData::Integer` class to make it
templated, makes it private and adds 2 public specialization for both
`int64_t` & `uint64_t` with a public type aliases, respectively
`SignedInteger` & `UnsignedInteger`.

It adds new getter for signed and unsigned interger values to the
`StructuredData::Object` base class and changes the implementation of
`StructuredData::Array::GetItemAtIndexAsInteger` and
`StructuredData::Dictionary::GetValueForKeyAsInteger` to support signed
and unsigned integers.

This patch also adds 2 new `Get{Signed,Unsigned}IntegerValue` to the
`SBStructuredData` class and marks `GetIntegerValue` as deprecated.

Finally, this patch audits all the caller of `StructuredData::Integer`
or `StructuredData::GetIntegerValue` to use the proper type as well the
various tests that uses `SBStructuredData.GetIntegerValue`.

rdar://105575764

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

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-05-22 16:14:00 -07:00
Muhammad Omair Javaid
a7c7c61af6 [LLDB] Fix missing import in TestInterruptBacktrace.py
This fixed missing import of lldbsuite.test.decorators in TestInterruptBacktrace.py.
2023-05-22 15:47:05 +04:00
Muhammad Omair Javaid
5dfec676c3 [LLDB] Skip TestInterruptBacktrace.py on Arm/Linux
TestInterruptBacktrace.py started randonmly failing on Arm/Linux
buildbot since e19387e693. This patch marks it skipped.

Differential Revision: https://reviews.llvm.org/D150236
2023-05-22 14:53:35 +04:00
Michael Buch
55acb70b21 [lldb][cmake] Allow specifying custom libcxx for tests in standalone builds
Standalone builds currently do not set the `LLDB_HAS_LIBCXX`,
`LIBCXX_LIBRARY_DIR`, `LIBCXX_GENERATED_INCLUDE_DIR`.
These are necessary for API tests with `USE_LIBCPP` to run against
a custom built libcxx. Thus on all buildbots using standalone builds
(most notably the public swift-ci), the API tests always run against
the libcxx headers in the system SDK.

This patch introduces a new cmake variable `LLDB_TEST_LIBCXX_ROOT_DIR`
that allows us to point the tests in standalone builds to a custom
libcxx directory.

Since the user can control the libcxx location we can hard error if
no such custom libcxx build exists.

Differential Revision: https://reviews.llvm.org/D150954
2023-05-20 12:07:48 +01:00
Med Ismail Bennani
dfdd898862 [lldb/crashlog] Load inlined symbol into interactive crashlog
Sometimes, crash reports come with inlined symbols. These provide the
exact stacktrace from the user binary.

However, when investigating a crash, it's very likely that the images related
to the crashed thread are not available on the debugging user system or
that the versions don't match. This causes interactive crashlog to show
a degraded backtrace in lldb.

This patch aims to address that issue, by parsing the inlined symbols
from the crash report and load them into lldb's target.

This patch is a follow-up to 27f27d1, focusing on inlined symbols
loading from legacy (non-json) crash reports.

To do so, it updates the stack frame regular expression to make the
capture groups more granular, to be able to extract the symbol name, the
offset and the source location if available, while making it more
maintainable.

So now, when parsing the crash report, we build a data structure
containing all the symbol information for each stackframe. Then, after
launching the scripted process for interactive mode, we write a JSON
symbol file for each module, only containing the symbols that it contains.

Finally, we load the json symbol file into lldb, before showing the user
the process status and backtrace.

rdar://97345586

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

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-05-19 20:08:18 -07:00
Adrian Prantl
85cb7fbc07 Relax test 2023-05-19 10:52:00 -07:00
Stefan Gränitz
0b6264738f [lldb][gnustep] Add minimal GNUstepObjCRuntime plugin for LanguageTypeObjC on non-Apple platforms
This is the next patch after D146058. We can now parse expressions to print instance variables from ObjC classes. Until now the expression parser would bail out with an error like this:
```
error: expression failed to parse:
error: Error [IRForTarget]: Couldn't find Objective-C indirect ivar symbol OBJC_IVAR_$_TestObj._int
```

Reviewed By: aprantl

Differential Revision: https://reviews.llvm.org/D146154
2023-05-17 13:56:01 +02:00
Stefan Gränitz
4241ac542d [lldb][gnustep] Add basic test and infrastructure for GNUstep ObjC runtime
This patch adds test infrastructure to utilize the GNUstep runtime in the LLDB test suite and adds coverage for features that already work on Linux. These seem accidental in parts, but it's a good early baseline. On Windows nothing works yet. Please find the repository for the GNUstep ObjC runtime here: https://github.com/gnustep/libobjc2

GNUstep support is disabled by default. CMake configuration involves two variables:
* `LLDB_TEST_OBJC_GNUSTEP=On` enables GNUstep support in the test suite. It requires the libobjc2 shared library and headers to be found.
* `LLDB_TEST_OBJC_GNUSTEP=Off` disables GNUstep support in the test suite and resets associated cache values if necessary (default).
* `LLDB_TEST_OBJC_GNUSTEP_DIR` allows to pass a custom installation root.

Differential Revision: https://reviews.llvm.org/D146058
2023-05-17 10:37:38 +02:00
Daniel Paoliello
f8499d5709 Emit the correct flags for the PROC CodeView Debug Symbol
The S_LPROC32_ID and S_GPROC32_ID CodeView Debug Symbols have a flags
field which LLVM has had the values for (in the ProcSymFlags enum) but
has never actually set.

These flags are used by Microsoft-internal tooling that leverages debug
information to do binary analysis.

Modified LLVM to set the correct flags:

- ProcSymFlags::HasOptimizedDebugInfo - always set, as this indicates that
debug info is present for optimized builds (if debug info is not emitted
for optimized builds, then LLVM won't emit a debug symbol at all).
- ProcSymFlags::IsNoReturn and ProcSymFlags::IsNoInline - set if the
function has the NoReturn or NoInline attributes respectively.
- ProcSymFlags::HasFP - set if the function requires a frame pointer (per
TargetFrameLowering::hasFP).

Per discussion in review, XFAIL'ing lldb test until someone working on
lldb has a chance to look at it.

Differential Revision: https://reviews.llvm.org/D148761
2023-05-16 10:58:10 -07:00
Michael Buch
3c30f22400 [lldb][DWARFASTParserClang] Don't create unnamed bitfields to account for vtable pointer
**Summary**

When filling out the LayoutInfo for a structure with the offsets
from DWARF, LLDB fills gaps in the layout by creating unnamed
bitfields and adding them to the AST. If we don't do this correctly
and our layout has overlapping fields, we will hat an assertion
in `clang::CGRecordLowering::lower()`. Specifically, if we have
a derived class with a VTable and a bitfield immediately following
the vtable pointer, we create a layout with overlapping fields.

This is an oversight in some of the previous cleanups done around this
area.

In `D76808`, we prevented LLDB from creating unnamed bitfields if there
was a gap between the last field of a base class and the start of a bitfield
in the derived class.

In `D112697`, we started accounting for the vtable pointer. The intention
there was to make sure the offset bookkeeping accounted for the
existence of a vtable pointer (but we didn't actually want to create
any AST nodes for it). Now that `last_field_info.bit_size` was being
set even for artifical fields, the previous fix `D76808` broke
specifically for cases where the bitfield was the first member of a
derived class with a vtable (this scenario wasn't tested so we didn't
notice it). I.e., we started creating redundant unnamed bitfields for
where the vtable pointer usually sits. This confused the lowering logic
in clang.

This patch adds a condition to `ShouldCreateUnnamedBitfield` which
checks whether the first field in the derived class is a vtable ptr.

**Testing**

* Added API test case

Differential Revision: https://reviews.llvm.org/D150591
2023-05-16 11:18:09 +01:00
Muhammad Omair Javaid
617c31c6a1 [LLDB] Fix typo in TestDataFormatterSynthVal.py
This is follow up to 039b28e14e to fix a typo to make sure skipped
part of test is only skipped for AArch64 Windows platform.
2023-05-16 10:13:06 +04:00
Muhammad Omair Javaid
039b28e14e [LLDB] Fix TestDataFormatterSynthVal.py for AArch64/Windows
Since 44363f2 various tests have started passing but introduced a
expression evaluation failure in TestDataFormatterSynthVal.py.
This patch marks the expression evaluation part as skipped while rest
of the test passes.
This patch aslo introduces a new helper isAArch64Windows in lldbtest.py.
2023-05-16 00:14:20 +04:00
Jeffrey Tan
25159ee3af Fix libstdc++ data formatter for reference/pointer to std::string
This patch fixes libstdc++ data formatter for reference/pointer to std::string.
The failure testcases are added which succeed with the patch.

Differential Revision: https://reviews.llvm.org/D150313
2023-05-12 10:09:58 -07:00
Leandro Lupori
b58dd9230e [lldb-vscode] Skip restart tests on ARM
These tests always time out on ARM buildbot. Disabling them for
now, until https://github.com/llvm/llvm-project/issues/62684 is
fixed.
2023-05-12 13:52:17 -03:00
Benjamin Kramer
5130e049ff [lldb] Don't write to source directory in test 2023-05-12 12:26:29 +02:00
Jim Ingham
e19387e693 We can't let GetStackFrameCount get interrupted or it will give the
wrong answer. Plus, it's useful in some places to have a way to force
the full stack to be created even in the face of
interruption. Moreover, most of the time when you're just getting
frames, you don't need to know the number of frames in the stack to
start with. You just keep calling
Thread::GetStackFrameAtIndex(index++) and when you get a null
StackFrameSP back, you're done. That's also more amenable to
interruption if you are doing some work frame by frame.

So this patch makes GetStackFrameCount always return the full count,
suspending interruption. I also went through all the places that use
GetStackFrameCount to make sure that they really needed the full stack
walk. In many cases, they did not. For instance frame select -r 10 was
getting the number of frames just to check whether cur_frame_idx + 10
was within the stack. It's better in that case to see if that frame
exists first, since that doesn't force a full stack walk, and only
deal with walking off the end of the stack if it doesn't...

I also added a test for some of these behaviors.

Differential Revision: https://reviews.llvm.org/D150236
2023-05-11 14:48:54 -07:00
Adrian Prantl
1585ee1077 Relax test to not rely on the variable being optimized out 2023-05-11 13:38:19 -07:00
Dave Lee
efbd587040 [lldb] Correct elision of line zero in mixed disassembly
When `disassemble --mixed` is run, do not show source for line zero, as intended.

Differential Revision: https://reviews.llvm.org/D150383
2023-05-11 13:24:32 -07:00
Jorge Gorbe Moya
1b11034c67 [lldb-vscode] Fix handling of RestartRequest arguments.
According to the spec, RestartRequest has an optional "arguments" field, which
is a RestartArguments object. RestartArguments has its own optional "arguments"
field, which is a (LaunchRequestArguments | AttachRequestArguments) object. So
we need to to the "arguments" lookup twice to get to the actual launch
arguments.

Differential Revision: https://reviews.llvm.org/D150392
2023-05-11 13:11:38 -07:00
Jim Ingham
7b5dc63fc4 When the Debugger runs HandleProcessEvent it should allow
selecting the "Most relevant" frame.

If you don't do that, then the correct frame gets selected, but it
happens AFTER the frame info gets printed in the stop message, so
you don't see the selected frame.

The test for this hid the issue because it ran `frame info` and
checked the result of that.  That happens after the recognizer selects
the frame, and so it was right.  But if the recognizer is working
correctly it will have already done the same printing in the stop
message, and this way we also verify that the stop message was right.

Differential Revision: https://reviews.llvm.org/D150315
2023-05-10 15:40:40 -07:00
Dave Lee
765237779c [lldb] Prevent mutation of CommandAlias::GetOptionArguments
Fix a mutation of `CommandAlias::m_option_args_sp`, which resulted in cases where
aliases would fail to run on second, and subsequent times.

For example, an alias such as:

```
command alias p1 p 1
```

When run the second time, the following error would be reported to the user:

```
error: expression failed to parse:
error: <user expression 1>:1:1: expression is not assignable
--  1
^   ~
```

To fix this, `CommandAlias::Desugar` now constructs options to a freshly constructed
vector, rather than by appending to the results of `GetOptionArguments`.

rdar://107770836

Differential Revision: https://reviews.llvm.org/D150078
2023-05-08 09:45:26 -07:00
Adrian Prantl
ba902efa49 Skip test when compiling with older versions of clang 2023-05-08 09:24:40 -07:00
Saleem Abdulrasool
5014830ede ObjectFile: introduce a COFF object file plugin
Windows uses COFF as an object file format and PE/COFF as an executable
file format. They are subtly different and certain elements of a COFF
file may not be present in an executable. Introduce a new plugin to add
support for the COFF object file format which is required to support
loading of modules built with -gmodules. This is motivated by Swift
which serialises debugging information into a PCM which is a COFF object
file.

Differential Revision: https://reviews.llvm.org/D149987
Reviewed By: bulbazord
2023-05-07 12:40:44 -07:00
Jonas Devlieghere
a136148d8f
[lldb] Use Haswell instead of arm64 in TestUniversal64
The architecture doesn't really matter for the test, at least not until
the dynamic loader can load these fat64 binaries. Use Hawell instead of
arm64 to support older bots that don't know about Apple Silicon triples.
2023-05-05 09:01:23 -07:00
LU Hongyi
16c2872d7b Reland "[lldb][DWARFExpression] Fix DW_OP_div to use signed division"
This patch resolves an issue where a value
is incorrectly displayed if it is represented
by DW_OP_div.

This issue is caused by lldb evaluating
operands of DW_OP_div as unsigned
and performed unintended unsigned
division.

This issue is resolved by creating two
temporary signed scalar and performing
signed division.

(Addresses GH#61727)

Differential Revision: https://reviews.llvm.org/D147370
2023-05-05 06:45:07 -04:00
Jason Molenda
2e16e41b28 Add AArch64 MASK watchpoint support in debugserver
Add suport for MASK style watchpoints on AArch64 in debugserver
on Darwin systems, for watching power-of-2 sized memory ranges.
More work needed in lldb before this can be exposed to the user
(because they will often try watching memory ranges that are not
exactly power-of-2 in size/alignment) but this is the first part
of adding that capability.

Differential Revision: https://reviews.llvm.org/D149792
rdar://108233371
2023-05-04 13:23:51 -07:00
Jim Ingham
c2be702104 Allow scripted thread plans to modify the thread stop description when
they are completed.
2023-05-03 10:52:12 -07:00
Muhammad Omair Javaid
6ea1a0d4fc [LLDB] Add/Remove xfail for some API tests on Windows
This patch add or removes XFAIL decorator from various tests which were marked
xfail for windows.

since 44363f2 various tests have started passing but introduced a couple of new failures.
Weight is in favor of new XPasses and I have removed XFail decorator from them. Also
some new tests have started failing for which we need to file separate bugs. I have
marked them xfail for now and will add the bug id after investigating the issue.

Differential Revision: https://reviews.llvm.org/D149235
2023-05-03 04:45:55 +05:00
Jorge Gorbe Moya
2b6c5bb995 [lldb-vscode] Implement RestartRequest
This is an optional request, but supporting it makes the experience
better when re-launching a big binary that takes significant time to
parse: instead of tearing down and re-create the whole session we just
need to kill the current process and launch a new one.

Some non-obvious comments that might help review this change:

* After killing the process, we get an "exited" event for it. Because
  the process no longer exists some interesting things can occur that
  manifest as flaky failures if not dealt with:

  - `EventIsProcessEvent` relies on `SBEvent::GetBroadcasterClass`,
    which can crash if the broadcaster is no longer there: the event
    only holds a weak_ptr to its broadcaster, and `GetBroadcasterClass`
    uses it without checking.

    Other `EventIs*` functions look at the flavor of the EventData, so I
    have modified EventIsProcessEvent to do that.

  - We keep the PID of the old process so we can detect its "exited"
    event and not terminate the whole session. But sometimes the
    SBProcess we get from the event won't have a PID, for some reason.

* I have factored out the code to launch a process out to a new
  LaunchProcess function, so it can be used from both `request_launch`
  and `request_restart`.

* The restart_runInTerminal test has the same problem with debug builds
  as the original runInTerminal test: when attaching to the launcher
  instance of lldb-vscode it takes a long time to parse its debug info.
  I have used the same workaround to disable that particular test for
  debug builds.

Differential Revision: https://reviews.llvm.org/D147831
2023-05-02 14:50:39 -07:00
Michael Buch
ad74df12b8 Revert "[lldb][DWARFExpression] Fix DW_OP_div to use signed division"
This reverts commit e15d6b520e.

Newly added test fails on Darwin platforms and arm.

Differential Revision: https://reviews.llvm.org/D147370
2023-05-02 15:36:56 -04:00
Adrian Prantl
419bc85675 Revert "Add amissing REQUIRES: to test"
This reverts commit 1f74964b40.

The googles. They do nothing!
2023-05-02 11:41:58 -07:00
Adrian Prantl
1f74964b40 Add amissing REQUIRES: to test 2023-05-02 11:16:04 -07:00
Ilya Kuklin
8be139fc12 [lldb] Add settings for expression evaluation memory allocations.
Expression evaluation allocates memory for storing intermediate data during evaluation. For it to work properly it has to be allocated within target's available address space, for example within first 0xFFFF bytes for the 16-bit MSP430. The memory for such targets can be very tightly packed, but not all targets support GetMemoryRegionInfo API to pick an unused region, like MSP430 with MSPDebug GDB server.

These settings allow the programmer to manually pick precisely where and how much memory to allocate for expression evaluation in order not to overlap with existing data in process memory.

Reviewed By: bulbazord

Differential Revision: https://reviews.llvm.org/D149262
2023-05-02 11:02:44 -07:00
Michael Buch
52882de0e6 [lldb][test] TestCPP20Standard.py: make it a libc++ test
We just want to test whether the language switch works.
This is easier to control for libc++, since for bots building
the tests against libstdc++ we might not have the necessary
`<compare>` header available currently.
2023-05-02 07:38:53 -04:00
LU Hongyi
e15d6b520e [lldb][DWARFExpression] Fix DW_OP_div to use signed division
This patch resolves an issue where a value
is incorrectly displayed if it is represented
by DW_OP_div.

This issue is caused by lldb evaluating
operands of DW_OP_div as unsigned
and performed unintended unsigned
division.

This issue is resolved by creating two
temporary signed scalar and performing
signed division.

(Addresses GH#61727)

Differential Revision: https://reviews.llvm.org/D147370
2023-05-02 07:38:52 -04:00
Jonas Devlieghere
76fb334302
[lldb] Remove TestExternalEditor.test
Remove TestExternalEditor.test as the code to open the transcript in an
external editor is conditional on lldb running in a graphical session.
As a result this test passes locally but not on the bots.
2023-05-01 21:25:14 -07:00
Jorge Gorbe Moya
d69518b4e5 Re-land "[lldb] Make the libcxx unique_ptr prettyprinter support custom deleters."
This reverts commit 4535112010.
2023-05-01 16:19:01 -07:00
Alex Langford
e53e1de57e [lldb] Change ObjectValueDictionary to use a StringMap
llvm has a structure for maps where the key's type is a string. Using
that also means that the keys for OptionValueDictionary don't stick
around forever in ConstString's StringPool (even after they are gone).

The only thing we lose here is ordering: iterating over the map where the keys
are ConstStrings guarantees that we iterate in alphabetical order.
StringMap makes no guarantees about the ordering when you iterate over
the entire map.

Differential Revision: https://reviews.llvm.org/D149482
2023-05-01 16:17:24 -07:00
Jorge Gorbe Moya
4535112010 Revert "[lldb] Make the libcxx unique_ptr prettyprinter support custom deleters."
This reverts commit d366da97bd.
2023-05-01 14:14:09 -07:00
Jonas Devlieghere
b12b35ad4b
[lldb] Add debugger.external-editor setting
Add a new setting (debugger.external-editor) to specify an external
editor. The setting takes precedence over the existing
LLDB_EXTERNAL_EDITOR environment variable.

Differential revision: https://reviews.llvm.org/D149565
2023-05-01 14:11:11 -07:00
Jorge Gorbe Moya
d366da97bd [lldb] Make the libcxx unique_ptr prettyprinter support custom deleters.
The unique_ptr prettyprinter calls `GetValueOfLibCXXCompressedPair`,
which looks for a `__value_` child. However, when the second value in
the compressed pair is not an empty class, there are two `__value_`
children because `__compressed_pair` derives twice from
`__compressed_pair_elem`, one for each member of the pair. And then the
lookup fails because it's ambiguous.

This patch makes the following changes:

- Rename `GetValueOfLibCXXCompressedPair` to
  `GetFirstValueOfLibCXXCompressedPair`, and add a similar function to
  get the second value. Put both functions in
  Plugin/Language/CPlusPlus/LibCxx.cpp because it seems inappropriate to
  have libcxx-specific helpers separate from all the libcxx-dependent
  code.

- Read the second value of the `__ptr_` pair and display a "deleter"
  child in the unique_ptr synthetic child provider, when available.

- Add a test case for the non-empty deleter case.

Differential Revision: https://reviews.llvm.org/D148662
2023-05-01 13:08:04 -07:00
Stefan Gränitz
64a2520bac [lldb][ObjectFileELF] Support AArch32 in ApplyRelocations
Allow the ObjectFileELF plugin to resolve R_ARM_ABS32 relocations from AArch32 object files. This fixes https://github.com/llvm/llvm-project/issues/61948

The existing architectures work with RELA-type relocation records that read addend from the relocation entry. REL-type relocations in AArch32 store addend in-place.
The new function doesn't re-use ELFRelocation::RelocAddend32(), because the interface doesn't match: in addition to the relocation entry we need the actual target section memory.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D147642
2023-04-29 17:34:39 +02:00
Jason Molenda
5679379cc7 Refactor and generalize AArch64 watchpoint support in debugserver
Refactor the debugserver watchpiont support in anticipating of
adding support for AArch64 MASK hardware watchpoints to watch
larger regions of memory.  debugserver already had support for
handling a request to watch an unaligned region of memory up
to 8 bytes using Byte Address Select watchpoints - it would split
an unaligned watch request into two aligned doublewords that
could be watched with two hardware watchpoints using the BAS
specification.

This patch generalizes that code for properly aligning, and
possibly splitting, a watchpoint request into two hardware watchpoints
to handle any size request.  And separates out the specifics
about BAS watchpoints into its own method, so a sibling method
for MASK watchpoints can be dropped in next.

Differential Revision: https://reviews.llvm.org/D149040
rdar://108233371
2023-04-28 18:24:38 -07:00
Jason Molenda
7777b305bf Fix CI failure - this depended on constants only defined on arm64 macs 2023-04-26 15:45:29 -07:00
Jason Molenda
6b6bac2cd8 Fix off-by-one error in armv7 mach-o corefile register context
The sanity check on the size of the register context we found in
the corefile was off by one, so lldb would not add the register
contents.  Add a test case to ensure it doesn't regress.

Differential Revision: https://reviews.llvm.org/D149224
rdar://108306070
2023-04-26 13:06:07 -07:00
Alex Langford
7590cc9088 [lldb] Skip Watchpoint/ExpressionLanguage.test on Windows
This test fails on the aarch64-windows bots unfortunately. Mark as
unsupported.

Context: https://lab.llvm.org/buildbot/#/builders/219/builds/2389
2023-04-26 12:40:03 -07:00
Alex Langford
c997acb97a [lldb] Add support for specifying language when setting watchpoint by expression
This is useful in contexts where you have multiple languages in play:
You may be stopped in a frame for language A, but want to set a watchpoint
with an expression using language B. The current way to do this is to
use the setting `target.language` while setting the watchpoint and
unset it after the watchpoint is set, but that's kind of clunky and
somewhat error-prone. This should add a better way to do this.

rdar://108202559

Differential Revision: https://reviews.llvm.org/D149111
2023-04-26 10:24:28 -07:00
Med Ismail Bennani
f8d6542e87 [lldb/test] Fix test failure from missing decorator
This should fix a test failure in TestInteractiveScriptedProcess.py
caused by a missing decorator added in d0d902d.

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2023-04-25 16:08:55 -07:00
Med Ismail Bennani
d0d902df06 [lldb/test] Disable Interactive Scripted Process test unless Darwin
Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2023-04-25 16:00:58 -07:00
Med Ismail Bennani
30f4adfd4d [lldb/test] Enable threads for TestInteractiveScriptedProcess.py (NFC)
Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2023-04-25 15:19:57 -07:00
Med Ismail Bennani
d3a6b93135 [lldb/test] Consolidate interactive scripted process debugging test
This patch improve the interactive scripted process debugging test by
adding test coverage for child process breakpoint setting and execution
state change.

This patch introduces a new test case for a multiplexed launch, which
does the same thing as the simple passthrough launch. After the
multiplexer process stops, this new test launches 2 other scripted processes
that should contain respectively the even and odd threads from the
multiplexer scripted process.

Then, we create a breakpoint on one the child scripted process, make
sure it was set probably on the child process, the multiplexer process
and the real process. This also test the breakpoint name tagging at the
multiplexer level.

Finally, we resume the child process that had a breakpoint and make sure
that all the processes has stopped at the right location.

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2023-04-25 15:03:45 -07:00
Med Ismail Bennani
e31d0c20e4 [lldb] Improve breakpoint management for interactive scripted process
This patch improves breakpoint management when doing interactive
scripted process debugging.

In other to know which process set a breakpoint, we need to do some book
keeping on the multiplexer scripted process. When initializing the
multiplexer, we will first copy breakpoints that are already set on the
driving target.

Everytime we launch or resume, we should copy breakpoints from the
multiplexer to the driving process.

When creating a breakpoint from a child process, it needs to be set both
on the multiplexer and on the driving process. We also tag the created
breakpoint with the name and pid of the originator process.

This patch also implements all the requirement to achieve proper
breakpoint management. That involves:

- Adding python interator for breakpoints and watchpoints in SBTarget
- Add a new `ScriptedProcess.create_breakpoint` python method

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2023-04-25 15:03:15 -07:00
Med Ismail Bennani
6cf668016e [lldb] Add an example of interactive scripted process debugging
This patch is a proof of concept that shows how a scripted process could
be used with real process to perform interactive debugging.

In this example, we run a process that spawns 10 threads.
That process gets launched by an intermediary scripted process who's job
is to intercept all of it's process events and dispatching them
back either to the real process or to other child scripted processes.

In this example, we have 2 child scripted processes, with even and odd
thread indices. The goal is to be able to do thread filtering and
explore the various interactive debugging approaches, by letting a child
process running when stopping the other process and inspecting it.
Another approach would be to have the child processes execution in-sync
to force running every child process when one of them starts running.

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2023-04-25 15:02:34 -07:00
Michael Buch
53791896de [lldb][test] TestCPP20Standard.py: skip on older compilers
Requires C++20 support (at least for the spaceship operator).
Seems to work back to Clang-11
2023-04-24 12:05:20 -04:00
Michael Buch
b4cae6bf53 [lldb][tests] TestPreferredName.py: add missing import 2023-04-24 08:40:32 -04:00
Michael Buch
b767b05041 [lldb][tests] TestPreferredName.py: Fix for older compilers
This only works as of D145803, where we re-point the
`DW_AT_type` based on existence of `[[clang::preferred_name]]`
2023-04-24 08:33:07 -04:00
Jason Molenda
d9bc7f7844 TestSTL was marked as skipped unconditionally in 2018, undo
It was avoiding a crash at the time on macOS, apparently, and
it skipped the test on all platforms.  This test passes for me
now on macOS, let's remove the skip and see how the bots go.
2023-04-21 13:17:43 -07:00
Jonas Devlieghere
c1d55d26d3
[lldb] Let Mangled decide whether a name is mangled or not
We have a handful of places in LLDB where we try to outsmart the logic
in Mangled to determine whether a string is mangled or not. There's at
least one place (*) where we are getting this wrong and causes a subtle
bug. The `cstring_is_mangled` is cheap enough that we should always rely
on it to determine whether a string is mangled or not.

(*) `ObjectFileMachO` assumes that a symbol that starts with a double
underscore (such as `__pthread_kill`) is mangled. That's mostly
harmless, until you use `function.name-without-args` in the frame
format. The formatter calls `Symbol::GetNameNoArguments()` which is a
wrapper around `Mangled::GetName(ePreferDemangledWithoutArguments)`. The
latter will first try using the appropriate language plugin to get the
demangled name without arguments, and if that fails, falls back to
returning the demangled name. Because we forced Mangled to treat the
symbol as a mangled name (even though it's not) there's no demangled
name. The result is that frames don't show any symbol at all.

Differential revision: https://reviews.llvm.org/D148846
2023-04-21 10:23:24 -07:00
David Spickett
c9083bea16 [LLDB] Don't print register fields when asked for a specific format
Previously if a register had fields we would always print them after the
value if the register was asked for by name.
```
(lldb) register read MDCR_EL3
MDCR_EL3 = 0x00000000
         = {
             ETBAD = 0
<...>
             RLTE = 0
           }
```
This can be quite annoying if there are a whole lot of fields but you
want to see the register in a specific format.
```
(lldb) register read MDCR_EL3 -f i
MDCR_EL3 = 0x00000000   unknown     udf    #0x0
         = {
             ETBAD = 0
<...lots of fields...>
```
Since it pushes the interesting bit far up the terminal. To solve this,
don't print fields if the user passes --format. If they're doing that
then I think it's reasonable to assume they know what they want and only
want to see that output.

This also gives users a way to silence fields, but not change the format.
By doing `register read foo -f x`. In case they are not useful or perhaps
they are trying to work around a crash.

I have customised the help text for --format for register read to explain this:
```
-f <format> ( --format <format> )
     Specify a format to be used for display. If this is set, register fields will not be dispayed.
```

Reviewed By: jasonmolenda

Differential Revision: https://reviews.llvm.org/D148790
2023-04-21 11:47:05 +00:00
David Spickett
dbc34e2bed [LLDB] Discard register flags where the size doesn't match the register
In the particular case I was looking at I autogenerated a 128 bit set
of flags that is only 64 bit. This doesn't crash lldb but it was certainly
not expected.

I suspect that we would have crashed if the top 64 bits weren't
marked as unused (or at least invoked some very undefined behaviour).

When this happens, log the details and ignore the flags. Like this:
```
Size of register flags TTBR0_EL1_flags (16 bytes) for register TTBR0_EL1 does not match the register size (8 bytes). Ignoring this set of flags.
```

Turns out a few of the tests relied on this bug so I have updated
them and added a specific test for this case.

Reviewed By: jasonmolenda

Differential Revision: https://reviews.llvm.org/D148715
2023-04-20 08:36:49 +00:00
Jason Molenda
53430bfd5c Remove hardcoded address bits in ABIMacOS_arm64
A default number of addressing bits was hardcoded in
ABIMacOSX_arm64::FixAddress while we updated different
environments to fetch the value dynamically.  Remove
the old hardcoded value.

Differential Revision: https://reviews.llvm.org/D148603
rdar://108068497
2023-04-18 13:01:49 -07:00
Dave Lee
773d9c3604 [lldb] Add more asserts to TestExec
If this test fails, the error message isn't helpful:

```
self.assertEqual(len(threads), 1,
AssertionError: 0 != 1 : Stopped at breakpoint in exec'ed process
```

This change adds asserts to verify that:
1. The process is stopped
2. For each thread, that the stop reason is None, or Breakpoint

The latter will indicate if execution has stopped for some other reason, and if so what
that reason is.

Differential Revision: https://reviews.llvm.org/D148588
2023-04-17 18:43:42 -07:00
Jorge Gorbe Moya
3c91d01634 [lldb] Build libcxx unique_ptr and shared_ptr test programs with -glldb.
The functionality added by https://reviews.llvm.org/D145803 is gated by
lldb tuning, so we need to build the test programs with `-glldb` to make
these tests print the expected preferred name.

Differential Revision: https://reviews.llvm.org/D148582
2023-04-17 17:03:29 -07:00
Ilya Kuklin
81beb15d7e [lldb] Add support for MSP430 in LLDB.
Add MSP430 to the list of available targets, implement MSP430 ABI, add support for debugging targets with 16-bit address size.

The update is intended for use with MSPDebug, a GDB server implementation for MSP430.

Reviewed By: bulbazord, DavidSpickett

Differential Revision: https://reviews.llvm.org/D146965
2023-04-17 16:03:35 -07:00
Michael Buch
1414a5bdfe [lldb][DataFormatter] Fix libcxx std::deque formatter for references and pointers
(Addresses GH#62153)

The `SBType` APIs to retrieve details about template arguments,
such as `GetTemplateArgumentType` or `GetTemplateArgumentKind`
don't "desugar" LValueReferences/RValueReferences or pointers.
So when we try to format a `std::deque&`, the python call to
`GetTemplateArgumentType` fails to get a type, leading to
an `element_size` of `0` and a division-by-zero python exception
(which gets caught by the summary provider silently). This leads
to the contents of such `std::deque&` to be printed incorrectly.

This patch dereferences the reference/pointer before calling
into the above SBAPIs.

**Testing**

* Add API test

Differential Revision: https://reviews.llvm.org/D148531
2023-04-17 21:31:30 +01:00
Jonas Devlieghere
f40ed1f619
[lldb] Fix TestObjectFileJSON and TestSymbolFileJSON
- Separate the two test and only have TestSymbolFileJSON rely on strip.
 - Use different file names to make sure LLDB reloads the module.

This should address all the post commit review from D148062.
2023-04-17 12:01:24 -07:00
Anton Korobeynikov
8456120623 Revert "[lldb] Add support for MSP430 in LLDB."
This reverts commit 82c02b733c.

Apparently, the original patch was not rebased onto `main
2023-04-17 11:30:27 -07:00
Anton Korobeynikov
82c02b733c [lldb] Add support for MSP430 in LLDB.
Add MSP430 to the list of available targets, implement MSP430 ABI, add support for debugging targets with 16-bit address size.

The update is intended for use with MSPDebug, a GDB server implementation for MSP430.

Reviewed By: bulbazord, DavidSpickett

Differential Revision: https://reviews.llvm.org/D146965
2023-04-17 11:05:09 -07:00
Michael Buch
6cdfa29574 [lldb][ClangExpression] Filter out non-root namespaces in FindNamespace
**Summary**

In a program such as:
```
namespace A {
namespace B {
struct Bar {};
}
}

namespace B {
struct Foo {};
}
```
...LLDB would run into issues such as:
```
(lldb) expr ::B::Foo f
error: expression failed to parse:
error: <user expression 0>:1:6: no type named 'Foo' in namespace 'A::B'
::B::Foo f
~~~~~^
```

This is because the `SymbolFileDWARF::FindNamespace` implementation
will return *any* namespace it finds if the `parent_decl_ctx` provided
is empty. In `FindExternalVisibleDecls` we use this API to find the
namespace that symbol `B` refers to. If `A::B` happened to be the one
that `SymbolFileDWARF::FindNamespace` looked at first, we would try
to find `struct Foo` in `A::B`. Hence the error.

This patch proposes a new `SymbolFileDWARF::FindNamespace` API that
will only find a match for top-level namespaces, which is what
`FindExternalVisibleDecls` is attempting anyway; it just never
accounted for multiple namespaces of the same name.

**Testing**

* Added API test-case

Differential Revision: https://reviews.llvm.org/D147436
2023-04-14 17:11:30 +01:00
Michael Buch
89cd0e8c26 [lldb] Allow evaluating expressions in C++20 mode
This patch allows users to evaluate expressions using
`expr -l c++20`. Currently DWARF keeps the CU's at
`DW_AT_language` at `DW_LANG_C_plus_plus_14` even
when compiling with `-std=c++20`. So even in "C++20
programs" expression evaluation will by default be
performed in `C++11` mode for now.

Enabling `C++14` has been previously attempted at
https://reviews.llvm.org/D80308

There are some remaining issues around evaluating C++20
expressions. Mainly, lack of support for C++20 AST nodes in
`clang::ASTImporter`. But these can be addressed in follow-up
patches.
2023-04-14 17:10:18 +01:00
Pavel Labath
09ba7b6053 [lldb] Add a sleep to TestObjectFileJSON
The test fails when the two generated files have the same timestamp
(lldb uses second granularity).
2023-04-14 14:37:32 +02:00
Jonas Devlieghere
27f27d15f6
[lldb] Use ObjectFileJSON to create modules for interactive crashlogs
Create an artificial module using a JSON object file when we can't
locate the module and dSYM through dsymForUUID (or however
locate_module_and_debug_symbols is implemented). By parsing the symbols
from the crashlog and making them part of the JSON object file, LLDB can
symbolicate frames it otherwise wouldn't be able to, as there is no
module for it.

For non-interactive crashlogs, that never was a problem because we could
simply show the "pre-symbolicated" frame from the input. For interactive
crashlogs, we need a way to pass the symbol information to LLDB so that
it can symbolicate the frames, which is what motivated the JSON object
file format.

Differential revision: https://reviews.llvm.org/D148172
2023-04-13 16:56:29 -07:00
Jonas Devlieghere
6f8360a0e1
[lldb] Use the host's target triple in TestObjectFileJSON
Use the target's triple when adding JSON modules in TestObjectFileJSON.
This should fix the test failure on non-Darwin bots.
2023-04-13 14:20:58 -07:00
Jonas Devlieghere
0e5cdbf07e
[lldb] Make ObjectFileJSON loadable as a module
This patch adds support for creating modules from JSON object files.
This is necessary for the crashlog use case where we don't have either a
module or a symbol file. In that case the ObjectFileJSON serves as both.

The patch adds support for an object file type (i.e. executable, shared
library, etc). It also adds the ability to specify sections, which is
necessary in order specify symbols by address. Finally, this patch
improves error handling and fixes a bug where we wouldn't read more than
the initial 512 bytes in GetModuleSpecifications.

Differential revision: https://reviews.llvm.org/D148062
2023-04-13 14:08:19 -07:00
Caroline Tice
be58b42a75 [lldb] Add 'CHECK' to class-type-nullptr-deref.s test.
This test previously relied on just segfaulting or not. This commit adds
a CHECK statement to the test.

Differential Revision: https://reviews.llvm.org/D148151
2023-04-13 08:17:53 -07:00
David Spickett
e07a421dd5 [lldb] Show register fields using bitfield struct types
This change uses the information from target.xml sent by
the GDB stub to produce C types that we can use to print
register fields.

lldb-server *does not* produce this information yet. This will
only work with GDB stubs that do. gdbserver or qemu
are 2 I know of. Testing is added that uses a mocked lldb-server.
```
(lldb) register read cpsr x0 fpcr fpsr x1
    cpsr = 0x60001000
         = (N = 0, Z = 1, C = 1, V = 0, TCO = 0, DIT = 0, UAO = 0, PAN = 0, SS = 0, IL = 0, SSBS = 1, BTYPE = 0, D = 0, A = 0, I = 0, F = 0, nRW = 0, EL = 0, SP = 0)
```

Only "register read" will display fields, and only when
we are not printing a register block.

For example, cpsr is a 32 bit register. Using the target's scratch type
system we construct a type:
```
struct __attribute__((__packed__)) cpsr {
  uint32_t N : 1;
  uint32_t Z : 1;
  ...
  uint32_t EL : 2;
  uint32_t SP : 1;
};
```

If this register had unallocated bits in it, those would
have been filled in by RegisterFlags as anonymous fields.
A new option "SetChildPrintingDecider" is added so we
can disable printing those.

Important things about this type:
* It is packed so that sizeof(struct cpsr) == sizeof(the real register).
  (this will hold for all flags types we create)
* Each field has the same storage type, which is the same as the type
  of the raw register value. This prevents fields being spilt over
  into more storage units, as is allowed by most ABIs.
* Each bitfield size matches that of its register field.
* The most significant field is first.

The last point is required because the most significant bit (MSB)
being on the left/top of a print out matches what you'd expect to
see in an architecture manual. In addition, having lldb print a
different field order on big/little endian hosts is not acceptable.

As a consequence, if the target is little endian we have to
reverse the order of the fields in the value. The value of each field
remains the same. For example 0b01 doesn't become 0b10, it just shifts
up or down.

This is needed because clang's type system assumes that for a struct
like the one above, the least significant bit (LSB) will be first
for a little endian target. We need the MSB to be first.

Finally, if lldb's host is a different endian to the target we have
to byte swap the host endian value to match the endian of the target's
typesystem.

| Host Endian | Target Endian | Field Order Swap | Byte Order Swap |
|-------------|---------------|------------------|-----------------|
| Little      | Little        | Yes              | No              |
| Big         | Little        | Yes              | Yes             |
| Little      | Big           | No               | Yes             |
| Big         | Big           | No               | No              |

Testing was done as follows:
* Little -> Little
  * LE AArch64 native debug.
* Big -> Little
  * s390x lldb running under QEMU, connected to LE AArch64 target.
* Little -> Big
  * LE AArch64 lldb connected to QEMU's GDB stub, which is running
    an s390x program.
* Big -> Big
 * s390x lldb running under QEMU, connected to another QEMU's GDB
   stub, which is running an s390x program.

As we are not allowed to link core code to plugins directly,
I have added a new plugin RegisterTypeBuilder. There is one implementation
of this, RegisterTypeBuilderClang, which uses TypeSystemClang to build
the CompilerType from the register fields.

Reviewed By: jasonmolenda

Differential Revision: https://reviews.llvm.org/D145580
2023-04-13 13:04:34 +00:00
Jason Molenda
e76cfaca70 AArch64 debugserver parse ESR register for watchpoints
Have debugserver parse the watchpoint flags out of the exception
syndrome register when we get a watchpoint mach exception.  Relay
those fields up to lldb in the stop reply packet, if the watchpoint
number was reported by the hardware, use the address from that as
the watchpoint address.

Change how watchpoints are reported to lldb from using the mach
exception data, to using the `reason:watchpoint` and `description:asciihex`
method that lldb-server uses, which can relay the actual trap address
as well as the address of a watched memory region responsible for
the trap, so lldb can step past it.

Have debugserver look for the nearest watchpoint that it has set
when it gets a watchpoint trap, so accesses that are reported as
starting before the watched region are associated with the correct
watchpoint to lldb.  Add a test case for this specific issue.

Differential Revision: https://reviews.llvm.org/D147820
rdar://83996471
2023-04-12 18:36:17 -07:00
Alexander Kornienko
ca7a20df10 [lldb] Reduce chances of spurious failures in some build setups
The test may fail when running from a directory that contains the string used in
CHECK-NOT. We observe flakiness rate of around 3/100000. Increasing the length
helps reducing the rate of failures.

Reviewed By: DavidSpickett

Differential Revision: https://reviews.llvm.org/D148099
2023-04-12 13:05:39 +02:00
Caroline Tice
1fa26e64fd [PATCH][lldb] Fix dereference of null pointer.
The function DWARFASTParserClang::ParsePointerToMemberType attempts to make
two pointers and then immediately tries to dereference them, without
verifying that the pointesr were successfully created. Sometimes the pointer
creation fails, and the dereference then causes a segfault. This add a check
that the pointers are non-null before attempting to dereference them.
2023-04-11 13:33:03 -07:00
Jorge Gorbe Moya
53aa22cd9a [lldb-vscode] Fix two issues with runInTerminal test.
With ptrace_scope = 1 the kernel only allows tracing descendants of a
process. When using runInTerminal, the target process is not launched
by the debugger, so we need to modify LaunchRunInTerminal to explicitly
allow tracing. This should fix a problem reported in
https://reviews.llvm.org/D84974#3903716

In order to allow only the main lldb-vscode process to attach to the
target, this change introduces a new `--debugger-pid` flag that needs
to be passed with `--launch-target` and `--comm-file`.

Also, remove a special case from the launch method in the
lldbvscode_testcase test harness. The existing test was using
stopOnEntry, so the first stop didn't happen at the expected breakpoint
unless the harness did configurationDone first.

Differential Revision: https://reviews.llvm.org/D147805
2023-04-10 18:18:05 -07:00
Alex Langford
469bdbd62c [lldb][NFC] Update syntax description for language cplusplus demangle
Also added some tests because this is completely untested.

rdar://107780577

Differential Revision: https://reviews.llvm.org/D147841
2023-04-10 13:59:44 -07:00
Michael Buch
9ca707b69b [lldb][test] Add tests for clang::PreferredNameAttr formatting
Add some tests to make sure we're formatting structures
with preferred names correctly.

Differential Revision: https://reviews.llvm.org/D145832
2023-04-07 01:37:36 +01:00
Michael Buch
711a644127 [clang][DebugInfo] Emit DW_AT_type of preferred name if available
With this patch, whenever we emit a `DW_AT_type` for some declaration
and the type is a template class with a `clang::PreferredNameAttr`, we
will emit the typedef that the attribute refers to instead. I.e.,

```
0x123 DW_TAG_variable
        DW_AT_name "var"
        DW_AT_type (0x123 "basic_string<char>")

0x124 DW_TAG_structure_type
        DW_AT_name "basic_string<char>"
```
...becomes
```
0x123 DW_TAG_variable
        DW_AT_name "var"
        DW_AT_type (0x124 "std::string")

0x124 DW_TAG_structure_type
        DW_AT_name "basic_string<char>"

0x125 DW_TAG_typedef
        DW_AT_name "std::string"
        DW_AT_type (0x124 "basic_string<char>")
```

We do this by returning the preferred name typedef `DIType` when
we create a structure definition. In some cases, e.g., with `-gmodules`,
we don't complete the structure definition immediately but do so later
via `completeClassData`, which overwrites the `TypeCache`. In such cases
we don't actually want to rewrite the cache with the preferred name. We
handle this by returning both the definition and the preferred typedef
from `CreateTypeDefinition` and let the callee decide what to do with
it.

Essentially we set up the types as:
```
TypeCache[Record] => DICompositeType
ReplaceMap[Record] => DIDerivedType(baseType: DICompositeType)
```

For now we keep this behind LLDB tuning.

**Testing**

- Added clang unit-test
- `check-llvm`, `check-clang` pass
- Confirmed that this change correctly repoints
  `basic_string` references in some of my test programs.
- Will add follow-up LLDB API tests

Differential Revision: https://reviews.llvm.org/D145803
2023-04-07 01:37:36 +01:00
Dave Lee
a58eefa115 [lldb] Rename test module.map files to module.modulemap (NFC)
The name `module.modulemap` is convention.

> Clang will also search for a file named `module.map`. This behavior is deprecated and
> we plan to eventually remove it.
2023-04-06 14:00:21 -07:00
Jonas Devlieghere
ea95da1809
[lldb] Add an overload to SetModuleLoadAddress that takes an unsigned value
Currently, SBTarget::SetModuleLoadAddress does not accept large slides
needed to load images in high memory. This function should always have
taken an unsigned as the slide, as it immediately passes it to
Target::SetSectionLoadAddress which takes an unsigned.

This patch adds an overload and exposes that to SWIG instead of the
signed variant. I've marked the signed variant as deprecated and added
check that the slide is positive.

rdar://101355155

Differential revision: https://reviews.llvm.org/D147482
2023-04-06 10:43:54 -07:00
Jim Ingham
f79c037b63 Fix the check in StopInfoBreakpoint for "are we currently running an expression"
We were checking "WasTheLastResumeForUserExpression" but that returns true even
if that expression was completed, provided we haven't run again.  This uses a
better check.

This is actually fairly hard to trigger.  It happens the first time you hit an
objc_exception_throw breakpoint and invoke that frame recognizer for that.  But
I couldn't trigger it using a Python based frame recognizer.  So I wrote a test
for the objc_exception_throw_breakpoint recognizer which should have been there
anyway...  It fails (the target auto-continues) w/o this patch and succeeds with
it.

Differential Revision: https://reviews.llvm.org/D147587
2023-04-05 17:14:25 -07:00
Adrian Prantl
7e28a2c9f4 Skip tests under asan 2023-04-05 09:00:55 -07:00
Pavel Labath
af9e1fa178 [lldb] Detach the child process when stepping over a fork
Step over thread plans were claiming to explain the fork stop reasons,
which prevented the default fork logic (detaching from the child
process) from kicking in. This patch changes that.

Differential Revision: https://reviews.llvm.org/D141605
2023-04-05 13:25:43 +02:00
Adrian Prantl
a78997e0aa Simplify test.
This test doesn't actually depend on being able to launch the process.
This may or may not explain why this test behaves oddly on some of our bots.
2023-04-04 15:16:01 -07:00
Adrian Prantl
5d77344d9d Simplify test script 2023-04-04 15:08:57 -07:00
Jonas Devlieghere
f03f8111d2
[lldb] Only run TestUniversal64 on macOS 11 and later
GreenDragon is running on a host OS and toolchain that doesn't support
building for Apple Silicon.
2023-03-30 14:12:32 -07:00
Dave Lee
7edff3c1b2 [lldb] Use one Progress event per root module build
Following the work done by @jdevlieghere in D143690, this changes how Clang module build
events are emitted.

Instead of one Progress event per module being built, a single Progress event is used to
encompass all modules, and each module build is sent as an `Increment` update.

Differential Revision: https://reviews.llvm.org/D147248
2023-03-30 13:59:02 -07:00
Jonas Devlieghere
a7005d7813
[lldb] Unify target triples across compiler and linker invocations
rdar://107364766
2023-03-29 14:58:19 -07:00
Jonas Devlieghere
fda53ad937
[lldb] Support Universal Mach-O binaries with a fat64 header
Support universal Mach-O binaries with a fat64 header. After
4d683f7fa7, dsymutil can now generate such binaries when the offsets
would otherwise overflow the 32-bit offsets in the regular fat header.

rdar://107289570

Differential revision: https://reviews.llvm.org/D147012
2023-03-28 15:46:26 -07:00