@@ -211,9 +211,17 @@ pub fn create_arg(bcx: block, arg: ast::arg, span: span) -> Option<DIVariable> {
211
211
let ident = path. idents . last ( ) ;
212
212
let name: & str = cx. sess . str_of ( * ident) ;
213
213
let mdnode = do as_c_str ( name) |name| { unsafe {
214
- llvm:: LLVMDIBuilderCreateLocalVariable ( DIB ( cx) ,
215
- ArgVariableTag as u32 , context, name,
216
- filemd, loc. line as c_uint , tymd, false , 0 , 0 )
214
+ llvm:: LLVMDIBuilderCreateLocalVariable (
215
+ DIB ( cx) ,
216
+ ArgVariableTag as u32 ,
217
+ context,
218
+ name,
219
+ filemd,
220
+ loc. line as c_uint ,
221
+ tymd,
222
+ false ,
223
+ 0 ,
224
+ 0 )
217
225
// XXX need to pass in a real argument number
218
226
} } ;
219
227
@@ -290,16 +298,17 @@ pub fn create_function(fcx: fn_ctxt) -> DISubprogram {
290
298
let ret_ty_md = if cx. sess . opts . extra_debuginfo {
291
299
match ret_ty. node {
292
300
ast:: ty_nil => ptr:: null ( ) ,
293
- _ => create_ty ( cx, ty:: node_id_to_type ( cx. tcx , id) ,
294
- ret_ty. span )
301
+ _ => create_ty ( cx, ty:: node_id_to_type ( cx. tcx , id) , ret_ty. span )
295
302
}
296
303
} else {
297
304
ptr:: null ( )
298
305
} ;
299
306
300
307
let fn_ty = unsafe {
301
- llvm:: LLVMDIBuilderCreateSubroutineType ( DIB ( cx) ,
302
- file_md, create_DIArray ( DIB ( cx) , [ ret_ty_md] ) )
308
+ llvm:: LLVMDIBuilderCreateSubroutineType (
309
+ DIB ( cx) ,
310
+ file_md,
311
+ create_DIArray ( DIB ( cx) , [ ret_ty_md] ) )
303
312
} ;
304
313
305
314
let fn_md =
@@ -308,13 +317,19 @@ pub fn create_function(fcx: fn_ctxt) -> DISubprogram {
308
317
llvm:: LLVMDIBuilderCreateFunction (
309
318
DIB ( cx) ,
310
319
file_md,
311
- name, linkage,
312
- file_md, loc. line as c_uint ,
313
- fn_ty, false , true ,
320
+ name,
321
+ linkage,
322
+ file_md,
323
+ loc. line as c_uint ,
324
+ fn_ty,
325
+ false ,
326
+ true ,
314
327
loc. line as c_uint ,
315
328
FlagPrototyped as c_uint ,
316
329
cx. sess . opts . optimize != session:: No ,
317
- fcx. llfn , ptr:: null ( ) , ptr:: null ( ) )
330
+ fcx. llfn ,
331
+ ptr:: null ( ) ,
332
+ ptr:: null ( ) )
318
333
} } } ;
319
334
320
335
dbg_cx ( cx) . created_functions . insert ( id, fn_md) ;
@@ -463,8 +478,11 @@ fn create_basic_type(cx: @mut CrateContext, t: ty::t, _span: span) -> DIType {
463
478
let ( size, align) = size_and_align_of ( cx, t) ;
464
479
let ty_md = do as_c_str ( name) |name| { unsafe {
465
480
llvm:: LLVMDIBuilderCreateBasicType (
466
- DIB ( cx) , name,
467
- size * 8 as u64 , align * 8 as u64 , encoding as c_uint )
481
+ DIB ( cx) ,
482
+ name,
483
+ bytes_to_bits ( size) ,
484
+ bytes_to_bits ( align) ,
485
+ encoding as c_uint )
468
486
} } ;
469
487
470
488
// One could think that this call is not necessary, as the create_ty() function will insert the
@@ -478,8 +496,12 @@ fn create_pointer_type(cx: @mut CrateContext, t: ty::t, _span: span, pointee: DI
478
496
let ( size, align) = size_and_align_of ( cx, t) ;
479
497
let name = ty_to_str ( cx. tcx , t) ;
480
498
let ptr_md = do as_c_str ( name) |name| { unsafe {
481
- llvm:: LLVMDIBuilderCreatePointerType ( DIB ( cx) ,
482
- pointee, size * 8 as u64 , align * 8 as u64 , name)
499
+ llvm:: LLVMDIBuilderCreatePointerType (
500
+ DIB ( cx) ,
501
+ pointee,
502
+ bytes_to_bits ( size) ,
503
+ bytes_to_bits ( align) ,
504
+ name)
483
505
} } ;
484
506
return ptr_md;
485
507
}
@@ -514,18 +536,18 @@ impl StructContext {
514
536
515
537
debug ! ( "StructContext(%s)::add_member: %s, size=%u, align=%u, offset=%u" ,
516
538
self . name, name, size, align, offset) ;
517
-
539
+
518
540
let mem_t = do as_c_str ( name) |name| { unsafe {
519
541
llvm:: LLVMDIBuilderCreateMemberType (
520
- self . builder ,
542
+ self . builder ,
543
+ self . file ,
544
+ name,
521
545
self . file ,
522
- name,
523
- self . file ,
524
546
line as c_uint ,
525
- ( size * 8 ) as c_ulonglong ,
526
- ( align * 8 ) as c_ulonglong ,
527
- ( offset * 8 ) as c_ulonglong ,
528
- 0 ,
547
+ bytes_to_bits ( size) ,
548
+ bytes_to_bits ( align) ,
549
+ bytes_to_bits ( offset) ,
550
+ 0 ,
529
551
ty)
530
552
} } ;
531
553
self . members . push ( mem_t) ;
@@ -542,10 +564,10 @@ impl StructContext {
542
564
// let repr = adt::represent_type(ccx, t);
543
565
544
566
// match *repr {
545
- // Univariant(*) =>
567
+ // Univariant(*) =>
546
568
// {
547
569
// let size_with_alignment = self.get_total_size_with_alignment();
548
-
570
+
549
571
// if st.size != size_with_alignment {
550
572
// ccx.sess.bug("StructContext(%s)::verify_against_struct_or_tuple_type: invalid type size. Expected = %u, actual = %u",
551
573
// st.size, size_with_alignment);
@@ -556,7 +578,7 @@ impl StructContext {
556
578
// st.align, self.align);
557
579
// }
558
580
// },
559
- // _ => ccx.sess.bug(fmt!("StructContext(%s)::verify_against_struct_or_tuple_type: called with invalid type %?",
581
+ // _ => ccx.sess.bug(fmt!("StructContext(%s)::verify_against_struct_or_tuple_type: called with invalid type %?",
560
582
// self.name, t))
561
583
// }
562
584
//}
@@ -567,24 +589,24 @@ impl StructContext {
567
589
let members_md = create_DIArray ( self . builder , self . members ) ;
568
590
569
591
// 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
592
+ // Otherwise gdb has trouble reading the struct correctly when it is embedded into another
571
593
// data structure. This is also the value `sizeof` in C would give.
572
- let total_size_with_alignment = self . get_total_size_with_alignment ( ) ;
594
+ let actual_total_size = self . get_total_size_with_alignment ( ) ;
573
595
574
596
let struct_md =
575
597
do as_c_str ( self . name ) |name| { unsafe {
576
598
llvm:: LLVMDIBuilderCreateStructType (
577
599
self . builder ,
578
- self . file ,
600
+ self . file ,
579
601
name,
580
- self . file ,
602
+ self . file ,
581
603
self . line as c_uint ,
582
- ( total_size_with_alignment * 8 ) as c_ulonglong ,
583
- ( self . align * 8 ) as c_ulonglong ,
604
+ bytes_to_bits ( actual_total_size ) ,
605
+ bytes_to_bits ( self . align ) ,
584
606
0 ,
585
607
ptr:: null ( ) ,
586
- members_md,
587
- 0 ,
608
+ members_md,
609
+ 0 ,
588
610
ptr:: null ( ) )
589
611
} } ;
590
612
return struct_md;
@@ -613,8 +635,12 @@ fn voidptr(cx: @mut CrateContext) -> (DIDerivedType, uint, uint) {
613
635
let size = sys:: size_of :: < ValueRef > ( ) ;
614
636
let align = sys:: min_align_of :: < ValueRef > ( ) ;
615
637
let vp = do as_c_str ( "*void" ) |name| { unsafe {
616
- llvm:: LLVMDIBuilderCreatePointerType ( DIB ( cx) , ptr:: null ( ) ,
617
- size* 8 as u64 , align* 8 as u64 , name)
638
+ llvm:: LLVMDIBuilderCreatePointerType (
639
+ DIB ( cx) ,
640
+ ptr:: null ( ) ,
641
+ bytes_to_bits ( size) ,
642
+ bytes_to_bits ( align) ,
643
+ name)
618
644
} } ;
619
645
return ( vp, size, align) ;
620
646
}
@@ -673,8 +699,12 @@ fn create_fixed_vec(cx: @mut CrateContext, _vec_t: ty::t, elem_t: ty::t,
673
699
674
700
let subscripts = create_DIArray ( DIB ( cx) , [ subrange] ) ;
675
701
return unsafe {
676
- llvm:: LLVMDIBuilderCreateArrayType ( DIB ( cx) ,
677
- size * len * 8 as u64 , align * 8 as u64 , elem_ty_md, subscripts)
702
+ llvm:: LLVMDIBuilderCreateArrayType (
703
+ DIB ( cx) ,
704
+ bytes_to_bits ( size * len) ,
705
+ bytes_to_bits ( align) ,
706
+ elem_ty_md,
707
+ subscripts)
678
708
} ;
679
709
}
680
710
@@ -688,10 +718,21 @@ fn create_boxed_vec(cx: @mut CrateContext, vec_t: ty::t, elem_t: ty::t,
688
718
689
719
let mut vec_scx = StructContext :: new ( cx, ty_to_str ( cx. tcx , vec_t) , file_md, 0 ) ;
690
720
let size_t_type = create_basic_type ( cx, ty:: mk_uint ( ) , vec_ty_span) ;
691
- vec_scx. add_member ( "fill" , 0 , sys:: size_of :: < libc:: size_t > ( ) ,
692
- sys:: min_align_of :: < libc:: size_t > ( ) , size_t_type) ;
693
- vec_scx. add_member ( "alloc" , 0 , sys:: size_of :: < libc:: size_t > ( ) ,
694
- sys:: min_align_of :: < libc:: size_t > ( ) , size_t_type) ;
721
+
722
+ vec_scx. add_member (
723
+ "fill" ,
724
+ 0 ,
725
+ sys:: size_of :: < libc:: size_t > ( ) ,
726
+ sys:: min_align_of :: < libc:: size_t > ( ) ,
727
+ size_t_type) ;
728
+
729
+ vec_scx. add_member (
730
+ "alloc" ,
731
+ 0 ,
732
+ sys:: size_of :: < libc:: size_t > ( ) ,
733
+ sys:: min_align_of :: < libc:: size_t > ( ) ,
734
+ size_t_type) ;
735
+
695
736
let subrange = unsafe {
696
737
llvm:: LLVMDIBuilderGetOrCreateSubrange ( DIB ( cx) , 0_i64 , 0_i64 )
697
738
} ;
@@ -700,18 +741,32 @@ fn create_boxed_vec(cx: @mut CrateContext, vec_t: ty::t, elem_t: ty::t,
700
741
701
742
let subscripts = create_DIArray ( DIB ( cx) , [ subrange] ) ;
702
743
let data_ptr = unsafe {
703
- llvm:: LLVMDIBuilderCreateArrayType ( DIB ( cx) ,
704
- arr_size * 8 as u64 , arr_align * 8 as u64 , elem_ty_md, subscripts)
744
+ llvm:: LLVMDIBuilderCreateArrayType (
745
+ DIB ( cx) ,
746
+ bytes_to_bits ( arr_size) ,
747
+ bytes_to_bits ( arr_align) ,
748
+ elem_ty_md,
749
+ subscripts)
705
750
} ;
706
- vec_scx. add_member ( "data" , 0 , 0 , // clang says the size should be 0
707
- sys:: min_align_of :: < u8 > ( ) , data_ptr) ;
751
+ vec_scx. add_member (
752
+ "data" ,
753
+ 0 ,
754
+ 0 , // clang says the size should be 0
755
+ sys:: min_align_of :: < u8 > ( ) , data_ptr) ;
756
+
708
757
let vec_md = vec_scx. finalize ( ) ;
709
758
710
759
let mut box_scx = StructContext :: new ( cx, fmt ! ( "box<%s>" , name) , file_md, 0 ) ;
711
760
let int_t = ty:: mk_int ( ) ;
712
761
let refcount_type = create_basic_type ( cx, int_t, vec_ty_span) ;
713
- box_scx. add_member ( "refcnt" , 0 , sys:: size_of :: < uint > ( ) ,
714
- sys:: min_align_of :: < uint > ( ) , refcount_type) ;
762
+
763
+ box_scx. add_member (
764
+ "refcnt" ,
765
+ 0 ,
766
+ sys:: size_of :: < uint > ( ) ,
767
+ sys:: min_align_of :: < uint > ( ) ,
768
+ refcount_type) ;
769
+
715
770
let ( vp, vpsize, vpalign) = voidptr ( cx) ;
716
771
box_scx. add_member ( "tydesc" , 0 , vpsize, vpalign, vp) ;
717
772
box_scx. add_member ( "prev" , 0 , vpsize, vpalign, vp) ;
@@ -736,8 +791,7 @@ fn create_vec_slice(cx: @mut CrateContext, vec_t: ty::t, elem_t: ty::t, span: sp
736
791
let mut scx = StructContext :: new ( cx, ty_to_str ( cx. tcx , vec_t) , file_md, 0 ) ;
737
792
let ( _, ptr_size, ptr_align) = voidptr ( cx) ;
738
793
scx. add_member ( "vec" , 0 , ptr_size, ptr_align, elem_ptr) ;
739
- scx. add_member ( "length" , 0 , sys:: size_of :: < uint > ( ) ,
740
- sys:: min_align_of :: < uint > ( ) , uint_type) ;
794
+ scx. add_member ( "length" , 0 , sys:: size_of :: < uint > ( ) , sys:: min_align_of :: < uint > ( ) , uint_type) ;
741
795
return scx. finalize ( ) ;
742
796
}
743
797
@@ -754,7 +808,9 @@ fn create_fn_ty(cx: @mut CrateContext, _fn_ty: ty::t, inputs: ~[ty::t], output:
754
808
let members = ~[ output_ptr_md, vp] + inputs_vals;
755
809
756
810
return unsafe {
757
- llvm:: LLVMDIBuilderCreateSubroutineType ( DIB ( cx) , file_md,
811
+ llvm:: LLVMDIBuilderCreateSubroutineType (
812
+ DIB ( cx) ,
813
+ file_md,
758
814
create_DIArray ( DIB ( cx) , members) )
759
815
} ;
760
816
}
@@ -765,8 +821,11 @@ fn create_unimpl_ty(cx: @mut CrateContext, t: ty::t) -> DIType {
765
821
let name = ty_to_str ( cx. tcx , t) ;
766
822
let md = do as_c_str ( fmt ! ( "NYI<%s>" , name) ) |name| { unsafe {
767
823
llvm:: LLVMDIBuilderCreateBasicType (
768
- DIB ( cx) , name,
769
- 0_u64 , 8_u64 , DW_ATE_unsigned as c_uint )
824
+ DIB ( cx) ,
825
+ name,
826
+ 0_u64 ,
827
+ 8_u64 ,
828
+ DW_ATE_unsigned as c_uint )
770
829
} } ;
771
830
return md;
772
831
}
@@ -867,8 +926,10 @@ fn set_debug_location(cx: @mut CrateContext, scope: DIScope, line: uint, col: ui
867
926
let elems = ~[ C_i32 ( line as i32 ) , C_i32 ( col as i32 ) , scope, ptr:: null ( ) ] ;
868
927
unsafe {
869
928
let dbg_loc = llvm:: LLVMMDNodeInContext (
870
- dbg_cx ( cx) . llcontext , vec:: raw:: to_ptr ( elems) ,
871
- elems. len ( ) as libc:: c_uint ) ;
929
+ dbg_cx ( cx) . llcontext ,
930
+ vec:: raw:: to_ptr ( elems) ,
931
+ elems. len ( ) as c_uint ) ;
932
+
872
933
llvm:: LLVMSetCurrentDebugLocation ( cx. builder . B , dbg_loc) ;
873
934
}
874
935
}
@@ -887,14 +948,18 @@ fn roundup(x: uint, a: uint) -> uint {
887
948
888
949
/// Return codemap::Loc corresponding to the beginning of the span
889
950
fn span_start ( cx : & CrateContext , span : span ) -> codemap:: Loc {
890
- return cx. sess . codemap . lookup_char_pos ( span. lo ) ;
951
+ cx. sess . codemap . lookup_char_pos ( span. lo )
891
952
}
892
953
893
954
fn size_and_align_of ( cx : @mut CrateContext , t : ty:: t ) -> ( uint , uint ) {
894
955
let llty = type_of:: type_of ( cx, t) ;
895
956
( machine:: llsize_of_real ( cx, llty) , machine:: llalign_of_min ( cx, llty) )
896
957
}
897
958
959
+ fn bytes_to_bits ( bytes : uint ) -> c_ulonglong {
960
+ ( bytes * 8 ) as c_ulonglong
961
+ }
962
+
898
963
#[ inline]
899
964
fn dbg_cx < ' a > ( cx : & ' a mut CrateContext ) -> & ' a mut DebugContext {
900
965
cx. dbg_cx . get_mut_ref ( )
0 commit comments