@@ -27,7 +27,7 @@ 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::local_var_metadata (bcx: block, local: &ast::local)`.
30
+ functions like `debuginfo::create_local_var_metadata (bcx: block, local: &ast::local)`.
31
31
32
32
Internally the module will try to reuse already created metadata by utilizing a cache. The way to
33
33
get a shared metadata node when needed is thus to just call the corresponding function in this
@@ -37,9 +37,8 @@ module:
37
37
38
38
The function will take care of probing the cache for an existing node for that exact file path.
39
39
40
- All private state used by the module is stored within a DebugContext struct, which in turn is
41
- contained in the CrateContext.
42
-
40
+ All private state used by the module is stored within either the CrateDebugContext struct (owned by
41
+ the CrateContext) or the FunctionDebugContext (owned by the FunctionContext).
43
42
44
43
This file consists of three conceptual sections:
45
44
1. The public interface of the module
@@ -92,7 +91,7 @@ static DW_ATE_unsigned_char: c_uint = 0x08;
92
91
//=-------------------------------------------------------------------------------------------------
93
92
94
93
/// A context object for maintaining all state needed by the debuginfo module.
95
- pub struct DebugContext {
94
+ pub struct CrateDebugContext {
96
95
priv crate_file : ~str ,
97
96
priv llcontext : ContextRef ,
98
97
priv builder : DIBuilderRef ,
@@ -101,13 +100,13 @@ pub struct DebugContext {
101
100
priv created_types : HashMap < uint , DIType > ,
102
101
}
103
102
104
- impl DebugContext {
105
- pub fn new ( llmod : ModuleRef , crate : ~str ) -> DebugContext {
106
- debug ! ( "DebugContext ::new" ) ;
103
+ impl CrateDebugContext {
104
+ pub fn new ( llmod : ModuleRef , crate : ~str ) -> CrateDebugContext {
105
+ debug ! ( "CrateDebugContext ::new" ) ;
107
106
let builder = unsafe { llvm:: LLVMDIBuilderCreate ( llmod) } ;
108
107
// DIBuilder inherits context from the module, so we'd better use the same one
109
108
let llcontext = unsafe { llvm:: LLVMGetModuleContext ( llmod) } ;
110
- return DebugContext {
109
+ return CrateDebugContext {
111
110
crate_file: crate ,
112
111
llcontext : llcontext,
113
112
builder : builder,
@@ -165,9 +164,9 @@ struct FunctionDebugContextData {
165
164
}
166
165
167
166
enum VariableAccess {
168
- // The value given is a pointer to data
167
+ // The value given is a pointer to the data (T*)
169
168
DirectVariable ,
170
- // The value given has to be dereferenced once to get the pointer to data
169
+ // The value given has to be dereferenced once to get the pointer to data (T**)
171
170
IndirectVariable
172
171
}
173
172
@@ -224,9 +223,9 @@ pub fn create_local_var_metadata(bcx: @mut Block,
224
223
}
225
224
}
226
225
227
- /// Creates debug information for a local variable introduced in the head of a match-statement arm .
226
+ /// Creates debug information for a variable captured in a closure .
228
227
///
229
- // // / Adds the created metadata nodes directly to the crate's IR.
228
+ /// Adds the created metadata nodes directly to the crate's IR.
230
229
pub fn create_captured_var_metadata ( bcx : @mut Block ,
231
230
node_id : ast:: NodeId ,
232
231
llptr : ValueRef ,
@@ -321,7 +320,8 @@ pub fn create_self_argument_metadata(bcx: @mut Block,
321
320
_) => {
322
321
explicit_self. span
323
322
}
324
- _ => bcx. ccx ( ) . sess . bug ( fmt ! ( "create_self_argument_metadata: unexpected sort of node: %?" , fnitem) )
323
+ _ => bcx. ccx ( ) . sess . bug (
324
+ fmt ! ( "create_self_argument_metadata: unexpected sort of node: %?" , fnitem) )
325
325
} ;
326
326
327
327
let scope_metadata = bcx. fcx . debug_context . get_ref ( bcx. ccx ( ) , span) . fn_metadata ;
@@ -361,14 +361,10 @@ pub fn create_argument_metadata(bcx: @mut Block,
361
361
let fcx = bcx. fcx ;
362
362
let cx = fcx. ccx ;
363
363
364
- let pattern = arg. pat ;
365
- let filename = span_start ( cx, pattern. span ) . file . name ;
366
-
367
364
let def_map = cx. tcx . def_map ;
368
- let file_metadata = file_metadata ( cx, filename) ;
369
365
let scope_metadata = bcx. fcx . debug_context . get_ref ( cx, arg. pat . span ) . fn_metadata ;
370
366
371
- do pat_util:: pat_bindings ( def_map, pattern ) |_, node_id, span, path_ref| {
367
+ do pat_util:: pat_bindings ( def_map, arg . pat ) |_, node_id, span, path_ref| {
372
368
373
369
let llptr = match bcx. fcx . llargs . find_copy ( & node_id) {
374
370
Some ( v) => v,
@@ -429,13 +425,24 @@ pub fn set_source_location(fcx: &FunctionContext,
429
425
}
430
426
}
431
427
428
+ /// Enables emitting source locations for the given functions.
429
+ ///
430
+ /// Since we don't want source locations to be emitted for the function prelude, they are disabled
431
+ /// when beginning to translate a new function. This functions switches source location emitting on
432
+ /// and must therefore be called before the first real statement/expression of the function is
433
+ /// translated.
432
434
pub fn start_emitting_source_locations ( fcx : & mut FunctionContext ) {
433
435
match fcx. debug_context {
434
436
FunctionDebugContext ( ~ref mut data) => data. source_locations_enabled = true ,
435
- _ => { /* safe to ignore */ }
437
+ _ => { /* safe to ignore */ }
436
438
}
437
439
}
438
440
441
+ /// Creates the function-specific debug context.
442
+ ///
443
+ /// Returns the FunctionDebugContext for the function which holds state needed for debug info
444
+ /// creation. The function may also return another variant of the FunctionDebugContext enum which
445
+ /// indicates why no debuginfo should be created for the function.
439
446
pub fn create_function_debug_context ( cx : & mut CrateContext ,
440
447
fn_ast_id : ast:: NodeId ,
441
448
param_substs : Option < @param_substs > ,
@@ -1662,7 +1669,7 @@ fn bytes_to_bits(bytes: uint) -> c_ulonglong {
1662
1669
}
1663
1670
1664
1671
#[ inline]
1665
- fn dbg_cx < ' a > ( cx : & ' a mut CrateContext ) -> & ' a mut DebugContext {
1672
+ fn dbg_cx < ' a > ( cx : & ' a mut CrateContext ) -> & ' a mut CrateDebugContext {
1666
1673
cx. dbg_cx . get_mut_ref ( )
1667
1674
}
1668
1675
0 commit comments