@@ -56,7 +56,7 @@ use util::ppaux::ty_to_str;
56
56
57
57
use core:: hashmap:: HashMap ;
58
58
use core:: libc;
59
- use core:: libc:: c_uint;
59
+ use core:: libc:: { c_uint, c_ulonglong } ;
60
60
use core:: cmp;
61
61
use core:: ptr;
62
62
use core:: str:: as_c_str;
@@ -337,6 +337,9 @@ fn create_DIArray(builder: DIBuilderRef, arr: &[DIDescriptor]) -> DIArray {
337
337
fn create_compile_unit ( cx : @mut CrateContext ) {
338
338
let dcx = dbg_cx ( cx) ;
339
339
let crate_name: & str = dcx. crate_file ;
340
+
341
+ debug ! ( "create_compile_unit: %?" , crate_name) ;
342
+
340
343
let work_dir = cx. sess . working_dir . to_str ( ) ;
341
344
let producer = fmt ! ( "rustc version %s" , env!( "CFG_VERSION" ) ) ;
342
345
@@ -507,40 +510,91 @@ impl StructContext {
507
510
}
508
511
509
512
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) ;
512
513
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
+
513
518
let mem_t = do as_c_str ( name) |name| { unsafe {
514
519
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)
518
530
} } ;
519
531
self . members . push ( mem_t) ;
520
532
self . total_size = offset + size;
521
533
// struct alignment is the max alignment of its' members
522
534
self . align = cmp:: max ( self . align , align) ;
523
535
}
524
536
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
+
525
564
fn finalize ( & self ) -> DICompositeType {
526
565
debug ! ( "StructContext(%s)::finalize: total_size=%u, align=%u" ,
527
566
self . name, self . total_size, self . align) ;
528
567
let members_md = create_DIArray ( self . builder , self . members ) ;
529
568
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
+
530
574
let struct_md =
531
575
do as_c_str ( self . name ) |name| { unsafe {
532
576
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 ( ) )
537
589
} } ;
538
590
return struct_md;
539
591
}
540
592
}
541
593
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 )
543
595
-> DICompositeType {
596
+ debug ! ( "create_struct: %?" , ty:: get( struct_type) ) ;
597
+
544
598
let loc = span_start ( cx, span) ;
545
599
let file_md = create_file ( cx, loc. file . name ) ;
546
600
@@ -565,8 +619,10 @@ fn voidptr(cx: @mut CrateContext) -> (DIDerivedType, uint, uint) {
565
619
return ( vp, size, align) ;
566
620
}
567
621
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 )
569
623
-> DICompositeType {
624
+ debug ! ( "create_tuple: %?" , ty:: get( tuple_type) ) ;
625
+
570
626
let loc = span_start ( cx, span) ;
571
627
let file_md = create_file ( cx, loc. file . name ) ;
572
628
@@ -582,6 +638,8 @@ fn create_tuple(cx: @mut CrateContext, _t: ty::t, elements: &[ty::t], span: span
582
638
583
639
fn create_boxed_type ( cx : @mut CrateContext , contents : ty:: t ,
584
640
span : span , boxed : DIType ) -> DICompositeType {
641
+ debug ! ( "create_boxed_type: %?" , ty:: get( contents) ) ;
642
+
585
643
let loc = span_start ( cx, span) ;
586
644
let file_md = create_file ( cx, loc. file . name ) ;
587
645
let int_t = ty:: mk_int ( ) ;
@@ -604,6 +662,8 @@ fn create_boxed_type(cx: @mut CrateContext, contents: ty::t,
604
662
605
663
fn create_fixed_vec ( cx : @mut CrateContext , _vec_t : ty:: t , elem_t : ty:: t ,
606
664
len : uint , span : span ) -> DIType {
665
+ debug ! ( "create_fixed_vec: %?" , ty:: get( _vec_t) ) ;
666
+
607
667
let elem_ty_md = create_ty ( cx, elem_t, span) ;
608
668
let ( size, align) = size_and_align_of ( cx, elem_t) ;
609
669
@@ -620,6 +680,8 @@ fn create_fixed_vec(cx: @mut CrateContext, _vec_t: ty::t, elem_t: ty::t,
620
680
621
681
fn create_boxed_vec ( cx : @mut CrateContext , vec_t : ty:: t , elem_t : ty:: t ,
622
682
vec_ty_span : span ) -> DICompositeType {
683
+ debug ! ( "create_boxed_vec: %?" , ty:: get( vec_t) ) ;
684
+
623
685
let loc = span_start ( cx, vec_ty_span) ;
624
686
let file_md = create_file ( cx, loc. file . name ) ;
625
687
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,
663
725
664
726
fn create_vec_slice ( cx : @mut CrateContext , vec_t : ty:: t , elem_t : ty:: t , span : span )
665
727
-> DICompositeType {
728
+ debug ! ( "create_vec_slice: %?" , ty:: get( vec_t) ) ;
729
+
666
730
let loc = span_start ( cx, span) ;
667
731
let file_md = create_file ( cx, loc. file . name ) ;
668
732
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
679
743
680
744
fn create_fn_ty ( cx : @mut CrateContext , _fn_ty : ty:: t , inputs : ~[ ty:: t ] , output : ty:: t ,
681
745
span : span ) -> DICompositeType {
746
+ debug ! ( "create_fn_ty: %?" , ty:: get( _fn_ty) ) ;
747
+
682
748
let loc = span_start ( cx, span) ;
683
749
let file_md = create_file ( cx, loc. file . name ) ;
684
750
let ( vp, _, _) = voidptr ( cx) ;
@@ -694,6 +760,8 @@ fn create_fn_ty(cx: @mut CrateContext, _fn_ty: ty::t, inputs: ~[ty::t], output:
694
760
}
695
761
696
762
fn create_unimpl_ty ( cx : @mut CrateContext , t : ty:: t ) -> DIType {
763
+ debug ! ( "create_unimpl_ty: %?" , ty:: get( t) ) ;
764
+
697
765
let name = ty_to_str ( cx. tcx , t) ;
698
766
let md = do as_c_str ( fmt ! ( "NYI<%s>" , name) ) |name| { unsafe {
699
767
llvm:: LLVMDIBuilderCreateBasicType (
0 commit comments