Fix the remaining `tests/debuginfo` failures on `msvc`
Fixes the remainder of the failing tests from https://github.com/rust-lang/rust/issues/161657
I used lldb 22.1 to individually check each of the `S_DEFRANGE_REGISTER_REL_INDIR` node (using e.g. `llvm-pdbutil dump --symbols ".\build\x86_64-pc-windows-gnu\test\debuginfo\<test_name>.lldb\a.pdb" | rg "unknown \(4471\)"`)
Any tests with an `unknown (4471)` node (4471/0x1177 being the enum value for `S_DEFRANGE_REGISTER_REL_INDIR`) got an `[msvc]` revision to disable on LLDB older than 23.1.0.
I then updated to LLDB 23.1.0 and disabled any remaining test failures that ocurred due to the variable shadowing behavior (so that they do not instantly break when we eventually run 23 in CI). Technically we could have avoided disabling those tests by using the python API to inspect individual slots of the frame, or by printing the whole frame at each step and matching against that, but the amount of effort seems not worth it until [we determine whether or not LLDB can/will improve its behavior here.](https://github.com/llvm/llvm-project/issues/221696).
One note, LLDB 23 seems to like it even less when we use the parent debugger instance for the test harness. I'll fix that in a followup PR since it requires a little bit of fiddling to get it to work with LLDB <23 (the short version is it's much harder to exit with a non-0 status code when using a nested debugger instance. We should be able to run something like `os.kill(os.getpid(), signal.SIGTERM)` from the internal python to kill the parent LLDB process to work around that)
There were a few fixes that required special handling
### `borrowed-basic.rs`, `basic-types-globals.rs`, `reference-debuginfo.rs`
LLDB appears to have changed their default formatting for chars again in v23.1.0 (`U+0x00000061 U'a'` -> `U+0061 U'a'`) luckily these are similar enough that we can use a wildcard to pass in both cases
### `dummy-span.rs`
There was a conditional to prevent using the (0,0) default dummy span on MSVC with a comment explaining why (it would default to the first line of the file instead). I removed the `is_msvc` check and this test worked and didn't break anything else so, best guess this got fixed at some point and the comment was outdated?
In any case, with this PR, the entirety of `tests/debuginfo` passes on `linux-gnu`, `windows-gnu`, and `windows-msvc` 🎉🎉
<img width="847" height="444" alt="image" src="https://github.com/user-attachments/assets/4c0f14d1-5ad4-4234-8380-59ad18ad6309" />
<img width="817" height="208" alt="image" src="https://github.com/user-attachments/assets/87819fcd-cdbb-4fd4-b2f8-c6cf2ecf5db3" />
r? @Kobzol, @jieyouxu
Add `gdb-repr` directive for `tests/debuginfo`
Part of https://github.com/rust-lang/rust/issues/148483 and followup to https://github.com/rust-lang/rust/pull/158298. Applies (approximately) identical logic to GDB.
I still need to test things on `windows-gnu` (and locally try a few more tests to see if there's any glaring issues). There's also a few bike-sheddy things.
The main way this differs from the LLDB implementation is that GDB doesn't use `lldb_batchmode/runner.py` to orchestrate the commands. Instead, I have `compiletest` import `from_gdb.py` which registers a custom `repr` CLI command. GDB's batch processing works as normal, but dispatches to our logic automatically whenever it encounters `repr <var_name>`.
An additional `repr-finalize` CLI command is also registered to implement the checks that ensure we encountered all expected types/vars, and verifies that there were no errors before saving blessed data.
r? @Kobzol, @jieyouxu
Use `#[repr(C)]` on debuginfo test structs
This fixes a couple of issues.
* LLDB reading PDB debug info re-orders fields and displays them in offset order instead of source-order like DWARF. While this has been [fixed upstream](https://github.com/llvm/llvm-project/pull/218731), it'll be quite a while before it's reflected in CI runners and such
* For all targets, the structs were often written (and named) under the assumption that they would have specific layouts. Nothing was actually enforcing those assumed layouts, so very often a type would be named e.g. `HasInternalPadding` but rust would reorder it such that no internal padding existed.
`struct-with-destructor.rs` is still iffy. I'll test it when I get home and can update my main PC's LLDB.
On my remote PC (lldb 22.1.2) it didn't fix the test, and it looked like the variable was straight up being read incorrectly:
```
// expected:
(struct_with_destructor::NestedOuter) nested = {a:{a:{x:7890, y:9870}}}
// got:
(struct_with_destructor::NestedOuter) nested = {a:{a:{y:1378684509906, x:9870}}
```
On my laptop when manually inspecting it (CodeLLDB which uses 22.1.8 under the hood) everything looked fine, so it might have been a bug that LLDB patched.
Part of the MSVC test fixes for https://github.com/rust-lang/rust/issues/161657
r? @Kobzol, @jieyouxu
---
test-jobs: aarch64-apple-1
test-jobs: aarch64-msvc-1
test-jobs: x86_64-msvc-1
test-jobs: x86_64-mingw-1
Apply str debugger visualizer to `*const str`, `*mut str` and `Box<str>`
Fairly straightforward. Note that the MSVC changes very likely aren't exercised by CI. My GSoC project is actively working on fixing that, but in the meantime i can personally verify that it works (note that the `ref$<str$> *` type name confirms this is MSVC):
<img width="318" height="138" alt="image" src="https://github.com/user-attachments/assets/fd868f16-d9a5-438a-a155-a429771bf525" />
[compiletest] Differentiate between LLVM LLDB and Apple LLDB
This patch causes `compiletest` to treat LLVM and Apple LLDB versions uniquely, including modified `min-version` directives. We'll need this level of granularity going forward:
* rust-lang/rust#158298 requires LLVM LLDB `22.1.x`. Currently, `compiletest` only cares about major versions.
* @jieyouxu's efforts to [pin debugger versions](https://github.com/rust-lang/compiler-team/issues/1012)
Any tests that specified `min-lldb-version` have been updated to equivalent `min-apple-lldb-version` and `min-llvm-lldb-version` directives to preserve existing test filters.
r? @Kobzol, @jieyouxu
See RUST-159073, this test has been flaky with
```
/checkout/obj/build/x86_64-unknown-linux-gnu/test/debuginfo/function-call.gdb/function-call.debugger.script:11: Error in sourced command file:
Couldn't write extended state status: Bad address.
```
on linux CI jobs under various environments and hosts/targets. I tried
running this under GDB 15.1 locally (WSL, `x86_64-unknown-linux-gnu`)
but could not reproduce. CI typically uses GDB 12.1 with Ubuntu 22.04.
So gate this test with min GDB 15.1 which prevents it from running in CI
to workaround the flakiness but still allow running it locally under
GDB >= 15.1.
It's *possible* there's a genuine problem here.
debuginfo: slices are DW_TAG_array_type's
Rust debuginfo for unsized structs with embedded slice types is lacking, and it makes it difficult for debuggers to correctly print types like `Rc<str>` (eg rust-lang/rust#114195). Specifically, these three structs would have essentially the same debug info (modulo some names):
```rust
struct Foo { a: u32, s: str } // unsized
struct Bar { a: u32, s: [u8] } // unsized
struct Baz { a: u32, s: u8 }
```
This changes how the compiler generates debuginfo in this case, and I used existing compilers (gcc, clang) handling of C flexible member arrays as a reference.
Since approx. Windows SDK 20348, the corresponding cdb (and/or its
underlying WinDbg engine) changed or regressed the `OsStr`/`OsString`
visualization, and no longer renders the emoji. Since approx. SDK/cdb
26100, the output formatting of the string containing UTF-8 (i.e. the
multi-byte emoji grapheme) seems to have further regressed (e.g. the end
quotation mark is no longer shown and command output becomes garbled).
Relevant issues:
* RUST-88840
* RUST-148743
* RUST-88796
Convert `lldb_batchmode` to a package
The new testing logic for https://github.com/rust-lang/rust/issues/148483 will end up being a couple of python files, and it doesn't make sense to have them all as freefloating scripts in `src/etc`.
I also made sure to update occurrences of `lldb_batchmode.py` in the code and documentation to point to the new package instead.
On lldb 22 (locally lldb 22.1.6) I see
```
v nz_isize
error: Invalid type: Cannot determine size
[...]
v nz_usize
error: Invalid type: Cannot determine size
```
AFAICT this might be an upstream issue, as reported in
<https://github.com/llvm/llvm-project/issues/196812>. Let's disable for
now to not have `./x test` fail for contributors using lldb 22.
We store a stable hash value in the most common interned values (e.g.
types, predicates, regions). This is 16 bytes of data.
- In non-incremental builds it's a straightforward performance loss: the
stable hash isn't computed or used, and the 16 bytes of space goes to
waste (but it still gets hashed when interning).
- In incremental builds it avoids some hashing but doesn't seem to
actually be a genuine performance win, and the complexity doesn't seem
worth it.
We don't consider it a bug that users can't break on initialization of
some non-zero sized types (see comment on `maximally-steppable` at the
top of the file), so it does not make sense to consider it a bug that
users can't break on initialization of some zero-sized types.
Some optimization passes _improve_ compile times [1]. So we want to run
some passes even with `-Copt-level=0`. That means that some of the lines
in the test can be optimized away. To make regression testing more
robust, we also want to run the test with such passes disabled. The
solution is to use two revisions. One with default `-Copt-level=0`
passes, and one "even less optimized", with enough optimization passes
disabled to keep the maximum number of lines steppable.
[1]: https://github.com/rust-lang/compiler-team/issues/319
Box in `ValTreeKind::Branch(Box<[I::Const]>)` changed to `List`
This is related to trait system refactoring. It fixes the FIXME in `ValTreeKind`
```
// FIXME(mgca): Use a `List` here instead of a boxed slice
Branch(Box<[I::Const]>),
```
It introduces `Interner::Consts`, changes `Branch(Box<[I::Const]>)` to `Branch(I::Consts)`, and updates all relevant places.
r? lcnr