diff options
| author | Michael Woerister <michaelwoerister@gmail> | 2013-07-25 19:46:57 +0200 |
|---|---|---|
| committer | Michael Woerister <michaelwoerister@gmail> | 2013-07-25 23:05:56 +0200 |
| commit | d54615528c9d90523865a5bc518b21bb20909ce2 (patch) | |
| tree | 90b34a6733929aa3473859c62a8049a45ea7d78d | |
| parent | af7b87f69d9c4633d7e0c7dd77f34c23bbd433d8 (diff) | |
| download | rust-d54615528c9d90523865a5bc518b21bb20909ce2.tar.gz rust-d54615528c9d90523865a5bc518b21bb20909ce2.zip | |
debuginfo: Fixed a few things for PR.
| -rw-r--r-- | src/librustc/middle/trans/base.rs | 2 | ||||
| -rw-r--r-- | src/librustc/middle/trans/debuginfo.rs | 47 | ||||
| -rw-r--r-- | src/test/debug-info/destructured-fn-argument.rs | 8 | ||||
| -rw-r--r-- | src/test/debug-info/destructured-local.rs | 22 | ||||
| -rw-r--r-- | src/test/debug-info/function-arguments.rs | 2 |
5 files changed, 51 insertions, 30 deletions
diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 437d1a50d18..8a2766b47e1 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -1790,7 +1790,7 @@ pub fn copy_args_to_allocas(fcx: @mut FunctionContext, bcx = _match::store_arg(bcx, args[arg_n].pat, llarg); if fcx.ccx.sess.opts.extra_debuginfo && fcx_has_nonzero_span(fcx) { - debuginfo::create_argument_metadata(bcx, &args[arg_n], args[arg_n].ty.span); + debuginfo::create_argument_metadata(bcx, &args[arg_n]); } } diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index 50acb080978..7333850bf96 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -99,7 +99,8 @@ pub struct DebugContext { priv created_functions: HashMap<ast::node_id, DISubprogram>, priv created_blocks: HashMap<ast::node_id, DILexicalBlock>, priv created_types: HashMap<uint, DIType>, - priv argument_index_counters: HashMap<ast::node_id, uint>, + priv last_function_context_id: ast::node_id, + priv argument_counter: uint, } impl DebugContext { @@ -117,7 +118,8 @@ impl DebugContext { created_functions: HashMap::new(), created_blocks: HashMap::new(), created_types: HashMap::new(), - argument_index_counters: HashMap::new(), + last_function_context_id: -1, // magic value :( + argument_counter: 1, }; } } @@ -196,25 +198,35 @@ pub fn create_local_var_metadata(bcx: @mut Block, local: &ast::Local) { /// Creates debug information for the given function argument. /// /// Adds the created metadata nodes directly to the crate's IR. -pub fn create_argument_metadata(bcx: @mut Block, arg: &ast::arg, span: span) { +pub fn create_argument_metadata(bcx: @mut Block, + arg: &ast::arg) { let fcx = bcx.fcx; let cx = fcx.ccx; + let pattern = arg.pat; + let filename = span_start(cx, pattern.span).file.name; + if fcx.id == -1 || fcx.span.is_none() || - "<intrinsic>" == span_start(cx, span).file.name { + "<intrinsic>" == filename { return; } - let def_map = cx.tcx.def_map; - let pattern = arg.pat; + // Limited the scope within which `debug_context` is live, + // otherwise => borrowing errors + { + let debug_context = dbg_cx(cx); - let mut argument_index = match dbg_cx(cx).argument_index_counters.find_copy(&fcx.id) { - Some(value) => value, - None => 0 - }; + // If this is a new function, reset the counter. llvm::DIBuilder + // wants arguments to be indexed starting from 1. + if fcx.id != debug_context.last_function_context_id { + debug_context.argument_counter = 1; + } + // Keep track of the function we are in + debug_context.last_function_context_id = fcx.id; + } - let filename = span_start(cx, span).file.name; + let def_map = cx.tcx.def_map; let file_metadata = file_metadata(cx, filename); let scope = create_function_metadata(fcx); @@ -227,6 +239,13 @@ pub fn create_argument_metadata(bcx: @mut Block, arg: &ast::arg, span: span) { let name: &str = cx.sess.str_of(ident); debug!("create_argument_metadata: %s", name); + let argument_index = { + let debug_context = dbg_cx(cx); + let argument_index = debug_context.argument_counter; + debug_context.argument_counter += 1; + argument_index as c_uint + }; + let arg_metadata = do name.as_c_str |name| { unsafe { llvm::LLVMDIBuilderCreateLocalVariable( @@ -239,12 +258,10 @@ pub fn create_argument_metadata(bcx: @mut Block, arg: &ast::arg, span: span) { type_metadata, false, 0, - argument_index as c_uint) + argument_index) } }; - argument_index += 1; - let llptr = match bcx.fcx.llargs.find_copy(&node_id) { Some(v) => v, None => { @@ -263,8 +280,6 @@ pub fn create_argument_metadata(bcx: @mut Block, arg: &ast::arg, span: span) { llvm::LLVMSetInstDebugLocation(trans::build::B(bcx).llbuilder, instr); } } - - dbg_cx(cx).argument_index_counters.insert(fcx.id, argument_index); } /// Sets the current debug location at the beginning of the span diff --git a/src/test/debug-info/destructured-fn-argument.rs b/src/test/debug-info/destructured-fn-argument.rs index fe0d9a486bc..05718ab4890 100644 --- a/src/test/debug-info/destructured-fn-argument.rs +++ b/src/test/debug-info/destructured-fn-argument.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// xfail-win32 Broken because of LLVM bug: http://llvm.org/bugs/show_bug.cgi?id=16249 + // compile-flags:-Z extra-debug-info // debugger:break zzz // debugger:run @@ -282,7 +284,7 @@ fn multiple_arguments((oo, pp): (int, int), qq : int) { } fn main() { - simple_tuple((1, false)); + simple_tuple((1, false)); nested_tuple((2, (3, 4))); destructure_only_first_level((5, (6, 7))); struct_as_tuple_element((8, Struct { a: 9, b: 10 }, 11)); @@ -291,8 +293,8 @@ fn main() { ignored_struct_field(Struct { a: 17, b: 18 }); one_struct_destructured_one_not((Struct { a: 19, b: 20 }, Struct { a: 21, b: 22 })); different_order_of_struct_fields(Struct { a: 23, b: 24 }); - complex_nesting(((25, 26), ((27, (28, Struct { a: 29, b: 30})), Struct { a: 31, b: 32 }), 33)); - managed_box(@(34, 35)); + complex_nesting(((25, 26), ((27, (28, Struct { a: 29, b: 30})), Struct { a: 31, b: 32 }), 33)); + managed_box(@(34, 35)); borrowed_pointer(&(36, 37)); contained_borrowed_pointer((&38, 39)); unique_pointer(~(40, 41, 42)); diff --git a/src/test/debug-info/destructured-local.rs b/src/test/debug-info/destructured-local.rs index 6d85b99a79d..f8db7981c94 100644 --- a/src/test/debug-info/destructured-local.rs +++ b/src/test/debug-info/destructured-local.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// xfail-win32 Broken because of LLVM bug: http://llvm.org/bugs/show_bug.cgi?id=16249 + // compile-flags:-Z extra-debug-info // debugger:break zzz // debugger:run @@ -125,8 +127,8 @@ struct Struct { - a: i64, - b: i32 + a: i64, + b: i32 } enum Univariant { @@ -137,7 +139,7 @@ struct TupleStruct (float, int); fn main() { - // simple tuple + // simple tuple let (a, b) : (int, bool) = (1, false); // nested tuple @@ -162,14 +164,14 @@ fn main() { let (Struct { a: p, b: q }, r) = (Struct { a: 19, b: 20 }, Struct { a: 21, b: 22 }); // different order of struct fields - let Struct { b: s, a: t } = Struct { a: 23, b: 24 }; + let Struct { b: s, a: t } = Struct { a: 23, b: 24 }; - // complex nesting - let ((u, v), ((w, (x, Struct { a: y, b: z})), Struct { a: ae, b: oe }), ue) = - ((25, 26), ((27, (28, Struct { a: 29, b: 30})), Struct { a: 31, b: 32 }), 33); + // complex nesting + let ((u, v), ((w, (x, Struct { a: y, b: z})), Struct { a: ae, b: oe }), ue) = + ((25, 26), ((27, (28, Struct { a: 29, b: 30})), Struct { a: 31, b: 32 }), 33); - // managed box - let @aa = @(34, 35); + // managed box + let @aa = @(34, 35); // borrowed pointer let &bb = &(36, 37); @@ -192,7 +194,7 @@ fn main() { // univariant enum let Unit(ii) = Unit(51); - // univariant enum with ref binding + // univariant enum with ref binding let Unit(ref jj) = Unit(52); // tuple struct diff --git a/src/test/debug-info/function-arguments.rs b/src/test/debug-info/function-arguments.rs index 5a410ef6462..1fe79b8e2a9 100644 --- a/src/test/debug-info/function-arguments.rs +++ b/src/test/debug-info/function-arguments.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// xfail-win32 Broken because of LLVM bug: http://llvm.org/bugs/show_bug.cgi?id=16249 + // compile-flags:-Z extra-debug-info // debugger:break zzz // debugger:run |
