Skip to content

Commit b81ea86

Browse files
debuginfo: Support for variables captured in closures and closure type descriptions.
1 parent 67555d9 commit b81ea86

File tree

11 files changed

+559
-192
lines changed

11 files changed

+559
-192
lines changed

src/librustc/lib/llvm.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,6 +2084,25 @@ pub mod llvm {
20842084
ColumnNo: c_uint)
20852085
-> ValueRef;
20862086

2087+
#[fast_ffi]
2088+
pub fn LLVMDIBuilderCreateOpDeref(IntType: TypeRef) -> ValueRef;
2089+
2090+
#[fast_ffi]
2091+
pub fn LLVMDIBuilderCreateOpPlus(IntType: TypeRef) -> ValueRef;
2092+
2093+
#[fast_ffi]
2094+
pub fn LLVMDIBuilderCreateComplexVariable(Builder: DIBuilderRef,
2095+
Tag: c_uint,
2096+
Scope: ValueRef,
2097+
Name: *c_char,
2098+
File: ValueRef,
2099+
LineNo: c_uint,
2100+
Ty: ValueRef,
2101+
AddrOps: *ValueRef,
2102+
AddrOpsCount: c_uint,
2103+
ArgNo: c_uint)
2104+
-> ValueRef;
2105+
20872106
pub fn LLVMInitializeX86TargetInfo();
20882107
pub fn LLVMInitializeX86Target();
20892108
pub fn LLVMInitializeX86TargetMC();

src/librustc/middle/moves.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ use syntax::visit;
143143
use syntax::visit::Visitor;
144144
use syntax::codemap::Span;
145145

146-
#[deriving(Encodable, Decodable)]
146+
#[deriving(Eq, Encodable, Decodable)]
147147
pub enum CaptureMode {
148148
CapCopy, // Copy the value into the closure.
149149
CapMove, // Move the value into the closure.

src/librustc/middle/trans/base.rs

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,6 @@ pub fn push_ctxt(s: &'static str) -> _InsnCtxt {
131131
_InsnCtxt { _x: () }
132132
}
133133

134-
fn fcx_has_nonzero_span(fcx: &FunctionContext) -> bool {
135-
match fcx.span {
136-
None => false,
137-
Some(span) => *span.lo != 0 || *span.hi != 0
138-
}
139-
}
140-
141-
fn span_is_empty(opt_span: &Option<Span>) -> bool {
142-
match *opt_span {
143-
None => true,
144-
Some(span) => *span.lo == 0 && *span.hi == 0
145-
}
146-
}
147-
148134
struct StatRecorder<'self> {
149135
ccx: @mut CrateContext,
150136
name: &'self str,
@@ -1132,8 +1118,7 @@ pub fn trans_stmt(cx: @mut Block, s: &ast::Stmt) -> @mut Block {
11321118
match d.node {
11331119
ast::DeclLocal(ref local) => {
11341120
bcx = init_local(bcx, *local);
1135-
if cx.sess().opts.extra_debuginfo
1136-
&& fcx_has_nonzero_span(bcx.fcx) {
1121+
if cx.sess().opts.extra_debuginfo {
11371122
debuginfo::create_local_var_metadata(bcx, *local);
11381123
}
11391124
}
@@ -1633,12 +1618,7 @@ pub fn new_fn_ctxt_w_id(ccx: @mut CrateContext,
16331618
}
16341619
};
16351620
let uses_outptr = type_of::return_uses_outptr(ccx.tcx, substd_output_type);
1636-
1637-
let debug_context = if id != -1 && ccx.sess.opts.debuginfo && !span_is_empty(&sp) {
1638-
Some(debuginfo::create_function_debug_context(ccx, id, param_substs, llfndecl))
1639-
} else {
1640-
None
1641-
};
1621+
let debug_context = debuginfo::create_function_debug_context(ccx, id, param_substs, llfndecl);
16421622

16431623
let fcx = @mut FunctionContext {
16441624
llfn: llfndecl,
@@ -1784,7 +1764,7 @@ pub fn copy_args_to_allocas(fcx: @mut FunctionContext,
17841764
fcx.llself = Some(ValSelfData {v: self_val, ..slf});
17851765
add_clean(bcx, self_val, slf.t);
17861766

1787-
if fcx.ccx.sess.opts.extra_debuginfo && fcx_has_nonzero_span(fcx) {
1767+
if fcx.ccx.sess.opts.extra_debuginfo {
17881768
debuginfo::create_self_argument_metadata(bcx, slf.t, self_val);
17891769
}
17901770
}
@@ -1811,7 +1791,7 @@ pub fn copy_args_to_allocas(fcx: @mut FunctionContext,
18111791
};
18121792
bcx = _match::store_arg(bcx, args[arg_n].pat, llarg);
18131793

1814-
if fcx.ccx.sess.opts.extra_debuginfo && fcx_has_nonzero_span(fcx) {
1794+
if fcx.ccx.sess.opts.extra_debuginfo {
18151795
debuginfo::create_argument_metadata(bcx, &args[arg_n]);
18161796
}
18171797
}

src/librustc/middle/trans/closure.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use middle::trans::base::*;
1717
use middle::trans::build::*;
1818
use middle::trans::common::*;
1919
use middle::trans::datum::{Datum, INIT};
20+
use middle::trans::debuginfo;
2021
use middle::trans::expr;
2122
use middle::trans::glue;
2223
use middle::trans::type_of::*;
@@ -317,6 +318,11 @@ pub fn load_environment(fcx: @mut FunctionContext,
317318
}
318319
let def_id = ast_util::def_id_of_def(cap_var.def);
319320
fcx.llupvars.insert(def_id.node, upvarptr);
321+
322+
if fcx.ccx.sess.opts.extra_debuginfo {
323+
debuginfo::create_captured_var_metadata(bcx, def_id.node, upvarptr, cap_var.span);
324+
}
325+
320326
i += 1u;
321327
}
322328
}

src/librustc/middle/trans/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ pub struct FunctionContext {
228228
ccx: @mut CrateContext,
229229

230230
// Used and maintained by the debuginfo module.
231-
debug_context: Option<~debuginfo::FunctionDebugContext>
231+
debug_context: debuginfo::FunctionDebugContext,
232232
}
233233

234234
impl FunctionContext {

0 commit comments

Comments
 (0)