auto merge of #8855 : michaelwoerister/rust/captured_vars, r=jdm
This pull request includes
* support for variables captured in closures*,
* a fix for issue #8512: arguments of non-immediate type (structs, tuples, etc) passed by value can now be accessed correctly in GDB. (I managed to fix this by using `llvm::DIBuilder::createComplexVariable()`. ~~However, I am not sure if this relies on unstable implementation details of LLVM's debug info handling. I'll try to clarify this on the LLVM mailing list~~).
* simplification of the `debuginfo` module's public interface: the caller of functions like `create_local_var_metadata()` doesn't have to know and catch all cases when it mustn't call the function,
* a cleanup refactoring with unified handling for locals, [self] arguments, captured variables, and match bindings,
* and proper span information for self arguments.
\* However, see comment at 1d916ace13/src/test/debug-info/var-captured-in-nested-closure.rs (L62) . This is the same problem as with the fix for issue #8512 above: We are probably using `llvm.dbg.declare` in an unsupported way that works today but might not work after the next LLVM update.
Cheers,
Michael
Fixes #8512
Fixes #1341
This commit is contained in:
commit
45c3ca72bc
17 changed files with 897 additions and 233 deletions
99
src/test/debug-info/by-value-non-immediate-argument.rs
Normal file
99
src/test/debug-info/by-value-non-immediate-argument.rs
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags:-Z extra-debug-info
|
||||
// debugger:break zzz
|
||||
// debugger:run
|
||||
|
||||
// debugger:finish
|
||||
// debugger:print s
|
||||
// check:$1 = {a = 1, b = 2.5}
|
||||
// debugger:continue
|
||||
|
||||
// debugger:finish
|
||||
// debugger:print x
|
||||
// check:$2 = {a = 3, b = 4.5}
|
||||
// debugger:print y
|
||||
// check:$3 = 5
|
||||
// debugger:print z
|
||||
// check:$4 = 6.5
|
||||
// debugger:continue
|
||||
|
||||
// debugger:finish
|
||||
// debugger:print a
|
||||
// check:$5 = {7, 8, 9.5, 10.5}
|
||||
// debugger:continue
|
||||
|
||||
// debugger:finish
|
||||
// debugger:print a
|
||||
// check:$6 = {11.5, 12.5, 13, 14}
|
||||
// debugger:continue
|
||||
|
||||
// debugger:finish
|
||||
// debugger:print x
|
||||
// check:$7 = {{Case1, x = 0, y = 8970181431921507452}, {Case1, 0, 2088533116, 2088533116}}
|
||||
// debugger:continue
|
||||
|
||||
#[deriving(Clone)]
|
||||
struct Struct {
|
||||
a: int,
|
||||
b: float
|
||||
}
|
||||
|
||||
#[deriving(Clone)]
|
||||
struct StructStruct {
|
||||
a: Struct,
|
||||
b: Struct
|
||||
}
|
||||
|
||||
fn fun(s: Struct) {
|
||||
zzz();
|
||||
}
|
||||
|
||||
fn fun_fun(StructStruct { a: x, b: Struct { a: y, b: z } }: StructStruct) {
|
||||
zzz();
|
||||
}
|
||||
|
||||
fn tup(a: (int, uint, float, float)) {
|
||||
zzz();
|
||||
}
|
||||
|
||||
struct Newtype(float, float, int, uint);
|
||||
|
||||
fn new_type(a: Newtype) {
|
||||
zzz();
|
||||
}
|
||||
|
||||
// The first element is to ensure proper alignment, irrespective of the machines word size. Since
|
||||
// the size of the discriminant value is machine dependent, this has be taken into account when
|
||||
// datatype layout should be predictable as in this case.
|
||||
enum Enum {
|
||||
Case1 { x: i64, y: i64 },
|
||||
Case2 (i64, i32, i32),
|
||||
}
|
||||
|
||||
fn by_val_enum(x: Enum) {
|
||||
zzz();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
fun(Struct { a: 1, b: 2.5 });
|
||||
fun_fun(StructStruct { a: Struct { a: 3, b: 4.5 }, b: Struct { a: 5, b: 6.5 } });
|
||||
tup((7, 8, 9.5, 10.5));
|
||||
new_type(Newtype(11.5, 12.5, 13, 14));
|
||||
|
||||
// 0b0111110001111100011111000111110001111100011111000111110001111100 = 8970181431921507452
|
||||
// 0b01111100011111000111110001111100 = 2088533116
|
||||
// 0b0111110001111100 = 31868
|
||||
// 0b01111100 = 124
|
||||
by_val_enum(Case1 { x: 0, y: 8970181431921507452 });
|
||||
}
|
||||
|
||||
fn zzz() {()}
|
||||
79
src/test/debug-info/by-value-self-argument-in-trait-impl.rs
Normal file
79
src/test/debug-info/by-value-self-argument-in-trait-impl.rs
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags:-Z extra-debug-info
|
||||
// debugger:break zzz
|
||||
// debugger:run
|
||||
|
||||
// debugger:finish
|
||||
// debugger:print self
|
||||
// check:$1 = 1111
|
||||
// debugger:continue
|
||||
|
||||
// debugger:finish
|
||||
// debugger:print self
|
||||
// check:$2 = {x = 2222, y = 3333}
|
||||
// debugger:continue
|
||||
|
||||
// debugger:finish
|
||||
// debugger:print self
|
||||
// check:$3 = {4444.5, 5555, 6666, 7777.5}
|
||||
// debugger:continue
|
||||
|
||||
// debugger:finish
|
||||
// debugger:print self->val
|
||||
// check:$4 = 8888
|
||||
// debugger:continue
|
||||
|
||||
trait Trait {
|
||||
fn method(self) -> Self;
|
||||
}
|
||||
|
||||
impl Trait for int {
|
||||
fn method(self) -> int {
|
||||
zzz();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
struct Struct {
|
||||
x: uint,
|
||||
y: uint,
|
||||
}
|
||||
|
||||
impl Trait for Struct {
|
||||
fn method(self) -> Struct {
|
||||
zzz();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Trait for (float, int, int, float) {
|
||||
fn method(self) -> (float, int, int, float) {
|
||||
zzz();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Trait for @int {
|
||||
fn method(self) -> @int {
|
||||
zzz();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _ = (1111 as int).method();
|
||||
let _ = Struct { x: 2222, y: 3333 }.method();
|
||||
let _ = (4444.5, 5555, 6666, 7777.5).method();
|
||||
let _ = (@8888).method();
|
||||
}
|
||||
|
||||
fn zzz() {()}
|
||||
56
src/test/debug-info/var-captured-in-managed-closure.rs
Normal file
56
src/test/debug-info/var-captured-in-managed-closure.rs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags:-Z extra-debug-info
|
||||
// debugger:break zzz
|
||||
// debugger:run
|
||||
// debugger:finish
|
||||
|
||||
// debugger:print constant
|
||||
// check:$1 = 1
|
||||
// debugger:print a_struct
|
||||
// check:$2 = {a = -2, b = 3.5, c = 4}
|
||||
// debugger:print *owned
|
||||
// check:$3 = 5
|
||||
// debugger:print managed->val
|
||||
// check:$4 = 6
|
||||
|
||||
#[allow(unused_variable)];
|
||||
|
||||
struct Struct {
|
||||
a: int,
|
||||
b: float,
|
||||
c: uint
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let constant = 1;
|
||||
|
||||
let a_struct = Struct {
|
||||
a: -2,
|
||||
b: 3.5,
|
||||
c: 4
|
||||
};
|
||||
|
||||
let owned = ~5;
|
||||
let managed = @6;
|
||||
|
||||
let closure: @fn() = || {
|
||||
zzz();
|
||||
do_something(&constant, &a_struct.a, owned, managed);
|
||||
};
|
||||
|
||||
closure();
|
||||
}
|
||||
|
||||
fn do_something(_: &int, _:&int, _:&int, _:&int) {
|
||||
}
|
||||
|
||||
fn zzz() {()}
|
||||
87
src/test/debug-info/var-captured-in-nested-closure.rs
Normal file
87
src/test/debug-info/var-captured-in-nested-closure.rs
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags:-Z extra-debug-info
|
||||
// debugger:break zzz
|
||||
// debugger:run
|
||||
// debugger:finish
|
||||
|
||||
// debugger:print variable
|
||||
// check:$1 = 1
|
||||
// debugger:print constant
|
||||
// check:$2 = 2
|
||||
// debugger:print a_struct
|
||||
// check:$3 = {a = -3, b = 4.5, c = 5}
|
||||
// debugger:print *struct_ref
|
||||
// check:$4 = {a = -3, b = 4.5, c = 5}
|
||||
// debugger:print *owned
|
||||
// check:$5 = 6
|
||||
// debugger:print managed->val
|
||||
// check:$6 = 7
|
||||
// debugger:print closure_local
|
||||
// check:$7 = 8
|
||||
// debugger:continue
|
||||
|
||||
// debugger:finish
|
||||
// debugger:print variable
|
||||
// check:$8 = 1
|
||||
// debugger:print constant
|
||||
// check:$9 = 2
|
||||
// debugger:print a_struct
|
||||
// check:$10 = {a = -3, b = 4.5, c = 5}
|
||||
// debugger:print *struct_ref
|
||||
// check:$11 = {a = -3, b = 4.5, c = 5}
|
||||
// debugger:print *owned
|
||||
// check:$12 = 6
|
||||
// debugger:print managed->val
|
||||
// check:$13 = 7
|
||||
// debugger:print closure_local
|
||||
// check:$14 = 8
|
||||
// debugger:continue
|
||||
|
||||
#[allow(unused_variable)];
|
||||
|
||||
struct Struct {
|
||||
a: int,
|
||||
b: float,
|
||||
c: uint
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut variable = 1;
|
||||
let constant = 2;
|
||||
|
||||
let a_struct = Struct {
|
||||
a: -3,
|
||||
b: 4.5,
|
||||
c: 5
|
||||
};
|
||||
|
||||
let struct_ref = &a_struct;
|
||||
let owned = ~6;
|
||||
let managed = @7;
|
||||
|
||||
let closure = || {
|
||||
let closure_local = 8;
|
||||
|
||||
let nested_closure = || {
|
||||
zzz();
|
||||
variable = constant + a_struct.a + struct_ref.a + *owned + *managed + closure_local;
|
||||
};
|
||||
|
||||
zzz();
|
||||
|
||||
nested_closure();
|
||||
};
|
||||
|
||||
closure();
|
||||
}
|
||||
|
||||
fn zzz() {()}
|
||||
|
|
@ -8,30 +8,47 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Does not work yet, see issue #8512
|
||||
// xfail-test
|
||||
|
||||
// compile-flags:-Z extra-debug-info
|
||||
// debugger:break zzz
|
||||
// debugger:run
|
||||
|
||||
// debugger:finish
|
||||
// debugger:print s
|
||||
// check:$1 = {a = 1, b = 2.5}
|
||||
// debugger:continue
|
||||
|
||||
#[deriving(Clone)]
|
||||
// debugger:print constant
|
||||
// check:$1 = 1
|
||||
// debugger:print a_struct
|
||||
// check:$2 = {a = -2, b = 3.5, c = 4}
|
||||
// debugger:print *owned
|
||||
// check:$3 = 5
|
||||
|
||||
#[allow(unused_variable)];
|
||||
|
||||
struct Struct {
|
||||
a: int,
|
||||
b: float
|
||||
}
|
||||
|
||||
fn fun(s: Struct) {
|
||||
zzz();
|
||||
b: float,
|
||||
c: uint
|
||||
}
|
||||
|
||||
fn main() {
|
||||
fun(Struct { a: 1, b: 2.5 });
|
||||
let constant = 1;
|
||||
|
||||
let a_struct = Struct {
|
||||
a: -2,
|
||||
b: 3.5,
|
||||
c: 4
|
||||
};
|
||||
|
||||
let owned = ~5;
|
||||
|
||||
let closure: ~fn() = || {
|
||||
zzz();
|
||||
do_something(&constant, &a_struct.a, owned);
|
||||
};
|
||||
|
||||
closure();
|
||||
}
|
||||
|
||||
fn do_something(_: &int, _:&int, _:&int) {
|
||||
|
||||
}
|
||||
|
||||
fn zzz() {()}
|
||||
59
src/test/debug-info/var-captured-in-stack-closure.rs
Normal file
59
src/test/debug-info/var-captured-in-stack-closure.rs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags:-Z extra-debug-info
|
||||
// debugger:break zzz
|
||||
// debugger:run
|
||||
// debugger:finish
|
||||
|
||||
// debugger:print variable
|
||||
// check:$1 = 1
|
||||
// debugger:print constant
|
||||
// check:$2 = 2
|
||||
// debugger:print a_struct
|
||||
// check:$3 = {a = -3, b = 4.5, c = 5}
|
||||
// debugger:print *struct_ref
|
||||
// check:$4 = {a = -3, b = 4.5, c = 5}
|
||||
// debugger:print *owned
|
||||
// check:$5 = 6
|
||||
// debugger:print managed->val
|
||||
// check:$6 = 7
|
||||
|
||||
#[allow(unused_variable)];
|
||||
|
||||
struct Struct {
|
||||
a: int,
|
||||
b: float,
|
||||
c: uint
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut variable = 1;
|
||||
let constant = 2;
|
||||
|
||||
let a_struct = Struct {
|
||||
a: -3,
|
||||
b: 4.5,
|
||||
c: 5
|
||||
};
|
||||
|
||||
let struct_ref = &a_struct;
|
||||
let owned = ~6;
|
||||
let managed = @7;
|
||||
|
||||
let closure = || {
|
||||
zzz();
|
||||
variable = constant + a_struct.a + struct_ref.a + *owned + *managed;
|
||||
};
|
||||
|
||||
closure();
|
||||
}
|
||||
|
||||
fn zzz() {()}
|
||||
Loading…
Add table
Add a link
Reference in a new issue