@@ -550,7 +550,7 @@ pub fn create_function_debug_context(cx: &mut CrateContext,
550
550
ast_map:: node_item( ref item, _) => {
551
551
match item. node {
552
552
ast:: item_fn( ref fn_decl, _, _, ref generics, ref top_level_block) => {
553
- ( item. ident , fn_decl, generics, Some ( top_level_block) , item. span )
553
+ ( item. ident , fn_decl, generics, top_level_block, item. span )
554
554
}
555
555
_ => {
556
556
cx. sess . span_bug ( item. span ,
@@ -569,7 +569,7 @@ pub fn create_function_debug_context(cx: &mut CrateContext,
569
569
} ,
570
570
_,
571
571
_) => {
572
- ( ident, fn_decl, generics, Some ( top_level_block) , span)
572
+ ( ident, fn_decl, generics, top_level_block, span)
573
573
}
574
574
ast_map:: node_expr( ref expr) => {
575
575
match expr. node {
@@ -580,7 +580,7 @@ pub fn create_function_debug_context(cx: &mut CrateContext,
580
580
// This is not quite right. It should actually inherit the generics of the
581
581
// enclosing function.
582
582
& empty_generics,
583
- Some ( top_level_block) ,
583
+ top_level_block,
584
584
expr. span )
585
585
}
586
586
_ => cx. sess . span_bug ( expr. span ,
@@ -599,7 +599,7 @@ pub fn create_function_debug_context(cx: &mut CrateContext,
599
599
} ) ,
600
600
_,
601
601
_) => {
602
- ( ident, fn_decl, generics, Some ( top_level_block) , span)
602
+ ( ident, fn_decl, generics, top_level_block, span)
603
603
}
604
604
ast_map:: node_foreign_item( @ast:: foreign_item { _ } , _, _, _) |
605
605
ast_map:: node_variant( * ) |
@@ -624,11 +624,11 @@ pub fn create_function_debug_context(cx: &mut CrateContext,
624
624
625
625
// get_template_parameters() will append a `<...>` clause to the function name if necessary.
626
626
let mut function_name = token:: ident_to_str ( & ident) . to_owned ( ) ;
627
- let template_parameters = if cx . sess . opts . extra_debuginfo {
628
- get_template_parameters ( cx , generics , param_substs , file_metadata , & mut function_name )
629
- } else {
630
- ptr :: null ( )
631
- } ;
627
+ let template_parameters = get_template_parameters ( cx ,
628
+ generics ,
629
+ param_substs ,
630
+ file_metadata ,
631
+ & mut function_name ) ;
632
632
633
633
let namespace_node = debug_context ( cx) . local_namespace_map . find_copy ( & fn_ast_id) ;
634
634
let ( linkage_name, containing_scope) = match namespace_node {
@@ -637,10 +637,9 @@ pub fn create_function_debug_context(cx: &mut CrateContext,
637
637
}
638
638
None => {
639
639
// This branch is only hit when there is a bug in the NamespaceVisitor.
640
- cx. sess . span_warn ( span, "debuginfo: Could not find namespace node for function. \
641
- This is a bug! Try running with RUST_LOG=rustc=1 \
642
- to get further details and report the results \
643
- to github.com/mozilla/rust/issues") ;
640
+ cx. sess . span_warn ( span, fmt ! ( "debuginfo: Could not find namespace node for function
641
+ with name %s. This is a bug! Please report this to
642
+ github.com/mozilla/rust/issues" , function_name) ) ;
644
643
( function_name. clone ( ) , file_metadata)
645
644
}
646
645
} ;
@@ -680,16 +679,14 @@ pub fn create_function_debug_context(cx: &mut CrateContext,
680
679
let arg_pats = do fn_decl. inputs . map |arg_ref| { arg_ref. pat } ;
681
680
populate_scope_map ( cx, arg_pats, top_level_block, fn_metadata, & mut fn_debug_context. scope_map ) ;
682
681
683
- match top_level_block {
684
- Some ( top_level_block) => {
685
- let mut namespace_visitor = NamespaceVisitor :: new_function_visitor ( cx,
686
- function_name,
687
- namespace_node,
688
- file_metadata,
689
- span) ;
690
- visit:: walk_block ( & mut namespace_visitor, top_level_block, ( ) ) ;
691
- }
692
- _ => { /*nothing to do*/ }
682
+ // Create namespaces for the interior of this function
683
+ {
684
+ let mut namespace_visitor = NamespaceVisitor :: new_function_visitor ( cx,
685
+ function_name,
686
+ namespace_node,
687
+ file_metadata,
688
+ span) ;
689
+ visit:: walk_block ( & mut namespace_visitor, top_level_block, ( ) ) ;
693
690
}
694
691
695
692
return FunctionDebugContext ( fn_debug_context) ;
@@ -757,7 +754,7 @@ pub fn create_function_debug_context(cx: &mut CrateContext,
757
754
let has_self_type = self_type. is_some ( ) ;
758
755
759
756
if !generics. is_type_parameterized ( ) && !has_self_type {
760
- return ptr :: null ( ) ;
757
+ return create_DIArray ( DIB ( cx ) , [ ] ) ;
761
758
}
762
759
763
760
name_to_append_suffix_to. push_char ( '<' ) ;
@@ -768,33 +765,37 @@ pub fn create_function_debug_context(cx: &mut CrateContext,
768
765
// Handle self type
769
766
if has_self_type {
770
767
let actual_self_type = self_type. unwrap ( ) ;
771
- let actual_self_type_metadata = type_metadata ( cx,
772
- actual_self_type,
773
- codemap:: dummy_sp ( ) ) ;
774
-
775
768
// Add self type name to <...> clause of function name
776
769
let actual_self_type_name = ppaux:: ty_to_str ( cx. tcx , actual_self_type) ;
777
770
name_to_append_suffix_to. push_str ( actual_self_type_name) ;
771
+
778
772
if generics. is_type_parameterized ( ) {
779
773
name_to_append_suffix_to. push_str ( "," ) ;
780
774
}
781
775
782
- let ident = special_idents:: type_self;
776
+ // Only create type information if extra_debuginfo is enabled
777
+ if cx. sess . opts . extra_debuginfo {
778
+ let actual_self_type_metadata = type_metadata ( cx,
779
+ actual_self_type,
780
+ codemap:: dummy_sp ( ) ) ;
783
781
784
- let param_metadata = do token:: ident_to_str ( & ident) . to_c_str ( ) . with_ref |name| {
785
- unsafe {
786
- llvm:: LLVMDIBuilderCreateTemplateTypeParameter (
787
- DIB ( cx) ,
788
- file_metadata,
789
- name,
790
- actual_self_type_metadata,
791
- ptr:: null ( ) ,
792
- 0 ,
793
- 0 )
794
- }
795
- } ;
782
+ let ident = special_idents:: type_self;
783
+
784
+ let param_metadata = do token:: ident_to_str ( & ident) . to_c_str ( ) . with_ref |name| {
785
+ unsafe {
786
+ llvm:: LLVMDIBuilderCreateTemplateTypeParameter (
787
+ DIB ( cx) ,
788
+ file_metadata,
789
+ name,
790
+ actual_self_type_metadata,
791
+ ptr:: null ( ) ,
792
+ 0 ,
793
+ 0 )
794
+ }
795
+ } ;
796
796
797
- template_params. push ( param_metadata) ;
797
+ template_params. push ( param_metadata) ;
798
+ }
798
799
}
799
800
800
801
// Handle other generic parameters
@@ -807,8 +808,6 @@ pub fn create_function_debug_context(cx: &mut CrateContext,
807
808
808
809
for ( index, & ast:: TyParam { ident : ident, _ } ) in generics. ty_params . iter ( ) . enumerate ( ) {
809
810
let actual_type = actual_types[ index] ;
810
- let actual_type_metadata = type_metadata ( cx, actual_type, codemap:: dummy_sp ( ) ) ;
811
-
812
811
// Add actual type name to <...> clause of function name
813
812
let actual_type_name = ppaux:: ty_to_str ( cx. tcx , actual_type) ;
814
813
name_to_append_suffix_to. push_str ( actual_type_name) ;
@@ -817,20 +816,23 @@ pub fn create_function_debug_context(cx: &mut CrateContext,
817
816
name_to_append_suffix_to. push_str ( "," ) ;
818
817
}
819
818
820
- let param_metadata = do token:: ident_to_str ( & ident) . to_c_str ( ) . with_ref |name| {
821
- unsafe {
822
- llvm:: LLVMDIBuilderCreateTemplateTypeParameter (
823
- DIB ( cx) ,
824
- file_metadata,
825
- name,
826
- actual_type_metadata,
827
- ptr:: null ( ) ,
828
- 0 ,
829
- 0 )
830
- }
831
- } ;
832
-
833
- template_params. push ( param_metadata) ;
819
+ // Again, only create type information if extra_debuginfo is enabled
820
+ if cx. sess . opts . extra_debuginfo {
821
+ let actual_type_metadata = type_metadata ( cx, actual_type, codemap:: dummy_sp ( ) ) ;
822
+ let param_metadata = do token:: ident_to_str ( & ident) . to_c_str ( ) . with_ref |name| {
823
+ unsafe {
824
+ llvm:: LLVMDIBuilderCreateTemplateTypeParameter (
825
+ DIB ( cx) ,
826
+ file_metadata,
827
+ name,
828
+ actual_type_metadata,
829
+ ptr:: null ( ) ,
830
+ 0 ,
831
+ 0 )
832
+ }
833
+ } ;
834
+ template_params. push ( param_metadata) ;
835
+ }
834
836
}
835
837
836
838
name_to_append_suffix_to. push_char ( '>' ) ;
@@ -839,14 +841,14 @@ pub fn create_function_debug_context(cx: &mut CrateContext,
839
841
}
840
842
841
843
fn get_scope_line ( cx : & CrateContext ,
842
- top_level_block : Option < & ast:: Block > ,
844
+ top_level_block : & ast:: Block ,
843
845
default : uint )
844
846
-> uint {
845
- match top_level_block {
846
- Some ( & ast:: Block { stmts : ref statements, _ } ) if statements. len ( ) > 0 => {
847
+ match * top_level_block {
848
+ ast:: Block { stmts : ref statements, _ } if statements. len ( ) > 0 => {
847
849
span_start ( cx, statements[ 0 ] . span ) . line
848
850
}
849
- Some ( & ast:: Block { expr : Some ( @ref expr) , _ } ) => {
851
+ ast:: Block { expr : Some ( @ref expr) , _ } => {
850
852
span_start ( cx, expr. span ) . line
851
853
}
852
854
_ => default
@@ -2154,7 +2156,7 @@ fn get_namespace_and_span_for_item(cx: &mut CrateContext,
2154
2156
// shadowing.
2155
2157
fn populate_scope_map( cx : & mut CrateContext ,
2156
2158
arg_pats : & [ @ast:: Pat ] ,
2157
- fn_entry_block : Option < & ast:: Block > ,
2159
+ fn_entry_block : & ast:: Block ,
2158
2160
fn_metadata : DISubprogram ,
2159
2161
scope_map : & mut HashMap < ast:: NodeId , DIScope > ) {
2160
2162
let def_map = cx. tcx . def_map ;
@@ -2175,13 +2177,9 @@ fn populate_scope_map(cx: &mut CrateContext,
2175
2177
}
2176
2178
}
2177
2179
2178
- for & fn_entry_block in fn_entry_block. iter ( ) {
2179
- walk_block ( cx, fn_entry_block, & mut scope_stack, scope_map) ;
2180
- }
2181
-
2180
+ walk_block ( cx, fn_entry_block, & mut scope_stack, scope_map) ;
2182
2181
2183
2182
// local helper functions for walking the AST.
2184
-
2185
2183
fn with_new_scope ( cx : & mut CrateContext ,
2186
2184
scope_span : Span ,
2187
2185
scope_stack : & mut ~[ ScopeStackEntry ] ,
0 commit comments