From fd7557b7ee454058fff84b556892adbef89f7d52 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Wed, 19 Jan 2022 17:56:53 +0100 Subject: debuginfo: Make sure that type names for closure and generator environments are unique in debuginfo. Before this change, closure/generator environments coming from different instantiations of the same generic function were all assigned the same name even though they were distinct types with potentially different data layout. Now we append the generic arguments of the originating function to the type name. This commit also emits '{closure_env#0}' as the name of these types in order to disambiguate them from the accompanying closure function '{closure#0}'. Previously both were assigned the same name. --- src/test/debuginfo/captured-fields-1.rs | 29 ++++++++++------------ src/test/debuginfo/function-names.rs | 21 +++++++++------- src/test/debuginfo/generator-objects.rs | 20 ++++++++------- src/test/debuginfo/issue-57822.rs | 12 +++++---- src/test/debuginfo/type-names.rs | 25 +++++++++++-------- .../debuginfo/var-captured-in-nested-closure.rs | 2 +- 6 files changed, 59 insertions(+), 50 deletions(-) (limited to 'src/test/debuginfo') diff --git a/src/test/debuginfo/captured-fields-1.rs b/src/test/debuginfo/captured-fields-1.rs index 65f9e5f5322..afbf942d404 100644 --- a/src/test/debuginfo/captured-fields-1.rs +++ b/src/test/debuginfo/captured-fields-1.rs @@ -4,44 +4,44 @@ // gdb-command:run // gdb-command:print test -// gdbr-check:$1 = captured_fields_1::main::{closure#0} {_ref__my_ref__my_field1: 0x[...]} +// gdbr-check:$1 = captured_fields_1::main::{closure_env#0} {_ref__my_ref__my_field1: 0x[...]} // gdb-command:continue // gdb-command:print test -// gdbr-check:$2 = captured_fields_1::main::{closure#1} {_ref__my_ref__my_field2: 0x[...]} +// gdbr-check:$2 = captured_fields_1::main::{closure_env#1} {_ref__my_ref__my_field2: 0x[...]} // gdb-command:continue // gdb-command:print test -// gdbr-check:$3 = captured_fields_1::main::{closure#2} {_ref__my_ref: 0x[...]} +// gdbr-check:$3 = captured_fields_1::main::{closure_env#2} {_ref__my_ref: 0x[...]} // gdb-command:continue // gdb-command:print test -// gdbr-check:$4 = captured_fields_1::main::{closure#3} {my_ref: 0x[...]} +// gdbr-check:$4 = captured_fields_1::main::{closure_env#3} {my_ref: 0x[...]} // gdb-command:continue // gdb-command:print test -// gdbr-check:$5 = captured_fields_1::main::{closure#4} {my_var__my_field2: 22} +// gdbr-check:$5 = captured_fields_1::main::{closure_env#4} {my_var__my_field2: 22} // gdb-command:continue // gdb-command:print test -// gdbr-check:$6 = captured_fields_1::main::{closure#5} {my_var: captured_fields_1::MyStruct {my_field1: 11, my_field2: 22}} +// gdbr-check:$6 = captured_fields_1::main::{closure_env#5} {my_var: captured_fields_1::MyStruct {my_field1: 11, my_field2: 22}} // gdb-command:continue // === LLDB TESTS ================================================================================== // lldb-command:run // lldb-command:print test -// lldbg-check:(captured_fields_1::main::{closure#0}) $0 = { _ref__my_ref__my_field1 = 0x[...] } +// lldbg-check:(captured_fields_1::main::{closure_env#0}) $0 = { _ref__my_ref__my_field1 = 0x[...] } // lldb-command:continue // lldb-command:print test -// lldbg-check:(captured_fields_1::main::{closure#1}) $1 = { _ref__my_ref__my_field2 = 0x[...] } +// lldbg-check:(captured_fields_1::main::{closure_env#1}) $1 = { _ref__my_ref__my_field2 = 0x[...] } // lldb-command:continue // lldb-command:print test -// lldbg-check:(captured_fields_1::main::{closure#2}) $2 = { _ref__my_ref = 0x[...] } +// lldbg-check:(captured_fields_1::main::{closure_env#2}) $2 = { _ref__my_ref = 0x[...] } // lldb-command:continue // lldb-command:print test -// lldbg-check:(captured_fields_1::main::{closure#3}) $3 = { my_ref = 0x[...] } +// lldbg-check:(captured_fields_1::main::{closure_env#3}) $3 = { my_ref = 0x[...] } // lldb-command:continue // lldb-command:print test -// lldbg-check:(captured_fields_1::main::{closure#4}) $4 = { my_var__my_field2 = 22 } +// lldbg-check:(captured_fields_1::main::{closure_env#4}) $4 = { my_var__my_field2 = 22 } // lldb-command:continue // lldb-command:print test -// lldbg-check:(captured_fields_1::main::{closure#5}) $5 = { my_var = { my_field1 = 11 my_field2 = 22 } } +// lldbg-check:(captured_fields_1::main::{closure_env#5}) $5 = { my_var = { my_field1 = 11 my_field2 = 22 } } // lldb-command:continue #![feature(capture_disjoint_fields)] @@ -53,10 +53,7 @@ struct MyStruct { } fn main() { - let mut my_var = MyStruct { - my_field1: 11, - my_field2: 22, - }; + let mut my_var = MyStruct { my_field1: 11, my_field2: 22 }; let my_ref = &mut my_var; let test = || { diff --git a/src/test/debuginfo/function-names.rs b/src/test/debuginfo/function-names.rs index ac9a02cce04..73e34d4bb32 100644 --- a/src/test/debuginfo/function-names.rs +++ b/src/test/debuginfo/function-names.rs @@ -27,9 +27,9 @@ // Closure // gdb-command:info functions -q function_names::.*::{closure.* -// gdb-check:[...]static fn function_names::generic_func::{closure#0}(*mut function_names::generic_func::{closure#0}); -// gdb-check:[...]static fn function_names::main::{closure#0}(*mut function_names::main::{closure#0}); -// gdb-check:[...]static fn function_names::{impl#2}::impl_function::{closure#0}(*mut function_names::{impl#2}::impl_function::{closure#0}); +// gdb-check:[...]static fn function_names::generic_func::{closure#0}(*mut function_names::generic_func::{closure_env#0}); +// gdb-check:[...]static fn function_names::main::{closure#0}(*mut function_names::main::{closure_env#0}); +// gdb-check:[...]static fn function_names::{impl#2}::impl_function::{closure#0}(*mut function_names::{impl#2}::impl_function::{closure_env#0}); // Generator // Generators don't seem to appear in GDB's symbol table. @@ -86,9 +86,9 @@ #![feature(adt_const_params, generators, generator_trait)] #![allow(incomplete_features)] -use Mod1::TestTrait2; use std::ops::Generator; use std::pin::Pin; +use Mod1::TestTrait2; fn main() { // Implementations @@ -107,16 +107,19 @@ fn main() { let _ = generic_func(42i32); // Closure - let closure = || { TestStruct1 }; + let closure = || TestStruct1; closure(); // Generator - let mut generator = || { yield; return; }; + let mut generator = || { + yield; + return; + }; Pin::new(&mut generator).resume(()); // Const generic functions const_generic_fn_bool::(); - const_generic_fn_non_int::<{()}>(); + const_generic_fn_non_int::<{ () }>(); const_generic_fn_signed_int::<-7>(); const_generic_fn_unsigned_int::<14>(); } @@ -158,7 +161,7 @@ struct GenericStruct(std::marker::PhantomData<(T1, T2)>); impl GenericStruct { pub fn impl_function() { // Closure in a generic implementation - let closure = || { TestStruct1 }; + let closure = || TestStruct1; closure(); } } @@ -190,7 +193,7 @@ impl TestTrait1 for GenericStruct<[T; N], f32> { // Generic function fn generic_func(value: T) -> T { // Closure in a generic function - let closure = || { TestStruct1 }; + let closure = || TestStruct1; closure(); value diff --git a/src/test/debuginfo/generator-objects.rs b/src/test/debuginfo/generator-objects.rs index 9bf33a7bb87..aee19736e7e 100644 --- a/src/test/debuginfo/generator-objects.rs +++ b/src/test/debuginfo/generator-objects.rs @@ -11,31 +11,31 @@ // gdb-command:run // gdb-command:print b -// gdb-check:$1 = generator_objects::main::{generator#0}::Unresumed{_ref__a: 0x[...]} +// gdb-check:$1 = generator_objects::main::{generator_env#0}::Unresumed{_ref__a: 0x[...]} // gdb-command:continue // gdb-command:print b -// gdb-check:$2 = generator_objects::main::{generator#0}::Suspend0{c: 6, d: 7, _ref__a: 0x[...]} +// gdb-check:$2 = generator_objects::main::{generator_env#0}::Suspend0{c: 6, d: 7, _ref__a: 0x[...]} // gdb-command:continue // gdb-command:print b -// gdb-check:$3 = generator_objects::main::{generator#0}::Suspend1{c: 7, d: 8, _ref__a: 0x[...]} +// gdb-check:$3 = generator_objects::main::{generator_env#0}::Suspend1{c: 7, d: 8, _ref__a: 0x[...]} // gdb-command:continue // gdb-command:print b -// gdb-check:$4 = generator_objects::main::{generator#0}::Returned{_ref__a: 0x[...]} +// gdb-check:$4 = generator_objects::main::{generator_env#0}::Returned{_ref__a: 0x[...]} // === LLDB TESTS ================================================================================== // lldb-command:run // lldb-command:print b -// lldbg-check:(generator_objects::main::{generator#0}) $0 = +// lldbg-check:(generator_objects::main::{generator_env#0}) $0 = // lldb-command:continue // lldb-command:print b -// lldbg-check:(generator_objects::main::{generator#0}) $1 = +// lldbg-check:(generator_objects::main::{generator_env#0}) $1 = // lldb-command:continue // lldb-command:print b -// lldbg-check:(generator_objects::main::{generator#0}) $2 = +// lldbg-check:(generator_objects::main::{generator_env#0}) $2 = // lldb-command:continue // lldb-command:print b -// lldbg-check:(generator_objects::main::{generator#0}) $3 = +// lldbg-check:(generator_objects::main::{generator_env#0}) $3 = #![feature(omit_gdb_pretty_printer_section, generators, generator_trait)] #![omit_gdb_pretty_printer_section] @@ -66,4 +66,6 @@ fn main() { _zzz(); // #break } -fn _zzz() {()} +fn _zzz() { + () +} diff --git a/src/test/debuginfo/issue-57822.rs b/src/test/debuginfo/issue-57822.rs index 1a26b0a3255..62e7eb13c2d 100644 --- a/src/test/debuginfo/issue-57822.rs +++ b/src/test/debuginfo/issue-57822.rs @@ -11,20 +11,20 @@ // gdb-command:run // gdb-command:print g -// gdb-check:$1 = issue_57822::main::{closure#1} {f: issue_57822::main::{closure#0} {x: 1}} +// gdb-check:$1 = issue_57822::main::{closure_env#1} {f: issue_57822::main::{closure_env#0} {x: 1}} // gdb-command:print b -// gdb-check:$2 = issue_57822::main::{generator#3}::Unresumed{a: issue_57822::main::{generator#2}::Unresumed{y: 2}} +// gdb-check:$2 = issue_57822::main::{generator_env#3}::Unresumed{a: issue_57822::main::{generator_env#2}::Unresumed{y: 2}} // === LLDB TESTS ================================================================================== // lldb-command:run // lldb-command:print g -// lldbg-check:(issue_57822::main::{closure#1}) $0 = { f = { x = 1 } } +// lldbg-check:(issue_57822::main::{closure_env#1}) $0 = { f = { x = 1 } } // lldb-command:print b -// lldbg-check:(issue_57822::main::{generator#3}) $1 = +// lldbg-check:(issue_57822::main::{generator_env#3}) $1 = #![feature(omit_gdb_pretty_printer_section, generators, generator_trait)] #![omit_gdb_pretty_printer_section] @@ -50,4 +50,6 @@ fn main() { zzz(); // #break } -fn zzz() { () } +fn zzz() { + () +} diff --git a/src/test/debuginfo/type-names.rs b/src/test/debuginfo/type-names.rs index 2c10360fc92..c9692128562 100644 --- a/src/test/debuginfo/type-names.rs +++ b/src/test/debuginfo/type-names.rs @@ -122,7 +122,6 @@ // gdb-command:whatis has_associated_type_trait // gdb-check:type = &(dyn type_names::Trait3 + core::marker::Send) - // BARE FUNCTIONS // gdb-command:whatis rust_fn // gdb-check:type = (fn(core::option::Option, core::option::Option<&type_names::mod1::Struct2>), usize) @@ -153,10 +152,10 @@ // CLOSURES // gdb-command:whatis closure1 -// gdb-check:type = (type_names::main::{closure#0}, usize) +// gdb-check:type = (type_names::main::{closure_env#0}, usize) // gdb-command:whatis closure2 -// gdb-check:type = (type_names::main::{closure#1}, usize) +// gdb-check:type = (type_names::main::{closure_env#1}, usize) // FOREIGN TYPES // gdb-command:whatis foreign1 @@ -254,8 +253,8 @@ // CLOSURES // cdb-command:dv /t closure* -// cdb-check:struct tuple$ closure2 = [...] -// cdb-check:struct tuple$ closure1 = [...] +// cdb-check:struct tuple$ closure2 = [...] +// cdb-check:struct tuple$ closure1 = [...] // FOREIGN TYPES // cdb-command:dv /t foreign* @@ -279,7 +278,9 @@ enum Enum1 { Variant2(isize), } -extern { type ForeignType1; } +extern "C" { + type ForeignType1; +} mod mod1 { pub use self::Enum2::{Variant1, Variant2}; @@ -300,7 +301,9 @@ mod mod1 { } } - extern { pub type ForeignType2; } + extern "C" { + pub type ForeignType2; + } } trait Trait1 { @@ -311,7 +314,9 @@ trait Trait2 { } trait Trait3 { type AssocType; - fn dummy(&self) -> T { panic!() } + fn dummy(&self) -> T { + panic!() + } } impl Trait1 for isize {} @@ -441,8 +446,8 @@ fn main() { let closure2 = (|x: i8, y: f32| (x as f32) + y, 0_usize); // Foreign Types - let foreign1 = unsafe{ 0 as *const ForeignType1 }; - let foreign2 = unsafe{ 0 as *const mod1::ForeignType2 }; + let foreign1 = unsafe { 0 as *const ForeignType1 }; + let foreign2 = unsafe { 0 as *const mod1::ForeignType2 }; zzz(); // #break } diff --git a/src/test/debuginfo/var-captured-in-nested-closure.rs b/src/test/debuginfo/var-captured-in-nested-closure.rs index d811915c387..537c0b50b8b 100644 --- a/src/test/debuginfo/var-captured-in-nested-closure.rs +++ b/src/test/debuginfo/var-captured-in-nested-closure.rs @@ -108,7 +108,7 @@ // cdb-command: dx closure_local // cdb-check:closure_local : 8 [Type: [...]] // cdb-command: dx nested_closure -// cdb-check:nested_closure [Type: var_captured_in_nested_closure::main::closure$0::closure$0] +// cdb-check:nested_closure [Type: var_captured_in_nested_closure::main::closure$0::closure_env$0] // cdb-command: g -- cgit 1.4.1-3-g733a5