From cda90f55419ce449f3a9db327465d9b2ae7dfce9 Mon Sep 17 00:00:00 2001 From: lrh2000 Date: Sat, 15 May 2021 19:01:13 +0800 Subject: Store names of captured variables in `optimized_mir` - Closures in external crates may get compiled in because of monomorphization. We should store names of captured variables in `optimized_mir`, so that they are written into the metadata file and we can use them to generate debuginfo. - If there are breakpoints inside closures, the names of captured variables stored in `optimized_mir` can be used to print them. Now the name is more precise when disjoint fields are captured. --- src/test/debuginfo/captured-fields-1.rs | 99 +++++++++++++++++++++++++++++++++ src/test/debuginfo/captured-fields-2.rs | 55 ++++++++++++++++++ src/test/debuginfo/captured-fields.rs | 87 ----------------------------- src/test/debuginfo/generator-objects.rs | 8 +-- src/test/debuginfo/issue-57822.rs | 6 +- 5 files changed, 161 insertions(+), 94 deletions(-) create mode 100644 src/test/debuginfo/captured-fields-1.rs create mode 100644 src/test/debuginfo/captured-fields-2.rs delete mode 100644 src/test/debuginfo/captured-fields.rs (limited to 'src/test/debuginfo') diff --git a/src/test/debuginfo/captured-fields-1.rs b/src/test/debuginfo/captured-fields-1.rs new file mode 100644 index 00000000000..65f9e5f5322 --- /dev/null +++ b/src/test/debuginfo/captured-fields-1.rs @@ -0,0 +1,99 @@ +// compile-flags:-g + +// === GDB TESTS =================================================================================== + +// gdb-command:run +// gdb-command:print test +// gdbr-check:$1 = captured_fields_1::main::{closure#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[...]} +// gdb-command:continue +// gdb-command:print test +// gdbr-check:$3 = captured_fields_1::main::{closure#2} {_ref__my_ref: 0x[...]} +// gdb-command:continue +// gdb-command:print test +// gdbr-check:$4 = captured_fields_1::main::{closure#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} +// 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}} +// 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[...] } +// lldb-command:continue +// lldb-command:print test +// lldbg-check:(captured_fields_1::main::{closure#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[...] } +// lldb-command:continue +// lldb-command:print test +// lldbg-check:(captured_fields_1::main::{closure#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 } +// lldb-command:continue +// lldb-command:print test +// lldbg-check:(captured_fields_1::main::{closure#5}) $5 = { my_var = { my_field1 = 11 my_field2 = 22 } } +// lldb-command:continue + +#![feature(capture_disjoint_fields)] +#![allow(unused)] + +struct MyStruct { + my_field1: u32, + my_field2: u32, +} + +fn main() { + let mut my_var = MyStruct { + my_field1: 11, + my_field2: 22, + }; + let my_ref = &mut my_var; + + let test = || { + let a = &mut my_ref.my_field1; + }; + + _zzz(); // #break + + let test = || { + let a = &my_ref.my_field2; + }; + + _zzz(); // #break + + let test = || { + let a = &my_ref; + }; + + _zzz(); // #break + + let test = || { + let a = my_ref; + }; + + _zzz(); // #break + + let test = move || { + let a = my_var.my_field2; + }; + + _zzz(); // #break + + let test = || { + let a = my_var; + }; + + _zzz(); // #break +} + +fn _zzz() {} diff --git a/src/test/debuginfo/captured-fields-2.rs b/src/test/debuginfo/captured-fields-2.rs new file mode 100644 index 00000000000..c872354a924 --- /dev/null +++ b/src/test/debuginfo/captured-fields-2.rs @@ -0,0 +1,55 @@ +// compile-flags:-g + +// === GDB TESTS =================================================================================== + +// gdb-command:run +// gdb-command:print my_ref__my_field1 +// gdbr-check:$1 = 11 +// gdb-command:continue +// gdb-command:print my_var__my_field2 +// gdbr-check:$2 = 22 +// gdb-command:continue + +// === LLDB TESTS ================================================================================== + +// lldb-command:run +// lldb-command:print my_ref__my_field1 +// lldbg-check:(unsigned int) $0 = 11 +// lldb-command:continue +// lldb-command:print my_var__my_field2 +// lldbg-check:(unsigned int) $1 = 22 +// lldb-command:continue + +#![feature(capture_disjoint_fields)] +#![allow(unused)] + +struct MyStruct { + my_field1: u32, + my_field2: u32, +} + +fn main() { + let mut my_var = MyStruct { + my_field1: 11, + my_field2: 22, + }; + let my_ref = &mut my_var; + + let test = || { + let a = my_ref.my_field1; + + _zzz(); // #break + }; + + test(); + + let test = move || { + let a = my_var.my_field2; + + _zzz(); // #break + }; + + test(); +} + +fn _zzz() {} diff --git a/src/test/debuginfo/captured-fields.rs b/src/test/debuginfo/captured-fields.rs deleted file mode 100644 index 5489fa14720..00000000000 --- a/src/test/debuginfo/captured-fields.rs +++ /dev/null @@ -1,87 +0,0 @@ -// compile-flags:-g - -// === GDB TESTS =================================================================================== - -// gdb-command:run -// gdb-command:print test -// gdbr-check:$1 = captured_fields::main::{closure#0} {_captured_ref__my_ref__my_field1: 0x[...]} -// gdb-command:continue -// gdb-command:print test -// gdbr-check:$2 = captured_fields::main::{closure#1} {_captured_ref__my_ref__my_field2: 0x[...]} -// gdb-command:continue -// gdb-command:print test -// gdbr-check:$3 = captured_fields::main::{closure#2} {_captured_ref__my_ref: 0x[...]} -// gdb-command:continue -// gdb-command:print test -// gdbr-check:$4 = captured_fields::main::{closure#3} {_captured_val__my_ref: 0x[...]} -// gdb-command:continue -// gdb-command:print test -// gdbr-check:$5 = captured_fields::main::{closure#4} {_captured_val__my_var: captured_fields::MyStruct {my_field1: 11, my_field2: 22}} -// gdb-command:continue - -// === LLDB TESTS ================================================================================== - -// lldb-command:run -// lldb-command:print test -// lldbg-check:(captured_fields::main::{closure#0}) $0 = { _captured_ref__my_ref__my_field1 = 0x[...] } -// lldb-command:continue -// lldb-command:print test -// lldbg-check:(captured_fields::main::{closure#1}) $1 = { _captured_ref__my_ref__my_field2 = 0x[...] } -// lldb-command:continue -// lldb-command:print test -// lldbg-check:(captured_fields::main::{closure#2}) $2 = { _captured_ref__my_ref = 0x[...] } -// lldb-command:continue -// lldb-command:print test -// lldbg-check:(captured_fields::main::{closure#3}) $3 = { _captured_val__my_ref = 0x[...] } -// lldb-command:continue -// lldb-command:print test -// lldbg-check:(captured_fields::main::{closure#4}) $4 = { _captured_val__my_var = { my_field1 = 11 my_field2 = 22 } } -// lldb-command:continue - -#![feature(capture_disjoint_fields)] -#![allow(unused)] - -struct MyStruct { - my_field1: u32, - my_field2: u32, -} - -fn main() { - let mut my_var = MyStruct { - my_field1: 11, - my_field2: 22, - }; - let my_ref = &mut my_var; - - let test = || { - let a = &mut my_ref.my_field1; - }; - - _zzz(); // #break - - let test = || { - let a = &my_ref.my_field2; - }; - - _zzz(); // #break - - let test = || { - let a = &my_ref; - }; - - _zzz(); // #break - - let test = || { - let a = my_ref; - }; - - _zzz(); // #break - - let test = || { - let a = my_var; - }; - - _zzz(); // #break -} - -fn _zzz() {} diff --git a/src/test/debuginfo/generator-objects.rs b/src/test/debuginfo/generator-objects.rs index 46a3d7924a1..9bf33a7bb87 100644 --- a/src/test/debuginfo/generator-objects.rs +++ b/src/test/debuginfo/generator-objects.rs @@ -11,16 +11,16 @@ // gdb-command:run // gdb-command:print b -// gdb-check:$1 = generator_objects::main::{generator#0}::Unresumed{_captured_ref__a: 0x[...]} +// gdb-check:$1 = generator_objects::main::{generator#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, _captured_ref__a: 0x[...]} +// gdb-check:$2 = generator_objects::main::{generator#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, _captured_ref__a: 0x[...]} +// gdb-check:$3 = generator_objects::main::{generator#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{_captured_ref__a: 0x[...]} +// gdb-check:$4 = generator_objects::main::{generator#0}::Returned{_ref__a: 0x[...]} // === LLDB TESTS ================================================================================== diff --git a/src/test/debuginfo/issue-57822.rs b/src/test/debuginfo/issue-57822.rs index 22d55ae989f..1a26b0a3255 100644 --- a/src/test/debuginfo/issue-57822.rs +++ b/src/test/debuginfo/issue-57822.rs @@ -11,17 +11,17 @@ // gdb-command:run // gdb-command:print g -// gdb-check:$1 = issue_57822::main::{closure#1} {_captured_val__f: issue_57822::main::{closure#0} {_captured_val__x: 1}} +// gdb-check:$1 = issue_57822::main::{closure#1} {f: issue_57822::main::{closure#0} {x: 1}} // gdb-command:print b -// gdb-check:$2 = issue_57822::main::{generator#3}::Unresumed{_captured_val__a: issue_57822::main::{generator#2}::Unresumed{_captured_val__y: 2}} +// gdb-check:$2 = issue_57822::main::{generator#3}::Unresumed{a: issue_57822::main::{generator#2}::Unresumed{y: 2}} // === LLDB TESTS ================================================================================== // lldb-command:run // lldb-command:print g -// lldbg-check:(issue_57822::main::{closure#1}) $0 = { _captured_val__f = { _captured_val__x = 1 } } +// lldbg-check:(issue_57822::main::{closure#1}) $0 = { f = { x = 1 } } // lldb-command:print b // lldbg-check:(issue_57822::main::{generator#3}) $1 = -- cgit 1.4.1-3-g733a5