diff options
| author | lrh2000 <lrh2000@pku.edu.cn> | 2021-05-05 23:50:44 +0800 |
|---|---|---|
| committer | lrh2000 <lrh2000@pku.edu.cn> | 2021-07-09 23:06:53 +0800 |
| commit | 29856acffeb87541bb167c33f4fdb13c31ba6de0 (patch) | |
| tree | 2bbb04127b4609350704b956985e38371cc62ca5 /src/test/debuginfo | |
| parent | 95fb1315217976ff4c268bb03c9b4132f0dfa9fd (diff) | |
| download | rust-29856acffeb87541bb167c33f4fdb13c31ba6de0.tar.gz rust-29856acffeb87541bb167c33f4fdb13c31ba6de0.zip | |
Name the captured upvars for closures/generators in debuginfo
Previously, debuggers print closures as something like
```
y::main::closure-0 (0x7fffffffdd34)
```
The pointer actually references to an upvar. It is not
very obvious, especially for beginners.
It's because upvars don't have names before, as they
are packed into a tuple. This commit names the upvars,
so we can expect to see something like
```
y::main::closure-0 {_captured_ref__b: 0x[...]}
```
Diffstat (limited to 'src/test/debuginfo')
| -rw-r--r-- | src/test/debuginfo/captured-fields.rs | 87 | ||||
| -rw-r--r-- | src/test/debuginfo/generator-objects.rs | 8 | ||||
| -rw-r--r-- | src/test/debuginfo/issue-57822.rs | 6 |
3 files changed, 94 insertions, 7 deletions
diff --git a/src/test/debuginfo/captured-fields.rs b/src/test/debuginfo/captured-fields.rs new file mode 100644 index 00000000000..5489fa14720 --- /dev/null +++ b/src/test/debuginfo/captured-fields.rs @@ -0,0 +1,87 @@ +// 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 7ac3304aa96..46a3d7924a1 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(0x[...]) +// gdb-check:$1 = generator_objects::main::{generator#0}::Unresumed{_captured_ref__a: 0x[...]} // gdb-command:continue // gdb-command:print b -// gdb-check:$2 = generator_objects::main::{generator#0}::Suspend0{c: 6, d: 7, __0: 0x[...]} +// gdb-check:$2 = generator_objects::main::{generator#0}::Suspend0{c: 6, d: 7, _captured_ref__a: 0x[...]} // gdb-command:continue // gdb-command:print b -// gdb-check:$3 = generator_objects::main::{generator#0}::Suspend1{c: 7, d: 8, __0: 0x[...]} +// gdb-check:$3 = generator_objects::main::{generator#0}::Suspend1{c: 7, d: 8, _captured_ref__a: 0x[...]} // gdb-command:continue // gdb-command:print b -// gdb-check:$4 = generator_objects::main::{generator#0}::Returned(0x[...]) +// gdb-check:$4 = generator_objects::main::{generator#0}::Returned{_captured_ref__a: 0x[...]} // === LLDB TESTS ================================================================================== diff --git a/src/test/debuginfo/issue-57822.rs b/src/test/debuginfo/issue-57822.rs index f6d2146fe11..22d55ae989f 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} (issue_57822::main::{closure#0} (1)) +// gdb-check:$1 = issue_57822::main::{closure#1} {_captured_val__f: issue_57822::main::{closure#0} {_captured_val__x: 1}} // gdb-command:print b -// gdb-check:$2 = issue_57822::main::{generator#3}::Unresumed(issue_57822::main::{generator#2}::Unresumed(2)) +// gdb-check:$2 = issue_57822::main::{generator#3}::Unresumed{_captured_val__a: issue_57822::main::{generator#2}::Unresumed{_captured_val__y: 2}} // === LLDB TESTS ================================================================================== // lldb-command:run // lldb-command:print g -// lldbg-check:(issue_57822::main::{closure#1}) $0 = { 0 = { 0 = 1 } } +// lldbg-check:(issue_57822::main::{closure#1}) $0 = { _captured_val__f = { _captured_val__x = 1 } } // lldb-command:print b // lldbg-check:(issue_57822::main::{generator#3}) $1 = |
