Skip to content

Commit 56d162d

Browse files
committed
---
yaml --- r: 12873 b: refs/heads/master c: f1a4691 h: refs/heads/master i: 12871: 0cc2636 v: v3
1 parent a6239d3 commit 56d162d

File tree

7 files changed

+70
-7
lines changed

7 files changed

+70
-7
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: c568cf6099b94d50ff7ca28e60d376ebe2cc9255
2+
refs/heads/master: f1a46914c4241c05a5b44f6f8dad4630a150e292
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/rt/rust_upcall.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,28 @@ upcall_fail(char const *expr,
129129
UPCALL_SWITCH_STACK(&args, upcall_s_fail);
130130
}
131131

132+
struct s_trace_args {
133+
char const *msg;
134+
char const *file;
135+
size_t line;
136+
};
137+
138+
extern "C" CDECL void
139+
upcall_s_trace(s_trace_args *args) {
140+
rust_task *task = rust_get_current_task();
141+
LOG_UPCALL_ENTRY(task);
142+
LOG(task, trace, "Trace %s:%d: %s",
143+
args->file, args->line, args->msg);
144+
}
145+
146+
extern "C" CDECL void
147+
upcall_trace(char const *msg,
148+
char const *file,
149+
size_t line) {
150+
s_trace_args args = {msg,file,line};
151+
UPCALL_SWITCH_STACK(&args, upcall_s_trace);
152+
}
153+
132154
/**********************************************************************
133155
* Allocate an object in the task-local heap.
134156
*/

trunk/src/rt/rustrt.def.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ vec_from_buf_shared
6565
unsupervise
6666
upcall_cmp_type
6767
upcall_fail
68+
upcall_trace
6869
upcall_free
6970
upcall_validate_box
7071
upcall_log_type

trunk/src/rustc/back/upcall.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import lib::llvm::{type_names, ModuleRef, ValueRef, TypeRef};
99

1010
type upcalls =
1111
{_fail: ValueRef,
12+
trace: ValueRef,
1213
malloc: ValueRef,
1314
free: ValueRef,
1415
validate_box: ValueRef,
@@ -53,6 +54,9 @@ fn declare_upcalls(targ_cfg: @session::config,
5354
ret @{_fail: dv("fail", [T_ptr(T_i8()),
5455
T_ptr(T_i8()),
5556
size_t]),
57+
trace: dv("trace", [T_ptr(T_i8()),
58+
T_ptr(T_i8()),
59+
int_t]),
5660
malloc:
5761
nothrow(d("malloc", [T_ptr(tydesc_type)],
5862
T_ptr(T_i8()))),

trunk/src/rustc/driver/session.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const time_llvm_passes: uint = 8u;
3030
const stats: uint = 16u;
3131
const no_asm_comments: uint = 32u;
3232
const no_verify: uint = 64u;
33+
const trace: uint = 128u;
3334

3435
fn debugging_opts_map() -> [(str, str, uint)] {
3536
[("ppregions", "prettyprint regions with \
@@ -40,7 +41,8 @@ fn debugging_opts_map() -> [(str, str, uint)] {
4041
("time-llvm-passes", "measure time of each LLVM pass", time_llvm_passes),
4142
("stats", "gather trans statistics", stats),
4243
("no-asm-comments", "omit comments when using -S", no_asm_comments),
43-
("no-verify", "skip LLVM verification", no_verify)]
44+
("no-verify", "skip LLVM verification", no_verify),
45+
("trace", "emit trace logs", trace)]
4446
}
4547

4648
type options =
@@ -141,6 +143,7 @@ impl session for session {
141143
fn stats() -> bool { self.debugging_opt(stats) }
142144
fn no_asm_comments() -> bool { self.debugging_opt(no_asm_comments) }
143145
fn no_verify() -> bool { self.debugging_opt(no_verify) }
146+
fn trace() -> bool { self.debugging_opt(trace) }
144147
}
145148

146149
#[doc = "Some reasonable defaults"]

trunk/src/rustc/middle/trans/base.rs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,10 +1683,12 @@ fn trans_assign_op(bcx: block, ex: @ast::expr, op: ast::binop,
16831683

16841684
fn root_value(bcx: block, val: ValueRef, ty: ty::t,
16851685
scope_id: ast::node_id) {
1686-
if !bcx.sess().no_asm_comments() {
1687-
add_comment(bcx, #fmt["preserving until end of scope %d",
1688-
scope_id]);
1686+
if bcx.sess().trace() {
1687+
trans_trace(
1688+
bcx, none,
1689+
#fmt["preserving until end of scope %d", scope_id]);
16891690
}
1691+
16901692
let root_loc = alloca(bcx, type_of(bcx.ccx(), ty));
16911693
copy_val(bcx, INIT, root_loc, val, ty);
16921694
add_root_cleanup(bcx, scope_id, root_loc, ty);
@@ -3725,6 +3727,30 @@ fn trans_fail_expr(bcx: block, sp_opt: option<span>,
37253727
}
37263728
}
37273729

3730+
fn trans_trace(bcx: block, sp_opt: option<span>, trace_str: str) {
3731+
if !bcx.sess().trace() { ret; }
3732+
let _icx = bcx.insn_ctxt("trans_trace");
3733+
add_comment(bcx, trace_str);
3734+
let V_trace_str = C_cstr(bcx.ccx(), trace_str);
3735+
let {V_filename, V_line} = alt sp_opt {
3736+
some(sp) {
3737+
let sess = bcx.sess();
3738+
let loc = codemap::lookup_char_pos(sess.parse_sess.cm, sp.lo);
3739+
{V_filename: C_cstr(bcx.ccx(), loc.file.name),
3740+
V_line: loc.line as int}
3741+
}
3742+
none {
3743+
{V_filename: C_cstr(bcx.ccx(), "<runtime>"),
3744+
V_line: 0}
3745+
}
3746+
};
3747+
let ccx = bcx.ccx();
3748+
let V_trace_str = PointerCast(bcx, V_trace_str, T_ptr(T_i8()));
3749+
let V_filename = PointerCast(bcx, V_filename, T_ptr(T_i8()));
3750+
let args = [V_trace_str, V_filename, C_int(ccx, V_line)];
3751+
Call(bcx, ccx.upcalls.trace, args);
3752+
}
3753+
37283754
fn trans_fail(bcx: block, sp_opt: option<span>, fail_str: str) ->
37293755
block {
37303756
let _icx = bcx.insn_ctxt("trans_fail");
@@ -4040,8 +4066,10 @@ fn cleanup_and_leave(bcx: block, upto: option<BasicBlockRef>,
40404066
loop {
40414067
#debug["cleanup_and_leave: leaving %s", cur.to_str()];
40424068

4043-
if !bcx.sess().no_asm_comments() {
4044-
add_comment(bcx, #fmt["cleanup_and_leave(%s)", cur.to_str()]);
4069+
if bcx.sess().trace() {
4070+
trans_trace(
4071+
bcx, none,
4072+
#fmt["cleanup_and_leave(%s)", cur.to_str()]);
40454073
}
40464074

40474075
alt cur.kind {

trunk/src/rustc/middle/trans/build.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,11 @@ fn Call(cx: block, Fn: ValueRef, Args: [ValueRef]) -> ValueRef {
669669
if cx.unreachable { ret _UndefReturn(cx, Fn); }
670670
unsafe {
671671
count_insn(cx, "call");
672+
673+
#debug["Call(Fn=%s, Args=%?)",
674+
val_str(cx.ccx().tn, Fn),
675+
Args.map { |arg| val_str(cx.ccx().tn, arg) }];
676+
672677
ret llvm::LLVMBuildCall(B(cx), Fn, vec::unsafe::to_ptr(Args),
673678
Args.len() as c_uint, noname());
674679
}

0 commit comments

Comments
 (0)