@@ -56,7 +56,7 @@ use util::ppaux::ty_to_str;
5656
5757use core:: hashmap:: HashMap ;
5858use core:: libc;
59- use core:: libc:: c_uint;
59+ use core:: libc:: { c_uint, c_ulonglong } ;
6060use core:: cmp;
6161use core:: ptr;
6262use core:: str:: as_c_str;
@@ -337,6 +337,9 @@ fn create_DIArray(builder: DIBuilderRef, arr: &[DIDescriptor]) -> DIArray {
337337fn create_compile_unit ( cx : @mut CrateContext ) {
338338 let dcx = dbg_cx ( cx) ;
339339 let crate_name: & str = dcx. crate_file ;
340+
341+ debug ! ( "create_compile_unit: %?" , crate_name) ;
342+
340343 let work_dir = cx. sess . working_dir . to_str ( ) ;
341344 let producer = fmt ! ( "rustc version %s" , env!( "CFG_VERSION" ) ) ;
342345
@@ -507,40 +510,91 @@ impl StructContext {
507510 }
508511
509512 fn add_member ( & mut self , name : & str , line : uint , size : uint , align : uint , ty : DIType ) {
510- debug ! ( "StructContext(%s)::add_member: %s, size=%u, align=%u" ,
511- self . name, name, size, align) ;
512513 let offset = roundup ( self . total_size , align) ;
514+
515+ debug ! ( "StructContext(%s)::add_member: %s, size=%u, align=%u, offset=%u" ,
516+ self . name, name, size, align, offset) ;
517+
513518 let mem_t = do as_c_str ( name) |name| { unsafe {
514519 llvm:: LLVMDIBuilderCreateMemberType (
515- self . builder , ptr:: null ( ) , name, self . file , line as c_uint ,
516- size * 8 as u64 , align * 8 as u64 , offset * 8 as u64 ,
517- 0 , ty)
520+ self . builder ,
521+ self . file ,
522+ name,
523+ self . file ,
524+ line as c_uint ,
525+ ( size * 8 ) as c_ulonglong ,
526+ ( align * 8 ) as c_ulonglong ,
527+ ( offset * 8 ) as c_ulonglong ,
528+ 0 ,
529+ ty)
518530 } } ;
519531 self . members . push ( mem_t) ;
520532 self . total_size = offset + size;
521533 // struct alignment is the max alignment of its' members
522534 self . align = cmp:: max ( self . align , align) ;
523535 }
524536
537+ fn get_total_size_with_alignment ( & self ) -> uint {
538+ roundup ( self . total_size , self . align )
539+ }
540+
541+ //fn verify_against_struct_or_tuple_type(&self, t: ty::t, ccx: &mut CrateContext) {
542+ // let repr = adt::represent_type(ccx, t);
543+
544+ // match *repr {
545+ // Univariant(*) =>
546+ // {
547+ // let size_with_alignment = self.get_total_size_with_alignment();
548+
549+ // if st.size != size_with_alignment {
550+ // ccx.sess.bug("StructContext(%s)::verify_against_struct_or_tuple_type: invalid type size. Expected = %u, actual = %u",
551+ // st.size, size_with_alignment);
552+ // }
553+
554+ // if st.align != self.align {
555+ // ccx.sess.bug("StructContext(%s)::verify_against_struct_or_tuple_type: invalid type alignment. Expected = %u, actual = %u",
556+ // st.align, self.align);
557+ // }
558+ // },
559+ // _ => ccx.sess.bug(fmt!("StructContext(%s)::verify_against_struct_or_tuple_type: called with invalid type %?",
560+ // self.name, t))
561+ // }
562+ //}
563+
525564 fn finalize ( & self ) -> DICompositeType {
526565 debug ! ( "StructContext(%s)::finalize: total_size=%u, align=%u" ,
527566 self . name, self . total_size, self . align) ;
528567 let members_md = create_DIArray ( self . builder , self . members ) ;
529568
569+ // The size of the struct/tuple must be rounded to the next multiple of its alignment.
570+ // Otherwise gdb has trouble reading the struct correct when it is embedded into another
571+ // data structure. This is also the value `sizeof` in C would give.
572+ let total_size_with_alignment = self . get_total_size_with_alignment ( ) ;
573+
530574 let struct_md =
531575 do as_c_str ( self . name ) |name| { unsafe {
532576 llvm:: LLVMDIBuilderCreateStructType (
533- self . builder , self . file , name,
534- self . file , self . line as c_uint ,
535- self . total_size * 8 as u64 , self . align * 8 as u64 , 0 , ptr:: null ( ) ,
536- members_md, 0 , ptr:: null ( ) )
577+ self . builder ,
578+ self . file ,
579+ name,
580+ self . file ,
581+ self . line as c_uint ,
582+ ( total_size_with_alignment * 8 ) as c_ulonglong ,
583+ ( self . align * 8 ) as c_ulonglong ,
584+ 0 ,
585+ ptr:: null ( ) ,
586+ members_md,
587+ 0 ,
588+ ptr:: null ( ) )
537589 } } ;
538590 return struct_md;
539591 }
540592}
541593
542- fn create_struct ( cx : @mut CrateContext , t : ty:: t , fields : ~[ ty:: field ] , span : span )
594+ fn create_struct ( cx : @mut CrateContext , struct_type : ty:: t , fields : ~[ ty:: field ] , span : span )
543595 -> DICompositeType {
596+ debug ! ( "create_struct: %?" , ty:: get( struct_type) ) ;
597+
544598 let loc = span_start ( cx, span) ;
545599 let file_md = create_file ( cx, loc. file . name ) ;
546600
@@ -565,8 +619,10 @@ fn voidptr(cx: @mut CrateContext) -> (DIDerivedType, uint, uint) {
565619 return ( vp, size, align) ;
566620}
567621
568- fn create_tuple ( cx : @mut CrateContext , _t : ty:: t , elements : & [ ty:: t ] , span : span )
622+ fn create_tuple ( cx : @mut CrateContext , tuple_type : ty:: t , elements : & [ ty:: t ] , span : span )
569623 -> DICompositeType {
624+ debug ! ( "create_tuple: %?" , ty:: get( tuple_type) ) ;
625+
570626 let loc = span_start ( cx, span) ;
571627 let file_md = create_file ( cx, loc. file . name ) ;
572628
@@ -582,6 +638,8 @@ fn create_tuple(cx: @mut CrateContext, _t: ty::t, elements: &[ty::t], span: span
582638
583639fn create_boxed_type ( cx : @mut CrateContext , contents : ty:: t ,
584640 span : span , boxed : DIType ) -> DICompositeType {
641+ debug ! ( "create_boxed_type: %?" , ty:: get( contents) ) ;
642+
585643 let loc = span_start ( cx, span) ;
586644 let file_md = create_file ( cx, loc. file . name ) ;
587645 let int_t = ty:: mk_int ( ) ;
@@ -604,6 +662,8 @@ fn create_boxed_type(cx: @mut CrateContext, contents: ty::t,
604662
605663fn create_fixed_vec ( cx : @mut CrateContext , _vec_t : ty:: t , elem_t : ty:: t ,
606664 len : uint , span : span ) -> DIType {
665+ debug ! ( "create_fixed_vec: %?" , ty:: get( _vec_t) ) ;
666+
607667 let elem_ty_md = create_ty ( cx, elem_t, span) ;
608668 let ( size, align) = size_and_align_of ( cx, elem_t) ;
609669
@@ -620,6 +680,8 @@ fn create_fixed_vec(cx: @mut CrateContext, _vec_t: ty::t, elem_t: ty::t,
620680
621681fn create_boxed_vec ( cx : @mut CrateContext , vec_t : ty:: t , elem_t : ty:: t ,
622682 vec_ty_span : span ) -> DICompositeType {
683+ debug ! ( "create_boxed_vec: %?" , ty:: get( vec_t) ) ;
684+
623685 let loc = span_start ( cx, vec_ty_span) ;
624686 let file_md = create_file ( cx, loc. file . name ) ;
625687 let elem_ty_md = create_ty ( cx, elem_t, vec_ty_span) ;
@@ -663,6 +725,8 @@ fn create_boxed_vec(cx: @mut CrateContext, vec_t: ty::t, elem_t: ty::t,
663725
664726fn create_vec_slice ( cx : @mut CrateContext , vec_t : ty:: t , elem_t : ty:: t , span : span )
665727 -> DICompositeType {
728+ debug ! ( "create_vec_slice: %?" , ty:: get( vec_t) ) ;
729+
666730 let loc = span_start ( cx, span) ;
667731 let file_md = create_file ( cx, loc. file . name ) ;
668732 let elem_ty_md = create_ty ( cx, elem_t, span) ;
@@ -679,6 +743,8 @@ fn create_vec_slice(cx: @mut CrateContext, vec_t: ty::t, elem_t: ty::t, span: sp
679743
680744fn create_fn_ty ( cx : @mut CrateContext , _fn_ty : ty:: t , inputs : ~[ ty:: t ] , output : ty:: t ,
681745 span : span ) -> DICompositeType {
746+ debug ! ( "create_fn_ty: %?" , ty:: get( _fn_ty) ) ;
747+
682748 let loc = span_start ( cx, span) ;
683749 let file_md = create_file ( cx, loc. file . name ) ;
684750 let ( vp, _, _) = voidptr ( cx) ;
@@ -694,6 +760,8 @@ fn create_fn_ty(cx: @mut CrateContext, _fn_ty: ty::t, inputs: ~[ty::t], output:
694760}
695761
696762fn create_unimpl_ty ( cx : @mut CrateContext , t : ty:: t ) -> DIType {
763+ debug ! ( "create_unimpl_ty: %?" , ty:: get( t) ) ;
764+
697765 let name = ty_to_str ( cx. tcx , t) ;
698766 let md = do as_c_str ( fmt ! ( "NYI<%s>" , name) ) |name| { unsafe {
699767 llvm:: LLVMDIBuilderCreateBasicType (
0 commit comments