Skip to content

Commit 4d8f2fd

Browse files
debuginfo: Many little formatting improvements.
1 parent 5f97a6e commit 4d8f2fd

File tree

1 file changed

+121
-56
lines changed

1 file changed

+121
-56
lines changed

src/librustc/middle/trans/debuginfo.rs

Lines changed: 121 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,17 @@ pub fn create_arg(bcx: block, arg: ast::arg, span: span) -> Option<DIVariable> {
211211
let ident = path.idents.last();
212212
let name: &str = cx.sess.str_of(*ident);
213213
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)
217225
// XXX need to pass in a real argument number
218226
}};
219227

@@ -290,16 +298,17 @@ pub fn create_function(fcx: fn_ctxt) -> DISubprogram {
290298
let ret_ty_md = if cx.sess.opts.extra_debuginfo {
291299
match ret_ty.node {
292300
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)
295302
}
296303
} else {
297304
ptr::null()
298305
};
299306

300307
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]))
303312
};
304313

305314
let fn_md =
@@ -308,13 +317,19 @@ pub fn create_function(fcx: fn_ctxt) -> DISubprogram {
308317
llvm::LLVMDIBuilderCreateFunction(
309318
DIB(cx),
310319
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,
314327
loc.line as c_uint,
315328
FlagPrototyped as c_uint,
316329
cx.sess.opts.optimize != session::No,
317-
fcx.llfn, ptr::null(), ptr::null())
330+
fcx.llfn,
331+
ptr::null(),
332+
ptr::null())
318333
}}};
319334

320335
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 {
463478
let (size, align) = size_and_align_of(cx, t);
464479
let ty_md = do as_c_str(name) |name| { unsafe {
465480
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)
468486
}};
469487

470488
// 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
478496
let (size, align) = size_and_align_of(cx, t);
479497
let name = ty_to_str(cx.tcx, t);
480498
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)
483505
}};
484506
return ptr_md;
485507
}
@@ -514,18 +536,18 @@ impl StructContext {
514536

515537
debug!("StructContext(%s)::add_member: %s, size=%u, align=%u, offset=%u",
516538
self.name, name, size, align, offset);
517-
539+
518540
let mem_t = do as_c_str(name) |name| { unsafe {
519541
llvm::LLVMDIBuilderCreateMemberType(
520-
self.builder,
542+
self.builder,
543+
self.file,
544+
name,
521545
self.file,
522-
name,
523-
self.file,
524546
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,
529551
ty)
530552
}};
531553
self.members.push(mem_t);
@@ -542,10 +564,10 @@ impl StructContext {
542564
// let repr = adt::represent_type(ccx, t);
543565

544566
// match *repr {
545-
// Univariant(*) =>
567+
// Univariant(*) =>
546568
// {
547569
// let size_with_alignment = self.get_total_size_with_alignment();
548-
570+
549571
// if st.size != size_with_alignment {
550572
// ccx.sess.bug("StructContext(%s)::verify_against_struct_or_tuple_type: invalid type size. Expected = %u, actual = %u",
551573
// st.size, size_with_alignment);
@@ -556,7 +578,7 @@ impl StructContext {
556578
// st.align, self.align);
557579
// }
558580
// },
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 %?",
560582
// self.name, t))
561583
// }
562584
//}
@@ -567,24 +589,24 @@ impl StructContext {
567589
let members_md = create_DIArray(self.builder, self.members);
568590

569591
// 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
571593
// 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();
573595

574596
let struct_md =
575597
do as_c_str(self.name) |name| { unsafe {
576598
llvm::LLVMDIBuilderCreateStructType(
577599
self.builder,
578-
self.file,
600+
self.file,
579601
name,
580-
self.file,
602+
self.file,
581603
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),
584606
0,
585607
ptr::null(),
586-
members_md,
587-
0,
608+
members_md,
609+
0,
588610
ptr::null())
589611
}};
590612
return struct_md;
@@ -613,8 +635,12 @@ fn voidptr(cx: @mut CrateContext) -> (DIDerivedType, uint, uint) {
613635
let size = sys::size_of::<ValueRef>();
614636
let align = sys::min_align_of::<ValueRef>();
615637
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)
618644
}};
619645
return (vp, size, align);
620646
}
@@ -673,8 +699,12 @@ fn create_fixed_vec(cx: @mut CrateContext, _vec_t: ty::t, elem_t: ty::t,
673699

674700
let subscripts = create_DIArray(DIB(cx), [subrange]);
675701
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)
678708
};
679709
}
680710

@@ -688,10 +718,21 @@ fn create_boxed_vec(cx: @mut CrateContext, vec_t: ty::t, elem_t: ty::t,
688718

689719
let mut vec_scx = StructContext::new(cx, ty_to_str(cx.tcx, vec_t), file_md, 0);
690720
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+
695736
let subrange = unsafe {
696737
llvm::LLVMDIBuilderGetOrCreateSubrange(DIB(cx), 0_i64, 0_i64)
697738
};
@@ -700,18 +741,32 @@ fn create_boxed_vec(cx: @mut CrateContext, vec_t: ty::t, elem_t: ty::t,
700741

701742
let subscripts = create_DIArray(DIB(cx), [subrange]);
702743
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)
705750
};
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+
708757
let vec_md = vec_scx.finalize();
709758

710759
let mut box_scx = StructContext::new(cx, fmt!("box<%s>", name), file_md, 0);
711760
let int_t = ty::mk_int();
712761
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+
715770
let (vp, vpsize, vpalign) = voidptr(cx);
716771
box_scx.add_member("tydesc", 0, vpsize, vpalign, vp);
717772
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
736791
let mut scx = StructContext::new(cx, ty_to_str(cx.tcx, vec_t), file_md, 0);
737792
let (_, ptr_size, ptr_align) = voidptr(cx);
738793
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);
741795
return scx.finalize();
742796
}
743797

@@ -754,7 +808,9 @@ fn create_fn_ty(cx: @mut CrateContext, _fn_ty: ty::t, inputs: ~[ty::t], output:
754808
let members = ~[output_ptr_md, vp] + inputs_vals;
755809

756810
return unsafe {
757-
llvm::LLVMDIBuilderCreateSubroutineType(DIB(cx), file_md,
811+
llvm::LLVMDIBuilderCreateSubroutineType(
812+
DIB(cx),
813+
file_md,
758814
create_DIArray(DIB(cx), members))
759815
};
760816
}
@@ -765,8 +821,11 @@ fn create_unimpl_ty(cx: @mut CrateContext, t: ty::t) -> DIType {
765821
let name = ty_to_str(cx.tcx, t);
766822
let md = do as_c_str(fmt!("NYI<%s>", name)) |name| { unsafe {
767823
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)
770829
}};
771830
return md;
772831
}
@@ -867,8 +926,10 @@ fn set_debug_location(cx: @mut CrateContext, scope: DIScope, line: uint, col: ui
867926
let elems = ~[C_i32(line as i32), C_i32(col as i32), scope, ptr::null()];
868927
unsafe {
869928
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+
872933
llvm::LLVMSetCurrentDebugLocation(cx.builder.B, dbg_loc);
873934
}
874935
}
@@ -887,14 +948,18 @@ fn roundup(x: uint, a: uint) -> uint {
887948

888949
/// Return codemap::Loc corresponding to the beginning of the span
889950
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)
891952
}
892953

893954
fn size_and_align_of(cx: @mut CrateContext, t: ty::t) -> (uint, uint) {
894955
let llty = type_of::type_of(cx, t);
895956
(machine::llsize_of_real(cx, llty), machine::llalign_of_min(cx, llty))
896957
}
897958

959+
fn bytes_to_bits(bytes: uint) -> c_ulonglong {
960+
(bytes * 8) as c_ulonglong
961+
}
962+
898963
#[inline]
899964
fn dbg_cx<'a>(cx: &'a mut CrateContext) -> &'a mut DebugContext {
900965
cx.dbg_cx.get_mut_ref()

0 commit comments

Comments
 (0)