@@ -99,7 +99,8 @@ pub struct DebugContext {
99
99
priv created_functions : HashMap < ast:: node_id , DISubprogram > ,
100
100
priv created_blocks : HashMap < ast:: node_id , DILexicalBlock > ,
101
101
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 ,
103
104
}
104
105
105
106
impl DebugContext {
@@ -117,7 +118,8 @@ impl DebugContext {
117
118
created_functions : HashMap :: new ( ) ,
118
119
created_blocks : HashMap :: new ( ) ,
119
120
created_types : HashMap :: new ( ) ,
120
- argument_index_counters : HashMap :: new ( ) ,
121
+ last_function_context_id : -1 , // magic value :(
122
+ argument_counter : 1 ,
121
123
} ;
122
124
}
123
125
}
@@ -196,25 +198,35 @@ pub fn create_local_var_metadata(bcx: @mut Block, local: &ast::Local) {
196
198
/// Creates debug information for the given function argument.
197
199
///
198
200
/// 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 ) {
200
203
let fcx = bcx. fcx ;
201
204
let cx = fcx. ccx ;
202
205
206
+ let pattern = arg. pat ;
207
+ let filename = span_start ( cx, pattern. span ) . file . name ;
208
+
203
209
if fcx. id == -1 ||
204
210
fcx. span . is_none ( ) ||
205
- "<intrinsic>" == span_start ( cx , span ) . file . name {
211
+ "<intrinsic>" == filename {
206
212
return ;
207
213
}
208
214
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) ;
211
219
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
+ }
216
228
217
- let filename = span_start ( cx , span ) . file . name ;
229
+ let def_map = cx . tcx . def_map ;
218
230
let file_metadata = file_metadata ( cx, filename) ;
219
231
let scope = create_function_metadata ( fcx) ;
220
232
@@ -227,6 +239,13 @@ pub fn create_argument_metadata(bcx: @mut Block, arg: &ast::arg, span: span) {
227
239
let name: & str = cx. sess . str_of ( ident) ;
228
240
debug ! ( "create_argument_metadata: %s" , name) ;
229
241
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
+
230
249
let arg_metadata = do name. as_c_str |name| {
231
250
unsafe {
232
251
llvm:: LLVMDIBuilderCreateLocalVariable (
@@ -239,12 +258,10 @@ pub fn create_argument_metadata(bcx: @mut Block, arg: &ast::arg, span: span) {
239
258
type_metadata,
240
259
false ,
241
260
0 ,
242
- argument_index as c_uint )
261
+ argument_index)
243
262
}
244
263
} ;
245
264
246
- argument_index += 1 ;
247
-
248
265
let llptr = match bcx. fcx . llargs . find_copy ( & node_id) {
249
266
Some ( v) => v,
250
267
None => {
@@ -263,8 +280,6 @@ pub fn create_argument_metadata(bcx: @mut Block, arg: &ast::arg, span: span) {
263
280
llvm:: LLVMSetInstDebugLocation ( trans:: build:: B ( bcx) . llbuilder , instr) ;
264
281
}
265
282
}
266
-
267
- dbg_cx( cx) . argument_index_counters . insert ( fcx. id , argument_index) ;
268
283
}
269
284
270
285
/// Sets the current debug location at the beginning of the span
0 commit comments