Skip to content

Commit 9aabe9a

Browse files
committed
---
yaml --- r: 6816 b: refs/heads/master c: 6c26b89 h: refs/heads/master v: v3
1 parent eb029f9 commit 9aabe9a

File tree

4 files changed

+131
-10
lines changed

4 files changed

+131
-10
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 0752252737d530db5b81ebd3127c622f6ec92712
2+
refs/heads/master: 6c26b892e422b7ea8d4576f074dc2e9af52caed4

trunk/src/comp/middle/debuginfo.rs

Lines changed: 110 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import lib::llvm::llvm;
44
import lib::llvm::llvm::ValueRef;
55
import middle::trans_common::*;
66
import middle::ty;
7-
import ast::ty;
87
import syntax::{ast, codemap};
8+
import ast::ty;
99

10-
const LLVMDebugVersion: int = (9 << 16); //& 0xffff0000; // 0x80000 ?
10+
const LLVMDebugVersion: int = (9 << 16);
1111

1212
const DW_LANG_RUST: int = 0x9000;
1313
const DW_VIRTUALITY_none: int = 0;
@@ -78,6 +78,8 @@ type subprogram_md = {name: str, file: str};
7878
type local_var_md = {id: ast::node_id};
7979
type tydesc_md = {hash: uint};
8080
type block_md = {start: codemap::loc, end: codemap::loc};
81+
type argument_md = {id: ast::node_id};
82+
type retval_md = {id: ast::node_id};
8183

8284
type metadata_cache = hashmap<int, [debug_metadata]>;
8385

@@ -88,9 +90,11 @@ tag debug_metadata {
8890
local_var_metadata(@metadata<local_var_md>);
8991
tydesc_metadata(@metadata<tydesc_md>);
9092
block_metadata(@metadata<block_md>);
93+
argument_metadata(@metadata<argument_md>);
94+
retval_metadata(@metadata<retval_md>);
9195
}
9296

93-
fn cast_safely<T, U>(val: T) -> U unsafe {
97+
fn cast_safely<copy T, U>(val: T) -> U unsafe {
9498
let val2 = val;
9599
let val3 = unsafe::reinterpret_cast(val2);
96100
unsafe::leak(val2);
@@ -105,11 +109,13 @@ fn md_from_metadata<T>(val: debug_metadata) -> T unsafe {
105109
local_var_metadata(md) { cast_safely(md) }
106110
tydesc_metadata(md) { cast_safely(md) }
107111
block_metadata(md) { cast_safely(md) }
112+
argument_metadata(md) { cast_safely(md) }
113+
retval_metadata(md) { cast_safely(md) }
108114
}
109115
}
110116

111-
fn cached_metadata<T>(cache: metadata_cache, mdtag: int,
112-
eq: block(md: T) -> bool) -> option::t<T> unsafe {
117+
fn cached_metadata<copy T>(cache: metadata_cache, mdtag: int,
118+
eq: block(md: T) -> bool) -> option::t<T> unsafe {
113119
if cache.contains_key(mdtag) {
114120
let items = cache.get(mdtag);
115121
for item in items {
@@ -270,7 +276,7 @@ fn function_metadata_from_block(bcx: @block_ctxt) -> @metadata<subprogram_md> {
270276
let fcx = bcx_fcx(bcx);
271277
let fn_node = cx.ast_map.get(fcx.id);
272278
let fn_item = alt fn_node { ast_map::node_item(item) { item } };
273-
get_function_metadata(cx, fn_item, fcx.llfn)
279+
get_function_metadata(fcx, fn_item, fcx.llfn)
274280
}
275281

276282
fn filename_from_span(cx: @crate_ctxt, sp: codemap::span) -> str {
@@ -323,6 +329,98 @@ fn get_local_var_metadata(bcx: @block_ctxt, local: @ast::local)
323329
ret mdval;
324330
}
325331

332+
//FIXME: consolidate with get_local_var_metadata
333+
/*fn get_retval_metadata(bcx: @block_ctxt)
334+
-> @metadata<retval_md> unsafe {
335+
let fcx = bcx_fcx(bcx);
336+
let cx = fcx_ccx(fcx);
337+
let cache = cx.llmetadata;
338+
alt cached_metadata::<@metadata<retval_md>>(
339+
cache, ReturnVariableTag, {|md| md.data.id == fcx.id}) {
340+
option::some(md) { ret md; }
341+
option::none. {}
342+
}
343+
let item = alt option::get(cx.ast_map.find(fcx.id)) {
344+
ast_map::node_item(item) { item }
345+
};
346+
let loc = codemap::lookup_char_pos(cx.sess.get_codemap(),
347+
fcx.sp.lo);
348+
let ret_ty = alt item.node {
349+
ast::item_fn(f, _) { f.decl.output }
350+
};
351+
let ty_node = alt ret_ty.node {
352+
ast::ty_nil. { llnull() }
353+
_ { get_ty_metadata(cx, ty::node_id_to_type(ccx_tcx(cx), item.id),
354+
ret_ty).node }
355+
};
356+
/*let ty_node = get_ty_metadata(cx, ty::node_id_to_type(ccx_tcx(cx), fcx.id),
357+
ty).node;*/
358+
//let ty = trans::node_id_type(cx, arg.id);
359+
//let tymd = get_ty_metadata(cx, ty, arg.ty);
360+
let filemd = get_file_metadata(cx, loc.filename);
361+
let fn_node = cx.ast_map.get(fcx.id);
362+
let fn_item = alt fn_node { ast_map::node_item(item) { item } };
363+
let context = get_function_metadata(fcx, fn_item, fcx.llfn);
364+
let lldata = [lltag(ReturnVariableTag),
365+
context.node, // context
366+
llstr("%0"), // name
367+
filemd.node,
368+
lli32(loc.line as int), // line
369+
ty_node,
370+
lli32(0) //XXX flags
371+
];
372+
let mdnode = llmdnode(lldata);
373+
let mdval = @{node: mdnode, data: {id: fcx.id}};
374+
update_cache(cache, ReturnVariableTag, retval_metadata(mdval));
375+
let llptr = fcx.llretptr;
376+
let declargs = [llmdnode([llptr]), mdnode];
377+
trans_build::Call(bcx, cx.intrinsics.get("llvm.dbg.declare"),
378+
declargs);
379+
ret mdval;
380+
}*/
381+
382+
//FIXME: consolidate with get_local_var_metadata
383+
fn get_arg_metadata(bcx: @block_ctxt, arg: ast::arg)
384+
-> @metadata<argument_md> unsafe {
385+
let fcx = bcx_fcx(bcx);
386+
let cx = fcx_ccx(fcx);
387+
let cache = cx.llmetadata;
388+
alt cached_metadata::<@metadata<argument_md>>(
389+
cache, ArgVariableTag, {|md| md.data.id == arg.id}) {
390+
option::some(md) { ret md; }
391+
option::none. {}
392+
}
393+
let arg_n = alt cx.ast_map.get(arg.id) {
394+
ast_map::node_arg(_, n) { n - 2u }
395+
};
396+
let loc = codemap::lookup_char_pos(cx.sess.get_codemap(),
397+
fcx.sp.lo);
398+
let ty = trans::node_id_type(cx, arg.id);
399+
let tymd = get_ty_metadata(cx, ty, arg.ty);
400+
let filemd = get_file_metadata(cx, loc.filename);
401+
let fn_node = cx.ast_map.get(fcx.id);
402+
let fn_item = alt fn_node { ast_map::node_item(item) { item } };
403+
let context = get_function_metadata(fcx, fn_item, fcx.llfn);
404+
let lldata = [lltag(ArgVariableTag),
405+
context.node, // context
406+
llstr(arg.ident), // name
407+
filemd.node,
408+
lli32(loc.line as int), // line
409+
tymd.node,
410+
lli32(0) //XXX flags
411+
];
412+
let mdnode = llmdnode(lldata);
413+
let mdval = @{node: mdnode, data: {id: arg.id}};
414+
update_cache(cache, ArgVariableTag, argument_metadata(mdval));
415+
let llptr = alt fcx.llargs.get(arg.id) {
416+
local_mem(v) | local_imm(v) { v }
417+
};
418+
let declargs = [llmdnode([llptr]), mdnode];
419+
trans_build::Call(bcx, cx.intrinsics.get("llvm.dbg.declare"),
420+
declargs);
421+
ret mdval;
422+
}
423+
326424
fn update_source_pos(cx: @block_ctxt, s: codemap::span) -> @debug_source_pos {
327425
let dsp = @debug_source_pos(cx);
328426
if !bcx_ccx(cx).sess.get_opts().debuginfo {
@@ -384,8 +482,9 @@ fn add_line_info(cx: @block_ctxt, llinstr: ValueRef) {
384482
llvm::LLVMSetMetadata(llinstr, kind_id, dbgscope);
385483
}
386484

387-
fn get_function_metadata(cx: @crate_ctxt, item: @ast::item,
485+
fn get_function_metadata(fcx: @fn_ctxt, item: @ast::item,
388486
llfndecl: ValueRef) -> @metadata<subprogram_md> {
487+
let cx = fcx_ccx(fcx);
389488
let cache = cx.llmetadata;
390489
alt cached_metadata::<@metadata<subprogram_md>>(
391490
cache, SubprogramTag, {|md| md.data.name == item.ident &&
@@ -448,5 +547,9 @@ fn get_function_metadata(cx: @crate_ctxt, item: @ast::item,
448547
let mdval = @{node: val, data: {name: item.ident,
449548
file: loc.filename}};
450549
update_cache(cache, SubprogramTag, subprogram_metadata(mdval));
550+
/*alt ret_ty.node {
551+
ast::ty_nil. {}
552+
_ { let _ = get_retval_metadata(fcx, ret_ty); }
553+
}*/
451554
ret mdval;
452555
}

trunk/src/comp/middle/trans.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4422,6 +4422,12 @@ fn create_llargs_for_fn_args(cx: @fn_ctxt, ty_self: self_arg,
44224422

44234423
fn copy_args_to_allocas(fcx: @fn_ctxt, bcx: @block_ctxt, args: [ast::arg],
44244424
arg_tys: [ty::arg]) -> @block_ctxt {
4425+
if fcx_ccx(fcx).sess.get_opts().debuginfo {
4426+
llvm::LLVMAddAttribute(llvm::LLVMGetFirstParam(fcx.llfn),
4427+
lib::llvm::LLVMStructRetAttribute as
4428+
lib::llvm::llvm::Attribute);
4429+
//let _ = debuginfo::get_retval_metadata(bcx);
4430+
}
44254431
let arg_n: uint = 0u, bcx = bcx;
44264432
for arg in arg_tys {
44274433
let id = args[arg_n].id;
@@ -4441,6 +4447,9 @@ fn copy_args_to_allocas(fcx: @fn_ctxt, bcx: @block_ctxt, args: [ast::arg],
44414447
}
44424448
ast::by_ref. {}
44434449
}
4450+
if fcx_ccx(fcx).sess.get_opts().debuginfo {
4451+
let _ = debuginfo::get_arg_metadata(bcx, args[arg_n]);
4452+
}
44444453
arg_n += 1u;
44454454
}
44464455
ret bcx;
@@ -4574,12 +4583,13 @@ fn trans_fn(cx: @local_ctxt, sp: span, f: ast::_fn, llfndecl: ValueRef,
45744583
id: ast::node_id) {
45754584
let do_time = cx.ccx.sess.get_opts().stats;
45764585
let start = do_time ? time::get_time() : {sec: 0u32, usec: 0u32};
4577-
trans_closure(cx, sp, f, llfndecl, ty_self, ty_params, id, {|_fcx|});
4586+
let fcx = option::none;
4587+
trans_closure(cx, sp, f, llfndecl, ty_self, ty_params, id, {|new_fcx| fcx = option::some(new_fcx);});
45784588
if cx.ccx.sess.get_opts().debuginfo {
45794589
let item = alt option::get(cx.ccx.ast_map.find(id)) {
45804590
ast_map::node_item(item) { item }
45814591
};
4582-
debuginfo::get_function_metadata(cx.ccx, item, llfndecl);
4592+
debuginfo::get_function_metadata(option::get(fcx), item, llfndecl);
45834593
}
45844594
if do_time {
45854595
let end = time::get_time();

trunk/src/comp/middle/trans_build.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ fn Invoke(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef],
104104
let instr = llvm::LLVMBuildInvoke(B(cx), Fn, vec::to_ptr(Args),
105105
vec::len(Args), Then, Catch,
106106
noname());
107+
if bcx_ccx(cx).sess.get_opts().debuginfo {
108+
/*llvm::LLVMAddAttribute(option::get(vec::last(llargs)),
109+
lib::llvm::LLVMStructRetAttribute as
110+
lib::llvm::llvm::Attribute);*/
111+
llvm::LLVMAddInstrAttribute(instr, 1u,
112+
lib::llvm::LLVMStructRetAttribute as
113+
lib::llvm::llvm::Attribute);
114+
}
107115
debuginfo::add_line_info(cx, instr);
108116
}
109117
}

0 commit comments

Comments
 (0)