Skip to content

Commit ba101d2

Browse files
debuginfo: Support for variables captured in closures and closure type descriptions.
1 parent 89d0400 commit ba101d2

File tree

11 files changed

+555
-188
lines changed

11 files changed

+555
-188
lines changed

src/librustc/lib/llvm.rs

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

2086+
#[fast_ffi]
2087+
pub fn LLVMDIBuilderCreateOpDeref(IntType: TypeRef) -> ValueRef;
2088+
2089+
#[fast_ffi]
2090+
pub fn LLVMDIBuilderCreateOpPlus(IntType: TypeRef) -> ValueRef;
2091+
2092+
#[fast_ffi]
2093+
pub fn LLVMDIBuilderCreateComplexVariable(Builder: DIBuilderRef,
2094+
Tag: c_uint,
2095+
Scope: ValueRef,
2096+
Name: *c_char,
2097+
File: ValueRef,
2098+
LineNo: c_uint,
2099+
Ty: ValueRef,
2100+
AddrOps: *ValueRef,
2101+
AddrOpsCount: c_uint,
2102+
ArgNo: c_uint)
2103+
-> ValueRef;
2104+
20862105
pub fn LLVMInitializeX86TargetInfo();
20872106
pub fn LLVMInitializeX86Target();
20882107
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
@@ -130,20 +130,6 @@ pub fn push_ctxt(s: &'static str) -> _InsnCtxt {
130130
_InsnCtxt { _x: () }
131131
}
132132

133-
fn fcx_has_nonzero_span(fcx: &FunctionContext) -> bool {
134-
match fcx.span {
135-
None => false,
136-
Some(span) => *span.lo != 0 || *span.hi != 0
137-
}
138-
}
139-
140-
fn span_is_empty(opt_span: &Option<span>) -> bool {
141-
match *opt_span {
142-
None => true,
143-
Some(span) => *span.lo == 0 && *span.hi == 0
144-
}
145-
}
146-
147133
struct StatRecorder<'self> {
148134
ccx: @mut CrateContext,
149135
name: &'self str,
@@ -1130,8 +1116,7 @@ pub fn trans_stmt(cx: @mut Block, s: &ast::stmt) -> @mut Block {
11301116
match d.node {
11311117
ast::decl_local(ref local) => {
11321118
bcx = init_local(bcx, *local);
1133-
if cx.sess().opts.extra_debuginfo
1134-
&& fcx_has_nonzero_span(bcx.fcx) {
1119+
if cx.sess().opts.extra_debuginfo {
11351120
debuginfo::create_local_var_metadata(bcx, *local);
11361121
}
11371122
}
@@ -1631,12 +1616,7 @@ pub fn new_fn_ctxt_w_id(ccx: @mut CrateContext,
16311616
}
16321617
};
16331618
let uses_outptr = type_of::return_uses_outptr(ccx.tcx, substd_output_type);
1634-
1635-
let debug_context = if id != -1 && ccx.sess.opts.debuginfo && !span_is_empty(&sp) {
1636-
Some(debuginfo::create_function_debug_context(ccx, id, param_substs, llfndecl))
1637-
} else {
1638-
None
1639-
};
1619+
let debug_context = debuginfo::create_function_debug_context(ccx, id, param_substs, llfndecl);
16401620

16411621
let fcx = @mut FunctionContext {
16421622
llfn: llfndecl,
@@ -1782,7 +1762,7 @@ pub fn copy_args_to_allocas(fcx: @mut FunctionContext,
17821762
fcx.llself = Some(ValSelfData {v: self_val, ..slf});
17831763
add_clean(bcx, self_val, slf.t);
17841764

1785-
if fcx.ccx.sess.opts.extra_debuginfo && fcx_has_nonzero_span(fcx) {
1765+
if fcx.ccx.sess.opts.extra_debuginfo {
17861766
debuginfo::create_self_argument_metadata(bcx, slf.t, self_val);
17871767
}
17881768
}
@@ -1809,7 +1789,7 @@ pub fn copy_args_to_allocas(fcx: @mut FunctionContext,
18091789
};
18101790
bcx = _match::store_arg(bcx, args[arg_n].pat, llarg);
18111791

1812-
if fcx.ccx.sess.opts.extra_debuginfo && fcx_has_nonzero_span(fcx) {
1792+
if fcx.ccx.sess.opts.extra_debuginfo {
18131793
debuginfo::create_argument_metadata(bcx, &args[arg_n]);
18141794
}
18151795
}

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
@@ -227,7 +227,7 @@ pub struct FunctionContext {
227227
ccx: @mut CrateContext,
228228

229229
// Used and maintained by the debuginfo module.
230-
debug_context: Option<~debuginfo::FunctionDebugContext>
230+
debug_context: debuginfo::FunctionDebugContext,
231231
}
232232

233233
impl FunctionContext {

0 commit comments

Comments
 (0)