提交 0b303523 编写于 作者: J Josh Matthews

Fix up local variable support so it actually works.

上级 e95c56f8
......@@ -221,7 +221,7 @@ fn get_ty_metadata(cx: @crate_ctxt, t: ty::t, ty: @ast::ty) -> @metadata<tydesc_
option::some(md) { ret md; }
option::none. {}
}
let (name, size, flags) = alt ty.node {
let (name, size, encoding) = alt ty.node {
ast::ty_bool. { ("bool", 1, DW_ATE_boolean) }
ast::ty_int. { ("int", 32, DW_ATE_signed) } //XXX machine-dependent?
ast::ty_uint. { ("uint", 32, DW_ATE_unsigned) } //XXX machine-dependent?
......@@ -240,15 +240,19 @@ fn get_ty_metadata(cx: @crate_ctxt, t: ty::t, ty: @ast::ty) -> @metadata<tydesc_
} }
ast::ty_char. { ("char", 32, DW_ATE_unsigned) }
};
let fname = filename_from_span(cx, ty.span);
let file_node = get_file_metadata(cx, fname);
let cu_node = get_compile_unit_metadata(cx, fname);
let lldata = [lltag(BasicTypeDescriptorTag),
llunused(), //XXX scope context
cu_node.node,
llstr(name),
llnull(), //XXX basic types only
file_node.node,
lli32(0), //XXX basic types only
lli64(size),
lli64(32), //XXX alignment?
lli64(0), //XXX offset?
lli32(flags)];
lli32(0), //XXX flags?
lli32(encoding)];
let llnode = llmdnode(lldata);
let mdval = @{node: llnode, data: {hash: ty::hash_ty(t)}};
update_cache(cache, BasicTypeDescriptorTag, tydesc_metadata(mdval));
......@@ -266,6 +270,10 @@ fn function_metadata_from_block(bcx: @block_ctxt) -> @metadata<subprogram_md> {
get_function_metadata(cx, fn_item, fcx.llfn)
}
fn filename_from_span(cx: @crate_ctxt, sp: codemap::span) -> str {
codemap::lookup_char_pos(cx.sess.get_codemap(), sp.lo).filename
}
fn get_local_var_metadata(bcx: @block_ctxt, local: @ast::local)
-> @metadata<local_var_md> unsafe {
let cx = bcx_ccx(bcx);
......@@ -293,8 +301,7 @@ fn get_local_var_metadata(bcx: @block_ctxt, local: @ast::local)
filemd.node,
lli32(loc.line as int), // line
tymd.node,
lli32(0), //XXX flags
llnull() // inline loc reference
lli32(0) //XXX flags
];
let mdnode = llmdnode(lldata);
let mdval = @{node: mdnode, data: {id: local.node.id}};
......@@ -310,9 +317,6 @@ fn get_local_var_metadata(bcx: @block_ctxt, local: @ast::local)
let declargs = [llmdnode([llptr]), mdnode];
trans_build::Call(bcx, cx.intrinsics.get("llvm.dbg.declare"),
declargs);
llvm::LLVMAddNamedMetadataOperand(cx.llmod, as_buf("llvm.dbg.vars"),
str::byte_len("llvm.dbg.vars"),
mdnode);
ret mdval;
}
......
......@@ -23,7 +23,7 @@
import middle::{ty, gc, resolve, debuginfo};
import middle::freevars::*;
import back::{link, abi, upcall};
import syntax::{ast, ast_util};
import syntax::{ast, ast_util, codemap};
import syntax::visit;
import syntax::codemap::span;
import syntax::print::pprust::{expr_to_str, stmt_to_str};
......@@ -4038,10 +4038,22 @@ fn trans_stmt(cx: @block_ctxt, s: ast::stmt) -> @block_ctxt {
_ { bcx_ccx(cx).sess.unimpl("stmt variant"); }
}
//debuginfo::reset_source_pos(cx);
ret bcx;
}
fn source_pos_from_block_parent(parent: block_parent)
-> (bool, [codemap::loc]) {
alt parent {
parent_none. { (false, []) }
parent_some(bcx) { (bcx.source_pos.usable,
alt vec::last(bcx.source_pos.pos) {
option::some(p) { [p] }
option::none. { [] }
})
}
}
}
// You probably don't want to use this one. See the
// next three functions instead.
fn new_block_ctxt(cx: @fn_ctxt, parent: block_parent, kind: block_kind,
......@@ -4053,6 +4065,7 @@ fn new_block_ctxt(cx: @fn_ctxt, parent: block_parent, kind: block_kind,
}
let llbb: BasicBlockRef =
str::as_buf(s, {|buf| llvm::LLVMAppendBasicBlock(cx.llfn, buf) });
let (usable, pos) = source_pos_from_block_parent(parent);
let bcx = @{llbb: llbb,
mutable terminated: false,
mutable unreachable: false,
......@@ -4063,8 +4076,7 @@ fn new_block_ctxt(cx: @fn_ctxt, parent: block_parent, kind: block_kind,
mutable lpad: option::none,
sp: cx.sp,
fcx: cx,
source_pos: {mutable usable: false,
mutable pos: []}};
source_pos: {mutable usable: usable, mutable pos: pos}};
alt parent {
parent_some(cx) {
if cx.unreachable { Unreachable(bcx); }
......@@ -4099,6 +4111,7 @@ fn new_sub_block_ctxt(bcx: @block_ctxt, n: str) -> @block_ctxt {
}
fn new_raw_block_ctxt(fcx: @fn_ctxt, llbb: BasicBlockRef) -> @block_ctxt {
let (usable, pos) = source_pos_from_block_parent(parent_none);
ret @{llbb: llbb,
mutable terminated: false,
mutable unreachable: false,
......@@ -4109,8 +4122,7 @@ fn new_raw_block_ctxt(fcx: @fn_ctxt, llbb: BasicBlockRef) -> @block_ctxt {
mutable lpad: option::none,
sp: fcx.sp,
fcx: fcx,
source_pos: {mutable usable: false,
mutable pos: []}};
source_pos: {mutable usable: usable, mutable pos: pos}};
}
......@@ -4168,6 +4180,7 @@ fn block_locals(b: ast::blk, it: block(@ast::local)) {
}
fn llstaticallocas_block_ctxt(fcx: @fn_ctxt) -> @block_ctxt {
let (usable, pos) = source_pos_from_block_parent(parent_none);
ret @{llbb: fcx.llstaticallocas,
mutable terminated: false,
mutable unreachable: false,
......@@ -4178,11 +4191,11 @@ fn llstaticallocas_block_ctxt(fcx: @fn_ctxt) -> @block_ctxt {
mutable lpad: option::none,
sp: fcx.sp,
fcx: fcx,
source_pos: {mutable usable: false,
mutable pos: []}};
source_pos: {mutable usable: usable, mutable pos: pos}};
}
fn llderivedtydescs_block_ctxt(fcx: @fn_ctxt) -> @block_ctxt {
let (usable, pos) = source_pos_from_block_parent(parent_none);
ret @{llbb: fcx.llderivedtydescs,
mutable terminated: false,
mutable unreachable: false,
......@@ -4193,8 +4206,7 @@ fn llderivedtydescs_block_ctxt(fcx: @fn_ctxt) -> @block_ctxt {
mutable lpad: option::none,
sp: fcx.sp,
fcx: fcx,
source_pos: {mutable usable: false,
mutable pos: []}};
source_pos: {mutable usable: usable, mutable pos: pos}};
}
......@@ -4271,14 +4283,12 @@ fn trans_block_dps(bcx: @block_ctxt, b: ast::blk, dest: dest)
for s: @ast::stmt in b.node.stmts {
let _s = debuginfo::update_source_pos(bcx, b.span);
bcx = trans_stmt(bcx, *s);
//debuginfo::reset_source_pos(bcx);
}
alt b.node.expr {
some(e) {
let bt = ty::type_is_bot(bcx_tcx(bcx), ty::expr_ty(bcx_tcx(bcx), e));
let _s = debuginfo::update_source_pos(bcx, e.span);
bcx = trans_expr(bcx, e, bt ? ignore : dest);
//debuginfo::reset_source_pos(bcx);
}
_ { assert dest == ignore || bcx.unreachable; }
}
......
......@@ -670,7 +670,7 @@ fn Call(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef]) -> ValueRef {
unsafe {
let instr = llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args),
vec::len(Args), noname());
//debuginfo::add_line_info(cx, instr);
debuginfo::add_line_info(cx, instr);
ret instr;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册