Skip to content

Commit d546155

Browse files
debuginfo: Fixed a few things for PR.
1 parent af7b87f commit d546155

File tree

5 files changed

+51
-30
lines changed

5 files changed

+51
-30
lines changed

src/librustc/middle/trans/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1790,7 +1790,7 @@ pub fn copy_args_to_allocas(fcx: @mut FunctionContext,
17901790
bcx = _match::store_arg(bcx, args[arg_n].pat, llarg);
17911791

17921792
if fcx.ccx.sess.opts.extra_debuginfo && fcx_has_nonzero_span(fcx) {
1793-
debuginfo::create_argument_metadata(bcx, &args[arg_n], args[arg_n].ty.span);
1793+
debuginfo::create_argument_metadata(bcx, &args[arg_n]);
17941794
}
17951795
}
17961796

src/librustc/middle/trans/debuginfo.rs

+31-16
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ pub struct DebugContext {
9999
priv created_functions: HashMap<ast::node_id, DISubprogram>,
100100
priv created_blocks: HashMap<ast::node_id, DILexicalBlock>,
101101
priv created_types: HashMap<uint, DIType>,
102-
priv argument_index_counters: HashMap<ast::node_id, uint>,
102+
priv last_function_context_id: ast::node_id,
103+
priv argument_counter: uint,
103104
}
104105

105106
impl DebugContext {
@@ -117,7 +118,8 @@ impl DebugContext {
117118
created_functions: HashMap::new(),
118119
created_blocks: HashMap::new(),
119120
created_types: HashMap::new(),
120-
argument_index_counters: HashMap::new(),
121+
last_function_context_id: -1, // magic value :(
122+
argument_counter: 1,
121123
};
122124
}
123125
}
@@ -196,25 +198,35 @@ pub fn create_local_var_metadata(bcx: @mut Block, local: &ast::Local) {
196198
/// Creates debug information for the given function argument.
197199
///
198200
/// Adds the created metadata nodes directly to the crate's IR.
199-
pub fn create_argument_metadata(bcx: @mut Block, arg: &ast::arg, span: span) {
201+
pub fn create_argument_metadata(bcx: @mut Block,
202+
arg: &ast::arg) {
200203
let fcx = bcx.fcx;
201204
let cx = fcx.ccx;
202205

206+
let pattern = arg.pat;
207+
let filename = span_start(cx, pattern.span).file.name;
208+
203209
if fcx.id == -1 ||
204210
fcx.span.is_none() ||
205-
"<intrinsic>" == span_start(cx, span).file.name {
211+
"<intrinsic>" == filename {
206212
return;
207213
}
208214

209-
let def_map = cx.tcx.def_map;
210-
let pattern = arg.pat;
215+
// Limited the scope within which `debug_context` is live,
216+
// otherwise => borrowing errors
217+
{
218+
let debug_context = dbg_cx(cx);
211219

212-
let mut argument_index = match dbg_cx(cx).argument_index_counters.find_copy(&fcx.id) {
213-
Some(value) => value,
214-
None => 0
215-
};
220+
// If this is a new function, reset the counter. llvm::DIBuilder
221+
// wants arguments to be indexed starting from 1.
222+
if fcx.id != debug_context.last_function_context_id {
223+
debug_context.argument_counter = 1;
224+
}
225+
// Keep track of the function we are in
226+
debug_context.last_function_context_id = fcx.id;
227+
}
216228

217-
let filename = span_start(cx, span).file.name;
229+
let def_map = cx.tcx.def_map;
218230
let file_metadata = file_metadata(cx, filename);
219231
let scope = create_function_metadata(fcx);
220232

@@ -227,6 +239,13 @@ pub fn create_argument_metadata(bcx: @mut Block, arg: &ast::arg, span: span) {
227239
let name: &str = cx.sess.str_of(ident);
228240
debug!("create_argument_metadata: %s", name);
229241

242+
let argument_index = {
243+
let debug_context = dbg_cx(cx);
244+
let argument_index = debug_context.argument_counter;
245+
debug_context.argument_counter += 1;
246+
argument_index as c_uint
247+
};
248+
230249
let arg_metadata = do name.as_c_str |name| {
231250
unsafe {
232251
llvm::LLVMDIBuilderCreateLocalVariable(
@@ -239,12 +258,10 @@ pub fn create_argument_metadata(bcx: @mut Block, arg: &ast::arg, span: span) {
239258
type_metadata,
240259
false,
241260
0,
242-
argument_index as c_uint)
261+
argument_index)
243262
}
244263
};
245264

246-
argument_index += 1;
247-
248265
let llptr = match bcx.fcx.llargs.find_copy(&node_id) {
249266
Some(v) => v,
250267
None => {
@@ -263,8 +280,6 @@ pub fn create_argument_metadata(bcx: @mut Block, arg: &ast::arg, span: span) {
263280
llvm::LLVMSetInstDebugLocation(trans::build::B(bcx).llbuilder, instr);
264281
}
265282
}
266-
267-
dbg_cx(cx).argument_index_counters.insert(fcx.id, argument_index);
268283
}
269284

270285
/// Sets the current debug location at the beginning of the span

src/test/debug-info/destructured-fn-argument.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// xfail-win32 Broken because of LLVM bug: http://llvm.org/bugs/show_bug.cgi?id=16249
12+
1113
// compile-flags:-Z extra-debug-info
1214
// debugger:break zzz
1315
// debugger:run
@@ -282,7 +284,7 @@ fn multiple_arguments((oo, pp): (int, int), qq : int) {
282284
}
283285

284286
fn main() {
285-
simple_tuple((1, false));
287+
simple_tuple((1, false));
286288
nested_tuple((2, (3, 4)));
287289
destructure_only_first_level((5, (6, 7)));
288290
struct_as_tuple_element((8, Struct { a: 9, b: 10 }, 11));
@@ -291,8 +293,8 @@ fn main() {
291293
ignored_struct_field(Struct { a: 17, b: 18 });
292294
one_struct_destructured_one_not((Struct { a: 19, b: 20 }, Struct { a: 21, b: 22 }));
293295
different_order_of_struct_fields(Struct { a: 23, b: 24 });
294-
complex_nesting(((25, 26), ((27, (28, Struct { a: 29, b: 30})), Struct { a: 31, b: 32 }), 33));
295-
managed_box(@(34, 35));
296+
complex_nesting(((25, 26), ((27, (28, Struct { a: 29, b: 30})), Struct { a: 31, b: 32 }), 33));
297+
managed_box(@(34, 35));
296298
borrowed_pointer(&(36, 37));
297299
contained_borrowed_pointer((&38, 39));
298300
unique_pointer(~(40, 41, 42));

src/test/debug-info/destructured-local.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// xfail-win32 Broken because of LLVM bug: http://llvm.org/bugs/show_bug.cgi?id=16249
12+
1113
// compile-flags:-Z extra-debug-info
1214
// debugger:break zzz
1315
// debugger:run
@@ -125,8 +127,8 @@
125127

126128

127129
struct Struct {
128-
a: i64,
129-
b: i32
130+
a: i64,
131+
b: i32
130132
}
131133

132134
enum Univariant {
@@ -137,7 +139,7 @@ struct TupleStruct (float, int);
137139

138140

139141
fn main() {
140-
// simple tuple
142+
// simple tuple
141143
let (a, b) : (int, bool) = (1, false);
142144

143145
// nested tuple
@@ -162,14 +164,14 @@ fn main() {
162164
let (Struct { a: p, b: q }, r) = (Struct { a: 19, b: 20 }, Struct { a: 21, b: 22 });
163165

164166
// different order of struct fields
165-
let Struct { b: s, a: t } = Struct { a: 23, b: 24 };
167+
let Struct { b: s, a: t } = Struct { a: 23, b: 24 };
166168

167-
// complex nesting
168-
let ((u, v), ((w, (x, Struct { a: y, b: z})), Struct { a: ae, b: oe }), ue) =
169-
((25, 26), ((27, (28, Struct { a: 29, b: 30})), Struct { a: 31, b: 32 }), 33);
169+
// complex nesting
170+
let ((u, v), ((w, (x, Struct { a: y, b: z})), Struct { a: ae, b: oe }), ue) =
171+
((25, 26), ((27, (28, Struct { a: 29, b: 30})), Struct { a: 31, b: 32 }), 33);
170172

171-
// managed box
172-
let @aa = @(34, 35);
173+
// managed box
174+
let @aa = @(34, 35);
173175

174176
// borrowed pointer
175177
let &bb = &(36, 37);
@@ -192,7 +194,7 @@ fn main() {
192194
// univariant enum
193195
let Unit(ii) = Unit(51);
194196

195-
// univariant enum with ref binding
197+
// univariant enum with ref binding
196198
let Unit(ref jj) = Unit(52);
197199

198200
// tuple struct

src/test/debug-info/function-arguments.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// xfail-win32 Broken because of LLVM bug: http://llvm.org/bugs/show_bug.cgi?id=16249
12+
1113
// compile-flags:-Z extra-debug-info
1214
// debugger:break zzz
1315
// debugger:run

0 commit comments

Comments
 (0)