rust/compiler
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
..
rustc The rustc crate feature is called jemalloc 2024-07-15 13:01:20 -04:00
rustc_abi interpret: simplify pointer arithmetic logic 2024-08-01 14:25:19 +02:00
rustc_arena Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_ast Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_ast_ir Use dep: for crate dependencies 2024-07-15 12:40:10 -04:00
rustc_ast_lowering minor effects cleanups 2024-07-31 03:29:10 +00:00
rustc_ast_passes Rollup merge of #127921 - spastorino:stabilize-unsafe-extern-blocks, r=compiler-errors 2024-08-03 20:51:51 +02:00
rustc_ast_pretty Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_attr Rollup merge of #128341 - Alexendoo:parse-version-pub, r=compiler-errors 2024-07-29 17:46:44 +02:00
rustc_baked_icu_data
rustc_borrowck Don't arbitrarily choose one upper bound for hidden captured region 2024-08-06 15:43:41 -04:00
rustc_builtin_macros Make Span optional in BufferedEarlyLint 2024-08-07 14:08:34 +02:00
rustc_codegen_cranelift Move computation of decorated names out of the create_dll_import_lib method 2024-07-30 10:32:32 +00:00
rustc_codegen_gcc Update compiler-builtins version to 0.1.118 2024-08-08 14:47:49 +02:00
rustc_codegen_llvm Rework MIR inlining debuginfo so function parameters show up in debuggers. 2024-08-12 19:20:00 -07:00
rustc_codegen_ssa Rework MIR inlining debuginfo so function parameters show up in debuggers. 2024-08-12 19:20:00 -07:00
rustc_const_eval Disallow enabling features without their implied features 2024-08-07 00:45:00 -04:00
rustc_data_structures Auto merge of #128083 - Mark-Simulacrum:bump-bootstrap, r=albertlarsan68 2024-07-30 17:49:08 +00:00
rustc_driver
rustc_driver_impl Add -Zerror-metrics=PATH to save diagnostic metadata to disk 2024-08-07 11:16:55 -07:00
rustc_error_codes Update E0517 message to reflect RFC 2195. 2024-08-07 23:11:30 -05:00
rustc_error_messages Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_errors Rollup merge of #128806 - estebank:color-config, r=jieyouxu 2024-08-09 00:03:36 +02:00
rustc_expand refactor(rustc_expand::mbe): Don't require full ExtCtxt when not necessary 2024-08-07 21:58:05 +02:00
rustc_feature Rollup merge of #127655 - RalfJung:invalid_type_param_default, r=compiler-errors 2024-08-05 05:40:19 +02:00
rustc_fluent_macro Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_fs_util Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_graphviz Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_hir Rollup merge of #128377 - veera-sivarajan:fix-128249, r=davidtwco 2024-08-06 20:23:39 +02:00
rustc_hir_analysis Rollup merge of #128424 - fee1-dead-contrib:fx-clean, r=oli-obk 2024-08-07 15:59:35 +02:00
rustc_hir_pretty Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_hir_typeck Rollup merge of #128520 - compiler-errors:more-precisely-force-move, r=BoxyUwU 2024-08-07 20:49:02 -05:00
rustc_incremental Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_index Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_index_macros
rustc_infer Use Vec in instantiate_binder_with_fresh_vars 2024-07-29 14:38:33 +03:00
rustc_interface Rollup merge of #128851 - compiler-errors:validate-mir-opt-mir, r=matthiaskrgr 2024-08-09 00:03:39 +02:00
rustc_lexer Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_lint Auto merge of #128796 - matthiaskrgr:rollup-r7l68ph, r=matthiaskrgr 2024-08-07 20:00:29 +00:00
rustc_lint_defs Disallow setting built-in cfgs via set the command-line 2024-08-07 14:08:34 +02:00
rustc_llvm Disable MC/DC tests on LLVM 19 2024-07-30 10:22:48 +02:00
rustc_log Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_macros Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_metadata Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_middle Only suggest #[allow] for --warn and --deny lint level flags 2024-08-08 13:09:58 +00:00
rustc_mir_build Disallow enabling features without their implied features 2024-08-07 00:45:00 -04:00
rustc_mir_dataflow Stop using MoveDataParamEnv for places that don't need a param-env 2024-07-29 11:59:47 -04:00
rustc_mir_transform Don't inline tainted MIR bodies 2024-08-08 20:53:25 -04:00
rustc_monomorphize MIR required_consts, mentioned_items: ensure we do not forget to fill these lists 2024-08-01 15:49:25 +02:00
rustc_next_trait_solver Don't implement AsyncFn for FnDef/FnPtr that wouldnt implement Fn 2024-08-08 14:07:31 -04:00
rustc_parse Rollup merge of #127921 - spastorino:stabilize-unsafe-extern-blocks, r=compiler-errors 2024-08-03 20:51:51 +02:00
rustc_parse_format Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_passes Rollup merge of #128552 - s7tya:check-no-sanitize-attribute-pos, r=BoxyUwU 2024-08-07 20:49:02 -05:00
rustc_pattern_analysis Use a separate pattern type for rustc_pattern_analysis diagnostics 2024-07-31 16:03:27 +10:00
rustc_privacy Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_query_impl Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_query_system chore: use shorthand initializer 2024-08-02 13:22:28 -04:00
rustc_resolve rm declared_features field in resolver 2024-08-08 20:30:20 +08:00
rustc_sanitizers Use ParamEnv::reveal_all in CFI 2024-08-02 23:24:50 -04:00
rustc_serialize Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_session Rollup merge of #128806 - estebank:color-config, r=jieyouxu 2024-08-09 00:03:36 +02:00
rustc_smir Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_span Rollup merge of #125048 - dingxiangfei2009:stable-deref, r=amanieu 2024-08-07 00:34:11 +02:00
rustc_symbol_mangling Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_target Fix typo 2024-08-07 00:43:56 -04:00
rustc_trait_selection Rollup merge of #128791 - compiler-errors:async-fn-unsafe, r=lcnr 2024-08-09 00:03:36 +02:00
rustc_traits Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_transmute Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_ty_utils Auto merge of #128083 - Mark-Simulacrum:bump-bootstrap, r=albertlarsan68 2024-07-30 17:49:08 +00:00
rustc_type_ir Auto merge of #128689 - matthiaskrgr:rollup-ukyn8wq, r=matthiaskrgr 2024-08-05 17:03:58 +00:00
rustc_type_ir_macros Reformat use declarations. 2024-07-29 08:26:52 +10:00
stable_mir Reformat use declarations. 2024-07-29 08:26:52 +10:00