rust/tests
Kyle Huey 1c5e3c90cf Rework MIR inlining debuginfo so function parameters show up in debuggers.
Line numbers of multiply-inlined functions were fixed in #114643 by using a
single DISubprogram. That, however, triggered assertions because parameters
weren't deduplicated. The "solution" to that in #115417 was to insert a
DILexicalScope below the DISubprogram and parent all of the parameters to that
scope. That fixed the assertion, but debuggers (including gdb and lldb) don't
recognize variables that are not parented to the subprogram itself as parameters,
even if they are emitted with DW_TAG_formal_parameter.

Consider the program:

use std::env;

fn square(n: i32) -> i32 {
    n * n
}

fn square_no_inline(n: i32) -> i32 {
    n * n
}

fn main() {
    let x = square(env::vars().count() as i32);
    let y = square_no_inline(env::vars().count() as i32);
    println!("{x} == {y}");
}

When making a release build with debug=2 and rustc 1.82.0-nightly (8b3870784 2024-08-07)

(gdb) r
Starting program: /ephemeral/tmp/target/release/tmp
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, tmp::square () at src/main.rs:5
5	    n * n
(gdb) info args
No arguments.
(gdb) info locals
n = 31
(gdb) c
Continuing.

Breakpoint 2, tmp::square_no_inline (n=31) at src/main.rs:10
10	    n * n
(gdb) info args
n = 31
(gdb) info locals
No locals.

This issue is particularly annoying because it removes arguments from stack traces.

The DWARF for the inlined function looks like this:

< 2><0x00002132 GOFF=0x00002132>      DW_TAG_subprogram
                                        DW_AT_linkage_name          _ZN3tmp6square17hc507052ff3d2a488E
                                        DW_AT_name                  square
                                        DW_AT_decl_file             0x0000000f /ephemeral/tmp/src/main.rs
                                        DW_AT_decl_line             0x00000004
                                        DW_AT_type                  0x00001a56<.debug_info+0x00001a56>
                                        DW_AT_inline                DW_INL_inlined
< 3><0x00002142 GOFF=0x00002142>        DW_TAG_lexical_block
< 4><0x00002143 GOFF=0x00002143>          DW_TAG_formal_parameter
                                            DW_AT_name                  n
                                            DW_AT_decl_file             0x0000000f /ephemeral/tmp/src/main.rs
                                            DW_AT_decl_line             0x00000004
                                            DW_AT_type                  0x00001a56<.debug_info+0x00001a56>
< 4><0x0000214e GOFF=0x0000214e>          DW_TAG_null
< 3><0x0000214f GOFF=0x0000214f>        DW_TAG_null

That DW_TAG_lexical_block inhibits every debugger I've tested from recognizing
'n' as a parameter.

This patch removes the additional lexical scope. Parameters can be easily
deduplicated by a tuple of their scope and the argument index, at the trivial
cost of taking a Hash + Eq bound on DIScope.
2024-08-12 19:20:00 -07:00
..
assembly Disallow setting built-in cfgs via set the command-line 2024-08-07 14:08:34 +02:00
auxiliary
codegen Rework MIR inlining debuginfo so function parameters show up in debuggers. 2024-08-12 19:20:00 -07:00
codegen-units Revert "Rollup merge of #125572 - mu001999-contrib:dead/enhance, r=pnkfelix" 2024-08-03 07:57:31 -04:00
coverage Finish blessing coverage/mcdc tests after LLVM 19 upgrade 2024-08-01 13:36:50 +10:00
coverage-run-rustdoc coverage: Extract hole spans from HIR instead of MIR 2024-07-08 21:22:56 +10:00
crashes Don't inline tainted MIR bodies 2024-08-08 20:53:25 -04:00
debuginfo Disallow setting built-in cfgs via set the command-line 2024-08-07 14:08:34 +02:00
incremental Do not normalize constants eagerly. 2024-07-31 00:59:12 +00:00
mir-opt custom MIR: add support for tail calls 2024-08-05 18:23:14 +02:00
pretty Mark format! with must_use hint 2024-07-06 14:24:20 +02:00
run-make Rollup merge of #128823 - ChrisDenton:staticlib, r=jieyouxu 2024-08-09 05:52:16 +02:00
run-pass-valgrind
rustdoc Rollup merge of #127921 - spastorino:stabilize-unsafe-extern-blocks, r=compiler-errors 2024-08-03 20:51:51 +02:00
rustdoc-gui rustdoc-search: account for numeric disambiguators on impls 2024-08-06 07:36:12 -07:00
rustdoc-js Add test for Self not being a generic in search index 2024-08-04 12:49:28 -07:00
rustdoc-js-std
rustdoc-json Rollup merge of #128836 - its-the-shrimp:add_test_for_107278, r=aDotInTheVoid 2024-08-09 00:03:38 +02:00
rustdoc-ui Rollup merge of #128755 - yaahc:jj-crlf, r=estebank 2024-08-07 20:28:19 +02:00
ui Rollup merge of #128616 - compiler-errors:mir-inline-tainted, r=cjgillot 2024-08-09 05:52:14 +02:00
ui-fulldeps Bless test fallout 2024-08-03 07:57:31 -04:00
COMPILER_TESTS.md