@@ -11,10 +11,7 @@ import util::ppaux::ty_to_str;
11
11
export create_local_var;
12
12
export create_function;
13
13
export create_arg;
14
- export add_line_info;
15
14
export update_source_pos;
16
- export invalidate_source_pos;
17
- export revalidate_source_pos;
18
15
export debug_ctxt;
19
16
20
17
const LLVMDebugVersion : int = ( 9 << 16 ) ;
@@ -98,7 +95,7 @@ type metadata<T> = {node: ValueRef, data: T};
98
95
99
96
type file_md = { path: str } ;
100
97
type compile_unit_md = { path: str } ;
101
- type subprogram_md = { name : str , file : str } ;
98
+ type subprogram_md = { path : str } ;
102
99
type local_var_md = { id : ast:: node_id } ;
103
100
type tydesc_md = { hash : uint } ;
104
101
type block_md = { start : codemap:: loc , end : codemap:: loc } ;
@@ -232,7 +229,7 @@ fn create_block(cx: @block_ctxt) -> @metadata<block_md> {
232
229
}
233
230
234
231
let parent = alt cx. parent {
235
- trans_common:: parent_none. { function_metadata_from_block ( cx) . node }
232
+ trans_common:: parent_none. { create_function ( cx. fcx ) . node }
236
233
trans_common:: parent_some ( bcx) { create_block ( cx) . node }
237
234
} ;
238
235
let file_node = create_file ( bcx_ccx ( cx) , fname) ;
@@ -595,14 +592,6 @@ fn create_ty(cx: @crate_ctxt, t: ty::t, ty: @ast::ty) -> @metadata<tydesc_md> {
595
592
} ;
596
593
}
597
594
598
- fn function_metadata_from_block ( bcx : @block_ctxt ) -> @metadata < subprogram_md > {
599
- let cx = bcx_ccx ( bcx) ;
600
- let fcx = bcx_fcx ( bcx) ;
601
- let fn_node = cx. ast_map . get ( fcx. id ) ;
602
- let fn_item = alt fn_node { ast_map : : node_item ( item) { item } } ;
603
- ret create_function ( fcx, fn_item, fcx. llfn ) ;
604
- }
605
-
606
595
fn filename_from_span ( cx : @crate_ctxt , sp : codemap:: span ) -> str {
607
596
codemap:: lookup_char_pos ( cx. sess . get_codemap ( ) , sp. lo ) . filename
608
597
}
@@ -640,7 +629,7 @@ fn create_local_var(bcx: @block_ctxt, local: @ast::local)
640
629
let tymd = create_ty ( cx, ty, local. node . ty ) ;
641
630
let filemd = create_file ( cx, loc. filename ) ;
642
631
let context = alt bcx. parent {
643
- trans_common:: parent_none. { function_metadata_from_block ( bcx) . node }
632
+ trans_common:: parent_none. { create_function ( bcx. fcx ) . node }
644
633
trans_common:: parent_some ( _) { create_block ( bcx) . node }
645
634
} ;
646
635
let mdnode = create_var ( tg, context, name, filemd. node ,
@@ -662,7 +651,6 @@ fn create_local_var(bcx: @block_ctxt, local: @ast::local)
662
651
ret mdval;
663
652
}
664
653
665
- //FIXME: consolidate with create_local_var
666
654
fn create_arg ( bcx : @block_ctxt , arg : ast:: arg )
667
655
-> @metadata < argument_md > unsafe {
668
656
let fcx = bcx_fcx ( bcx) ;
@@ -683,9 +671,7 @@ fn create_arg(bcx: @block_ctxt, arg: ast::arg)
683
671
let ty = trans:: node_id_type ( cx, arg. id ) ;
684
672
let tymd = create_ty ( cx, ty, arg. ty ) ;
685
673
let filemd = create_file ( cx, loc. filename ) ;
686
- let fn_node = cx. ast_map . get ( fcx. id ) ;
687
- let fn_item = alt fn_node { ast_map : : node_item ( item) { item } } ;
688
- let context = create_function ( fcx, fn_item, fcx. llfn ) ;
674
+ let context = create_function ( bcx. fcx ) ;
689
675
let mdnode = create_var ( tg, context. node , arg. ident , filemd. node ,
690
676
loc. line as int , tymd. node ) ;
691
677
let mdval = @{ node: mdnode, data : { id : arg. id } } ;
@@ -700,92 +686,76 @@ fn create_arg(bcx: @block_ctxt, arg: ast::arg)
700
686
ret mdval;
701
687
}
702
688
703
- fn update_source_pos ( cx : @block_ctxt , s : codemap:: span ) -> @debug_source_pos {
704
- let dsp = @debug_source_pos ( cx) ;
689
+ fn update_source_pos ( cx : @block_ctxt , s : codemap:: span ) {
705
690
if !bcx_ccx ( cx) . sess . get_opts ( ) . debuginfo {
706
- ret dsp ;
691
+ ret;
707
692
}
708
693
let cm = bcx_ccx ( cx) . sess . get_codemap ( ) ;
709
- if vec:: is_empty ( cx. source_pos . pos ) {
710
- cx. source_pos . usable = true ;
711
- }
712
- cx. source_pos . pos += [ codemap:: lookup_char_pos ( cm, s. lo ) ] ; //XXX maybe hi
713
- ret dsp;
694
+ let blockmd = create_block ( cx) ;
695
+ let loc = codemap:: lookup_char_pos ( cm, s. lo ) ;
696
+ let scopedata = [ lli32 ( loc. line as int ) ,
697
+ lli32 ( loc. col as int ) ,
698
+ blockmd. node ,
699
+ llnull ( ) ] ;
700
+ let dbgscope = llmdnode ( scopedata) ;
701
+ llvm:: LLVMSetCurrentDebugLocation ( trans_build:: B ( cx) , dbgscope) ;
714
702
}
715
703
716
- fn invalidate_source_pos ( cx : @block_ctxt ) -> @invalidated_source_pos {
717
- let isp = @invalidated_source_pos ( cx) ;
718
- if !bcx_ccx ( cx) . sess . get_opts ( ) . debuginfo {
719
- ret isp;
720
- }
721
- cx. source_pos . usable = false ;
722
- ret isp;
723
- }
704
+ fn create_function ( fcx : @fn_ctxt ) -> @metadata < subprogram_md > {
705
+ let cx = fcx_ccx ( fcx) ;
706
+ let dbg_cx = option:: get ( cx. dbg_cx ) ;
724
707
725
- fn revalidate_source_pos ( cx : @block_ctxt ) {
726
- if !bcx_ccx ( cx) . sess . get_opts ( ) . debuginfo {
727
- ret;
728
- }
729
- cx. source_pos . usable = true ;
730
- }
708
+ log "~~" ;
709
+ log fcx. id ;
710
+ log cx. sess . span_str ( fcx. sp ) ;
731
711
732
- fn reset_source_pos ( cx : @block_ctxt ) {
733
- if !bcx_ccx ( cx) . sess . get_opts ( ) . debuginfo {
734
- ret;
735
- }
736
- vec:: pop ( cx. source_pos . pos ) ;
737
- }
712
+ let ( ident, ret_ty, id) = alt cx. ast_map . get ( fcx. id ) {
713
+ ast_map:: node_item ( item) {
714
+ alt item. node {
715
+ ast:: item_fn ( f, _) | ast:: item_res ( f, _, _, _) {
716
+ ( item. ident , f. decl . output , item. id )
717
+ }
718
+ }
719
+ }
720
+ ast_map:: node_obj_method ( method) {
721
+ ( method. node . ident , method. node . meth . decl . output , method. node . id )
722
+ }
723
+ ast_map:: node_res_ctor ( item) {
724
+ alt item. node { ast:: item_res ( f, _, _, ctor_id) {
725
+ ( item. ident , f. decl . output , ctor_id)
726
+ } }
727
+ }
728
+ ast_map:: node_expr ( expr) {
729
+ alt expr. node {
730
+ ast:: expr_fn ( f) {
731
+ ( dbg_cx. names . next ( "fn" ) , f. decl . output , expr. id )
732
+ }
733
+ }
734
+ }
735
+ } ;
738
736
739
- resource debug_source_pos ( bcx: @block_ctxt) {
740
- reset_source_pos ( bcx) ;
741
- }
742
- resource invalidated_source_pos ( bcx: @block_ctxt) {
743
- revalidate_source_pos ( bcx) ;
744
- }
737
+ log ident;
738
+ log id;
739
+
740
+ let path = str:: connect ( fcx. lcx . path + [ ident] , "::" ) ;
745
741
746
- fn add_line_info ( cx : @block_ctxt , llinstr : ValueRef ) {
747
- if !bcx_ccx ( cx) . sess . get_opts ( ) . debuginfo ||
748
- !cx. source_pos . usable ||
749
- vec:: is_empty ( cx. source_pos . pos ) {
750
- ret;
751
- }
752
- let loc = option:: get ( vec:: last ( cx. source_pos . pos ) ) ;
753
- let blockmd = create_block ( cx) ;
754
- let kind = "dbg" ;
755
- str:: as_buf ( kind, { |sbuf|
756
- let kind_id = llvm:: LLVMGetMDKindID ( sbuf,
757
- str:: byte_len ( kind) ) ;
758
- let scopedata = [ lli32 ( loc. line as int ) ,
759
- lli32 ( loc. col as int ) ,
760
- blockmd. node ,
761
- llnull ( ) ] ;
762
- let dbgscope = llmdnode ( scopedata) ;
763
- llvm:: LLVMSetMetadata ( llinstr, kind_id, dbgscope)
764
- } ) ;
765
- }
766
-
767
- fn create_function ( fcx : @fn_ctxt , item : @ast:: item , llfndecl : ValueRef )
768
- -> @metadata < subprogram_md > {
769
- let cx = fcx_ccx ( fcx) ;
770
742
let cache = get_cache ( cx) ;
771
743
alt cached_metadata :: < @metadata < subprogram_md > > (
772
- cache, SubprogramTag , { |md| md. data . name == item . ident &&
744
+ cache, SubprogramTag , { |md| md. data . path == path &&
773
745
/*md.data.path == ??*/ true } ) {
774
746
option:: some ( md) { ret md; }
775
747
option:: none. { }
776
748
}
777
749
778
750
let loc = codemap:: lookup_char_pos ( cx. sess . get_codemap ( ) ,
779
- item . span . lo ) ;
751
+ fcx . sp . lo ) ;
780
752
let file_node = create_file ( cx, loc. filename ) . node ;
781
- let mangled = cx. item_symbols . get ( item. id ) ;
782
- let ret_ty = alt item. node {
783
- ast:: item_fn ( f, _) { f. decl . output }
784
- } ;
753
+ let key = cx. item_symbols . contains_key ( fcx. id ) ? fcx. id : id;
754
+ let mangled = cx. item_symbols . get ( key) ;
785
755
let ty_node = if cx. sess . get_opts ( ) . extra_debuginfo {
786
756
alt ret_ty. node {
787
757
ast:: ty_nil. { llnull ( ) }
788
- _ { create_ty( cx, ty:: node_id_to_type ( ccx_tcx ( cx) , item . id ) ,
758
+ _ { create_ty( cx, ty:: node_id_to_type ( ccx_tcx ( cx) , id) ,
789
759
ret_ty) . node }
790
760
}
791
761
} else {
@@ -798,8 +768,8 @@ fn create_function(fcx: @fn_ctxt, item: @ast::item, llfndecl: ValueRef)
798
768
let fn_metadata = [ lltag ( SubprogramTag ) ,
799
769
llunused ( ) ,
800
770
file_node,
801
- llstr ( item . ident ) ,
802
- llstr ( item . ident ) , //XXX fully-qualified C++ name
771
+ llstr ( ident) ,
772
+ llstr ( path ) , //XXX fully-qualified C++ name
803
773
llstr ( mangled) , //XXX MIPS name?????
804
774
file_node,
805
775
lli32 ( loc. line as int ) ,
@@ -811,15 +781,14 @@ fn create_function(fcx: @fn_ctxt, item: @ast::item, llfndecl: ValueRef)
811
781
llnull ( ) , // base type with vtbl
812
782
lli1 ( false ) , // artificial
813
783
lli1 ( cx. sess . get_opts ( ) . optimize != 0 u) ,
814
- llfndecl
784
+ fcx . llfn
815
785
//list of template params
816
786
//func decl descriptor
817
787
//list of func vars
818
788
] ;
819
789
let val = llmdnode ( fn_metadata) ;
820
790
add_named_metadata ( cx, "llvm.dbg.sp" , val) ;
821
- let mdval = @{ node: val, data : { name : item. ident ,
822
- file : loc. filename } } ;
791
+ let mdval = @{ node: val, data : { path : path} } ;
823
792
update_cache ( cache, SubprogramTag , subprogram_metadata ( mdval) ) ;
824
793
ret mdval;
825
794
}
0 commit comments