@@ -27,7 +27,7 @@ where possible. This will hopefully ease the adaption of this module to future L
2727
2828The public API of the module is a set of functions that will insert the correct metadata into the
2929LLVM 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)`.
3131
3232Internally the module will try to reuse already created metadata by utilizing a cache. The way to
3333get a shared metadata node when needed is thus to just call the corresponding function in this
@@ -37,9 +37,8 @@ module:
3737
3838The function will take care of probing the cache for an existing node for that exact file path.
3939
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).
4342
4443This file consists of three conceptual sections:
45441. The public interface of the module
@@ -92,7 +91,7 @@ static DW_ATE_unsigned_char: c_uint = 0x08;
9291//=-------------------------------------------------------------------------------------------------
9392
9493/// A context object for maintaining all state needed by the debuginfo module.
95- pub struct DebugContext {
94+ pub struct CrateDebugContext {
9695 priv crate_file : ~str ,
9796 priv llcontext : ContextRef ,
9897 priv builder : DIBuilderRef ,
@@ -101,13 +100,13 @@ pub struct DebugContext {
101100 priv created_types : HashMap < uint , DIType > ,
102101}
103102
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" ) ;
107106 let builder = unsafe { llvm:: LLVMDIBuilderCreate ( llmod) } ;
108107 // DIBuilder inherits context from the module, so we'd better use the same one
109108 let llcontext = unsafe { llvm:: LLVMGetModuleContext ( llmod) } ;
110- return DebugContext {
109+ return CrateDebugContext {
111110 crate_file: crate ,
112111 llcontext : llcontext,
113112 builder : builder,
@@ -165,9 +164,9 @@ struct FunctionDebugContextData {
165164}
166165
167166enum VariableAccess {
168- // The value given is a pointer to data
167+ // The value given is a pointer to the data (T*)
169168 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**)
171170 IndirectVariable
172171}
173172
@@ -224,9 +223,9 @@ pub fn create_local_var_metadata(bcx: @mut Block,
224223 }
225224}
226225
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 .
228227///
229- // // / Adds the created metadata nodes directly to the crate's IR.
228+ /// Adds the created metadata nodes directly to the crate's IR.
230229pub fn create_captured_var_metadata ( bcx : @mut Block ,
231230 node_id : ast:: NodeId ,
232231 llptr : ValueRef ,
@@ -321,7 +320,8 @@ pub fn create_self_argument_metadata(bcx: @mut Block,
321320 _) => {
322321 explicit_self. span
323322 }
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) )
325325 } ;
326326
327327 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,
361361 let fcx = bcx. fcx ;
362362 let cx = fcx. ccx ;
363363
364- let pattern = arg. pat ;
365- let filename = span_start ( cx, pattern. span ) . file . name ;
366-
367364 let def_map = cx. tcx . def_map ;
368- let file_metadata = file_metadata ( cx, filename) ;
369365 let scope_metadata = bcx. fcx . debug_context . get_ref ( cx, arg. pat . span ) . fn_metadata ;
370366
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| {
372368
373369 let llptr = match bcx. fcx . llargs . find_copy ( & node_id) {
374370 Some ( v) => v,
@@ -429,13 +425,24 @@ pub fn set_source_location(fcx: &FunctionContext,
429425 }
430426}
431427
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.
432434pub fn start_emitting_source_locations ( fcx : & mut FunctionContext ) {
433435 match fcx. debug_context {
434436 FunctionDebugContext ( ~ref mut data) => data. source_locations_enabled = true ,
435- _ => { /* safe to ignore */ }
437+ _ => { /* safe to ignore */ }
436438 }
437439}
438440
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.
439446pub fn create_function_debug_context ( cx : & mut CrateContext ,
440447 fn_ast_id : ast:: NodeId ,
441448 param_substs : Option < @param_substs > ,
@@ -1663,7 +1670,7 @@ fn bytes_to_bits(bytes: uint) -> c_ulonglong {
16631670}
16641671
16651672#[ inline]
1666- fn dbg_cx < ' a > ( cx : & ' a mut CrateContext ) -> & ' a mut DebugContext {
1673+ fn dbg_cx < ' a > ( cx : & ' a mut CrateContext ) -> & ' a mut CrateDebugContext {
16671674 cx. dbg_cx . get_mut_ref ( )
16681675}
16691676
0 commit comments