@@ -27,11 +27,18 @@ where possible. This will hopefully ease the adaption of this module to future L
27
27
28
28
The public API of the module is a set of functions that will insert the correct metadata into the
29
29
LLVM IR when called with the right parameters. The module is thus driven from an outside client with
30
- functions like `debuginfo::create_local_var_metadata (bcx: block, local: @ ast::local)`.
30
+ functions like `debuginfo::local_var_metadata (bcx: block, local: & ast::local)`.
31
31
32
- Internally the module will try to reuse already created metadata by utilizing a cache. All private
33
- state used by the module is stored within a DebugContext struct, which in turn is contained in the
34
- CrateContext.
32
+ Internally the module will try to reuse already created metadata by utilizing a cache. The way to
33
+ get a shared metadata node when needed is thus to just call the corresponding function in this
34
+ module:
35
+
36
+ let file_metadata = file_metadata(crate_context, path);
37
+
38
+ The function will take care of probing the cache for an existing node for that exact file path.
39
+
40
+ All private state used by the module is stored within a DebugContext struct, which in turn is
41
+ contained in the CrateContext.
35
42
36
43
37
44
This file consists of three conceptual sections:
@@ -149,7 +156,7 @@ pub fn create_local_var_metadata(bcx: block, local: @ast::local) -> DIVariable {
149
156
150
157
let context = match bcx. parent {
151
158
None => create_function_metadata ( bcx. fcx ) ,
152
- Some ( _) => block_metadata ( bcx)
159
+ Some ( _) => lexical_block_metadata ( bcx)
153
160
} ;
154
161
155
162
let var_metadata = do as_c_str ( name) |name| {
@@ -178,7 +185,7 @@ pub fn create_local_var_metadata(bcx: block, local: @ast::local) -> DIVariable {
178
185
}
179
186
} ;
180
187
181
- set_debug_location ( cx, block_metadata ( bcx) , loc. line , loc. col . to_uint ( ) ) ;
188
+ set_debug_location ( cx, lexical_block_metadata ( bcx) , loc. line , loc. col . to_uint ( ) ) ;
182
189
unsafe {
183
190
let instr = llvm:: LLVMDIBuilderInsertDeclareAtEnd ( DIB ( cx) , llptr, var_metadata, bcx. llbb ) ;
184
191
llvm:: LLVMSetInstDebugLocation ( trans:: build:: B ( bcx) , instr) ;
@@ -236,7 +243,7 @@ pub fn create_argument_metadata(bcx: block, arg: &ast::arg, span: span) -> Optio
236
243
} ;
237
244
238
245
let llptr = fcx. llargs . get_copy ( & arg. id ) ;
239
- set_debug_location ( cx, block_metadata ( bcx) , loc. line , loc. col . to_uint ( ) ) ;
246
+ set_debug_location ( cx, lexical_block_metadata ( bcx) , loc. line , loc. col . to_uint ( ) ) ;
240
247
unsafe {
241
248
let instr = llvm:: LLVMDIBuilderInsertDeclareAtEnd (
242
249
DIB ( cx) , llptr, var_metadata, bcx. llbb ) ;
@@ -259,7 +266,7 @@ pub fn update_source_pos(bcx: block, span: span) {
259
266
}
260
267
debug ! ( "update_source_pos: %s" , bcx. sess( ) . codemap. span_to_str( span) ) ;
261
268
let loc = span_start ( bcx. ccx ( ) , span) ;
262
- set_debug_location ( bcx. ccx ( ) , block_metadata ( bcx) , loc. line , loc. col . to_uint ( ) )
269
+ set_debug_location ( bcx. ccx ( ) , lexical_block_metadata ( bcx) , loc. line , loc. col . to_uint ( ) )
263
270
}
264
271
265
272
/// Creates debug information for the given function.
@@ -418,44 +425,50 @@ fn file_metadata(cx: &mut CrateContext, full_path: &str) -> DIFile {
418
425
return file_metadata;
419
426
}
420
427
421
- fn block_metadata ( bcx : block ) -> DILexicalBlock {
422
- let mut bcx = bcx ;
428
+ /// Get or create the lexical block metadata node for the given LLVM basic block.
429
+ fn lexical_block_metadata ( bcx : block ) -> DILexicalBlock {
423
430
let cx = bcx. ccx ( ) ;
431
+ let mut bcx = bcx;
424
432
433
+ // Search up the tree of basic blocks until we find one that knows the containing lexical block.
425
434
while bcx. node_info . is_none ( ) {
426
435
match bcx. parent {
427
- Some ( b) => bcx = b,
428
- None => fail ! ( )
436
+ Some ( b) => bcx = b,
437
+ None => cx . sess . bug ( "debuginfo: Could not find lexical block for LLVM basic block." )
429
438
}
430
439
}
440
+
431
441
let span = bcx. node_info . get ( ) . span ;
432
442
let id = bcx. node_info . get ( ) . id ;
433
443
444
+ // Check whether we already have a cache entry for this node id
434
445
match dbg_cx ( cx) . created_blocks . find ( & id) {
435
446
Some ( block) => return * block,
436
447
None => ( )
437
448
}
438
449
439
- debug ! ( "block_metadata : %s" , bcx. sess( ) . codemap. span_to_str( span) ) ;
450
+ debug ! ( "lexical_block_metadata : %s" , bcx. sess( ) . codemap. span_to_str( span) ) ;
440
451
441
452
let parent = match bcx. parent {
442
453
None => create_function_metadata ( bcx. fcx ) ,
443
- Some ( b) => block_metadata ( b)
454
+ Some ( b) => lexical_block_metadata ( b)
444
455
} ;
445
- let cx = bcx . ccx ( ) ;
456
+
446
457
let loc = span_start ( cx, span) ;
447
458
let file_metadata = file_metadata ( cx, loc. file . name ) ;
448
459
449
- let block_metadata = unsafe {
460
+ let lexical_block_metadata = unsafe {
450
461
llvm:: LLVMDIBuilderCreateLexicalBlock (
451
462
DIB ( cx) ,
452
- parent, file_metadata,
453
- loc. line as c_uint , loc. col . to_uint ( ) as c_uint )
463
+ parent,
464
+ file_metadata,
465
+ loc. line as c_uint ,
466
+ loc. col . to_uint ( ) as c_uint )
454
467
} ;
455
468
456
- dbg_cx ( cx) . created_blocks . insert ( id, block_metadata ) ;
469
+ dbg_cx ( cx) . created_blocks . insert ( id, lexical_block_metadata ) ;
457
470
458
- return block_metadata ;
471
+ return lexical_block_metadata ;
459
472
}
460
473
461
474
fn basic_type_metadata ( cx : & mut CrateContext , t : ty:: t ) -> DIType {
0 commit comments