@@ -149,7 +149,7 @@ pub fn create_local_var(bcx: block, local: @ast::local) -> DIVariable {
149
149
let loc = span_start ( cx, local. span ) ;
150
150
let ty = node_id_type ( bcx, local. node . id ) ;
151
151
let tymd = create_ty ( cx, ty, local. node . ty . span ) ;
152
- let filemd = create_file ( cx, loc. file . name ) ;
152
+ let filemd = get_or_create_file ( cx, loc. file . name ) ;
153
153
let context = match bcx. parent {
154
154
None => create_function ( bcx. fcx ) ,
155
155
Some ( _) => create_block ( bcx)
@@ -203,7 +203,7 @@ pub fn create_arg(bcx: block, arg: &ast::arg, span: span) -> Option<DIVariable>
203
203
204
204
let ty = node_id_type ( bcx, arg. id ) ;
205
205
let tymd = create_ty ( cx, ty, arg. ty . span ) ;
206
- let filemd = create_file ( cx, loc. file . name ) ;
206
+ let filemd = get_or_create_file ( cx, loc. file . name ) ;
207
207
let context = create_function ( fcx) ;
208
208
209
209
match arg. pat . node {
@@ -297,7 +297,7 @@ pub fn create_function(fcx: fn_ctxt) -> DISubprogram {
297
297
debug ! ( "create_function: %s, %s" , cx. sess. str_of( ident) , cx. sess. codemap. span_to_str( span) ) ;
298
298
299
299
let loc = span_start ( cx, span) ;
300
- let file_md = create_file ( cx, loc. file . name ) ;
300
+ let file_md = get_or_create_file ( cx, loc. file . name ) ;
301
301
302
302
let ret_ty_md = if cx. sess . opts . extra_debuginfo {
303
303
match ret_ty. node {
@@ -374,13 +374,13 @@ fn create_compile_unit(cx: @mut CrateContext) {
374
374
} } } } } } ;
375
375
}
376
376
377
- fn create_file ( cx : & mut CrateContext , full_path : & str ) -> DIFile {
377
+ fn get_or_create_file ( cx : & mut CrateContext , full_path : & str ) -> DIFile {
378
378
match dbg_cx ( cx) . created_files . find_equiv ( & full_path) {
379
379
Some ( file_md) => return * file_md,
380
380
None => ( )
381
381
}
382
382
383
- debug ! ( "create_file : %s" , full_path) ;
383
+ debug ! ( "get_or_create_file : %s" , full_path) ;
384
384
385
385
let work_dir = cx. sess . working_dir . to_str ( ) ;
386
386
let file_name =
@@ -428,7 +428,7 @@ fn create_block(bcx: block) -> DILexicalBlock {
428
428
} ;
429
429
let cx = bcx. ccx ( ) ;
430
430
let loc = span_start ( cx, span) ;
431
- let file_md = create_file ( cx, loc. file . name ) ;
431
+ let file_md = get_or_create_file ( cx, loc. file . name ) ;
432
432
433
433
let block_md = unsafe {
434
434
llvm:: LLVMDIBuilderCreateLexicalBlock (
@@ -639,6 +639,9 @@ fn create_tuple(cx: &mut CrateContext,
639
639
span) ;
640
640
}
641
641
642
+ /// Creates debug information for a composite type, that is, anything that results in a LLVM struct.
643
+ ///
644
+ /// Examples of Rust types to use this are: structs, tuples, boxes, and enums.
642
645
fn create_composite_type ( cx : & mut CrateContext ,
643
646
composite_llvm_type : Type ,
644
647
composite_type_name : & str ,
@@ -649,7 +652,7 @@ fn create_composite_type(cx: &mut CrateContext,
649
652
-> DICompositeType {
650
653
651
654
let loc = span_start ( cx, span) ;
652
- let file_metadata = create_file ( cx, loc. file . name ) ;
655
+ let file_metadata = get_or_create_file ( cx, loc. file . name ) ;
653
656
654
657
let composite_size = machine:: llsize_of_alloc ( cx, composite_llvm_type) ;
655
658
let composite_align = machine:: llalign_of_min ( cx, composite_llvm_type) ;
@@ -763,47 +766,21 @@ fn create_boxed_type(cx: &mut CrateContext,
763
766
member_types_metadata,
764
767
span) ;
765
768
769
+ // Unfortunately, we cannot assert anything but the correct types here---and not whether the
770
+ // 'next' and 'prev' pointers are in the order.
766
771
fn box_layout_is_as_expected ( cx : & CrateContext ,
767
- member_types : & [ Type ] ,
768
- content_type : Type )
772
+ member_llvm_types : & [ Type ] ,
773
+ content_llvm_type : Type )
769
774
-> bool {
770
- return member_types[ 0 ] == cx. int_type
771
- && member_types[ 1 ] == cx. tydesc_type . ptr_to ( )
772
- && member_types[ 2 ] == Type :: i8 ( ) . ptr_to ( )
773
- && member_types[ 3 ] == Type :: i8 ( ) . ptr_to ( )
774
- && member_types[ 4 ] == content_type;
775
+ member_llvm_types. len ( ) == 5 &&
776
+ member_llvm_types[ 0 ] == cx. int_type &&
777
+ member_llvm_types[ 1 ] == cx. tydesc_type . ptr_to ( ) &&
778
+ member_llvm_types[ 2 ] == Type :: i8 ( ) . ptr_to ( ) &&
779
+ member_llvm_types[ 3 ] == Type :: i8 ( ) . ptr_to ( ) &&
780
+ member_llvm_types[ 4 ] == content_llvm_type
775
781
}
776
782
}
777
783
778
- // fn create_boxed_type(cx: &mut CrateContext,
779
- // contents: ty::t,
780
- // span: span,
781
- // boxed: DIType)
782
- // -> DICompositeType {
783
-
784
- // debug!("create_boxed_type: %?", ty::get(contents));
785
-
786
- // let loc = span_start(cx, span);
787
- // let file_md = create_file(cx, loc.file.name);
788
- // let int_t = ty::mk_int();
789
- // let refcount_type = create_basic_type(cx, int_t, span);
790
- // let name = ty_to_str(cx.tcx, contents);
791
-
792
- // let mut scx = StructContext::new(cx, fmt!("box<%s>", name), file_md, 0);
793
- // scx.add_member("refcnt", 0, sys::size_of::<uint>(),
794
- // sys::min_align_of::<uint>(), refcount_type);
795
- // // the tydesc and other pointers should be irrelevant to the
796
- // // debugger, so treat them as void* types
797
- // let (vp, vpsize, vpalign) = voidptr(cx);
798
- // scx.add_member("tydesc", 0, vpsize, vpalign, vp);
799
- // scx.add_member("prev", 0, vpsize, vpalign, vp);
800
- // scx.add_member("next", 0, vpsize, vpalign, vp);
801
- // let (size, align) = size_and_align_of(cx, contents);
802
- // scx.add_member("val", 0, size, align, boxed);
803
- // return scx.finalize();
804
- // }
805
-
806
-
807
784
fn create_fixed_vec ( cx : & mut CrateContext , _vec_t : ty:: t , elem_t : ty:: t ,
808
785
len : uint , span : span ) -> DIType {
809
786
debug ! ( "create_fixed_vec: %?" , ty:: get( _vec_t) ) ;
@@ -831,7 +808,7 @@ fn create_boxed_vec(cx: &mut CrateContext, vec_t: ty::t, elem_t: ty::t,
831
808
debug ! ( "create_boxed_vec: %?" , ty:: get( vec_t) ) ;
832
809
833
810
let loc = span_start ( cx, vec_ty_span) ;
834
- let file_md = create_file ( cx, loc. file . name ) ;
811
+ let file_md = get_or_create_file ( cx, loc. file . name ) ;
835
812
let elem_ty_md = create_ty ( cx, elem_t, vec_ty_span) ;
836
813
837
814
let mut vec_scx = StructContext :: new ( cx, ty_to_str ( cx. tcx , vec_t) , file_md, 0 ) ;
@@ -896,29 +873,54 @@ fn create_boxed_vec(cx: &mut CrateContext, vec_t: ty::t, elem_t: ty::t,
896
873
return mdval;
897
874
}
898
875
899
- fn create_vec_slice ( cx : & mut CrateContext , vec_t : ty:: t , elem_t : ty:: t , span : span )
900
- -> DICompositeType {
901
- debug ! ( "create_vec_slice: %?" , ty:: get( vec_t) ) ;
876
+ fn create_vec_slice ( cx : & mut CrateContext ,
877
+ vec_type : ty:: t ,
878
+ element_type : ty:: t ,
879
+ span : span )
880
+ -> DICompositeType {
902
881
903
- let loc = span_start ( cx, span) ;
904
- let file_md = create_file ( cx, loc. file . name ) ;
905
- let elem_ty_md = create_ty ( cx, elem_t, span) ;
906
- let uint_type = create_basic_type ( cx, ty:: mk_uint ( ) , span) ;
907
- let elem_ptr = create_pointer_type ( cx, elem_t, span, elem_ty_md) ;
882
+ debug ! ( "create_vec_slice: %?" , ty:: get( vec_type) ) ;
908
883
909
- let mut scx = StructContext :: new ( cx, ty_to_str ( cx. tcx , vec_t) , file_md, 0 ) ;
910
- let ( _, ptr_size, ptr_align) = voidptr ( cx) ;
911
- scx. add_member ( "vec" , 0 , ptr_size, ptr_align, elem_ptr) ;
912
- scx. add_member ( "length" , 0 , sys:: size_of :: < uint > ( ) , sys:: min_align_of :: < uint > ( ) , uint_type) ;
913
- return scx. finalize ( ) ;
884
+ let slice_llvm_type = type_of:: type_of ( cx, vec_type) ;
885
+ let slice_type_name = ty_to_str ( cx. tcx , vec_type) ;
886
+
887
+ let member_llvm_types = slice_llvm_type. field_types ( ) ;
888
+ let member_names = & [ ~"data_ptr", ~"size_in_bytes"] ;
889
+
890
+ assert ! ( slice_layout_is_as_expected( cx, member_llvm_types, element_type) ) ;
891
+
892
+ let data_ptr_type = ty:: mk_ptr ( cx. tcx , ty:: mt { ty : element_type, mutbl : ast:: m_const } ) ;
893
+
894
+ let member_type_metadata = & [
895
+ create_ty ( cx, data_ptr_type, span) ,
896
+ create_ty ( cx, ty:: mk_uint ( ) , span)
897
+ ] ;
898
+
899
+ return create_composite_type (
900
+ cx,
901
+ slice_llvm_type,
902
+ slice_type_name,
903
+ member_llvm_types,
904
+ member_names,
905
+ member_type_metadata,
906
+ span) ;
907
+
908
+ fn slice_layout_is_as_expected ( cx : & mut CrateContext ,
909
+ member_llvm_types : & [ Type ] ,
910
+ element_type : ty:: t )
911
+ -> bool {
912
+ member_llvm_types. len ( ) == 2 &&
913
+ member_llvm_types[ 0 ] == type_of:: type_of ( cx, element_type) . ptr_to ( ) &&
914
+ member_llvm_types[ 1 ] == cx. int_type
915
+ }
914
916
}
915
917
916
918
fn create_fn_ty ( cx : & mut CrateContext , _fn_ty : ty:: t , inputs : ~[ ty:: t ] , output : ty:: t ,
917
919
span : span ) -> DICompositeType {
918
920
debug ! ( "create_fn_ty: %?" , ty:: get( _fn_ty) ) ;
919
921
920
922
let loc = span_start ( cx, span) ;
921
- let file_md = create_file ( cx, loc. file . name ) ;
923
+ let file_md = get_or_create_file ( cx, loc. file . name ) ;
922
924
let ( vp, _, _) = voidptr ( cx) ;
923
925
let output_md = create_ty ( cx, output, span) ;
924
926
let output_ptr_md = create_pointer_type ( cx, output, span, output_md) ;
0 commit comments