@@ -280,6 +280,66 @@ pub fn finalize(cx: &CrateContext) {
280280 } ;
281281}
282282
283+ /// Creates debug information for the given global variable.
284+ ///
285+ /// Adds the created metadata nodes directly to the crate's IR.
286+ pub fn create_global_var_metadata ( cx : & CrateContext ,
287+ node_id : ast:: NodeId ,
288+ global : ValueRef ) {
289+ if cx. dbg_cx . is_none ( ) {
290+ return ;
291+ }
292+
293+ let var_item = cx. tcx . map . get ( node_id) ;
294+
295+ let ( ident, span) = match var_item {
296+ ast_map:: NodeItem ( item) => {
297+ match item. node {
298+ ast:: ItemStatic ( ..) => ( item. ident , item. span ) ,
299+ _ => cx. sess ( ) . span_bug ( item. span ,
300+ format ! ( "debuginfo::create_global_var_metadata() -
301+ Captured var-id refers to unexpected ast_item
302+ variant: {:?}" ,
303+ var_item) )
304+ }
305+ } ,
306+ _ => cx. sess ( ) . bug ( format ! ( "debuginfo::create_global_var_metadata() - Captured var-id \
307+ refers to unexpected ast_map variant: {:?}",
308+ var_item) )
309+ } ;
310+
311+ let filename = span_start ( cx, span) . file . name . clone ( ) ;
312+ let file_metadata = file_metadata ( cx, filename) ;
313+
314+ let is_local_to_unit = is_node_local_to_unit ( cx, node_id) ;
315+ let loc = span_start ( cx, span) ;
316+
317+ let variable_type = ty:: node_id_to_type ( cx. tcx ( ) , node_id) ;
318+ let type_metadata = type_metadata ( cx, variable_type, span) ;
319+
320+ let namespace_node = namespace_for_item ( cx, ast_util:: local_def ( node_id) ) ;
321+ let var_name = token:: get_ident ( ident) . get ( ) . to_str ( ) ;
322+ let linkage_name = namespace_node. mangled_name_of_contained_item ( var_name) ;
323+ let var_scope = namespace_node. scope ;
324+
325+ var_name. with_c_str ( |var_name| {
326+ linkage_name. with_c_str ( |linkage_name| {
327+ unsafe {
328+ llvm:: LLVMDIBuilderCreateStaticVariable ( DIB ( cx) ,
329+ var_scope,
330+ var_name,
331+ linkage_name,
332+ file_metadata,
333+ loc. line as c_uint ,
334+ type_metadata,
335+ is_local_to_unit,
336+ global,
337+ ptr:: null ( ) ) ;
338+ }
339+ } )
340+ } ) ;
341+ }
342+
283343/// Creates debug information for the given local variable.
284344///
285345/// Adds the created metadata nodes directly to the crate's IR.
@@ -640,13 +700,7 @@ pub fn create_function_debug_context(cx: &CrateContext,
640700 // Clang sets this parameter to the opening brace of the function's block, so let's do this too.
641701 let scope_line = span_start ( cx, top_level_block. span ) . line ;
642702
643- // The is_local_to_unit flag indicates whether a function is local to the current compilation
644- // unit (i.e. if it is *static* in the C-sense). The *reachable* set should provide a good
645- // approximation of this, as it contains everything that might leak out of the current crate
646- // (by being externally visible or by being inlined into something externally visible). It might
647- // better to use the `exported_items` set from `driver::CrateAnalysis` in the future, but (atm)
648- // this set is not available in the translation pass.
649- let is_local_to_unit = !cx. reachable . contains ( & fn_ast_id) ;
703+ let is_local_to_unit = is_node_local_to_unit ( cx, fn_ast_id) ;
650704
651705 let fn_metadata = function_name. with_c_str ( |function_name| {
652706 linkage_name. with_c_str ( |linkage_name| {
@@ -854,6 +908,17 @@ pub fn create_function_debug_context(cx: &CrateContext,
854908// Module-Internal debug info creation functions
855909//=-------------------------------------------------------------------------------------------------
856910
911+ fn is_node_local_to_unit ( cx : & CrateContext , node_id : ast:: NodeId ) -> bool
912+ {
913+ // The is_local_to_unit flag indicates whether a function is local to the current compilation
914+ // unit (i.e. if it is *static* in the C-sense). The *reachable* set should provide a good
915+ // approximation of this, as it contains everything that might leak out of the current crate
916+ // (by being externally visible or by being inlined into something externally visible). It might
917+ // better to use the `exported_items` set from `driver::CrateAnalysis` in the future, but (atm)
918+ // this set is not available in the translation pass.
919+ !cx. reachable . contains ( & node_id)
920+ }
921+
857922fn create_DIArray ( builder : DIBuilderRef , arr : & [ DIDescriptor ] ) -> DIArray {
858923 return unsafe {
859924 llvm:: LLVMDIBuilderGetOrCreateArray ( builder, arr. as_ptr ( ) , arr. len ( ) as u32 )
0 commit comments