Skip to content

Commit 65dd621

Browse files
committed
Fixed remaining issues to pass debug-test/* tests.
Made debugger scripts source line insensitive.
1 parent 62e86e0 commit 65dd621

File tree

9 files changed

+73
-28
lines changed

9 files changed

+73
-28
lines changed

src/librustc/lib/llvm.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,6 +2045,14 @@ pub mod llvm {
20452045
AlwaysPreserve: bool,
20462046
Flags: c_uint,
20472047
ArgNo: c_uint) -> DIVariable;
2048+
2049+
#[fast_ffi]
2050+
pub unsafe fn LLVMDIBuilderCreateArrayType(
2051+
Builder: DIBuilderRef,
2052+
Size: c_ulonglong,
2053+
AlignInBits: c_ulonglong,
2054+
Ty: DIType,
2055+
Subscripts: DIArray) -> DIType;
20482056

20492057
#[fast_ffi]
20502058
pub unsafe fn LLVMDIBuilderCreateVectorType(

src/librustc/middle/trans/debuginfo.rs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use util::ppaux::ty_to_str;
2424
use core::hashmap::HashMap;
2525
use core::libc;
2626
use core::libc::c_uint;
27+
use core::cmp;
2728
use core::ptr;
2829
use core::str::as_c_str;
2930
use core::sys;
@@ -204,8 +205,7 @@ fn create_block(bcx: block) -> DILexicalBlock {
204205

205206
fn size_and_align_of(cx: @CrateContext, t: ty::t) -> (uint, uint) {
206207
let llty = type_of::type_of(cx, t);
207-
(machine::llsize_of_real(cx, llty),
208-
machine::llalign_of_pref(cx, llty))
208+
(machine::llsize_of_real(cx, llty), machine::llalign_of_min(cx, llty))
209209
}
210210

211211
fn create_basic_type(cx: @CrateContext, t: ty::t, span: span) -> DIType{
@@ -277,46 +277,56 @@ struct StructContext {
277277

278278
impl StructContext {
279279
fn create(cx: @CrateContext, file: DIFile, name: ~str, line: uint) -> ~StructContext {
280+
debug!("StructContext::create: %s", name);
280281
let scx = ~StructContext {
281282
cx: cx,
282283
file: file,
283284
name: name,
284285
line: line,
285286
members: ~[],
286287
total_size: 0,
287-
align: 64 //XXX different alignment per arch?
288+
align: 1
288289
};
289290
return scx;
290291
}
291292

292293
fn add_member(&mut self, name: &str, line: uint, size: uint, align: uint, ty: DIType) {
294+
debug!("StructContext(%s)::add_member: %s, size=%u, align=%u", self.name, name, size, align);
295+
let offset = roundup(self.total_size, align);
293296
let mem_t = do as_c_str(name) |name| { unsafe {
294297
llvm::LLVMDIBuilderCreateMemberType(dbg_cx(self.cx).builder,
295298
ptr::null(), name, self.file, line as c_uint,
296-
size * 8 as u64, align * 8 as u64, self.total_size as u64,
299+
size * 8 as u64, align * 8 as u64, offset * 8 as u64,
297300
0, ty)
298301
}};
299-
// XXX What about member alignment???
300302
self.members.push(mem_t);
301-
self.total_size += size * 8;
303+
self.total_size = offset + size;
304+
// struct alignment is the max alignment of its' members
305+
self.align = cmp::max(self.align, align);
302306
}
303307

304308
fn finalize(&self) -> DICompositeType {
309+
debug!("StructContext(%s)::finalize: total_size=%u, align=%u", self.name, self.total_size, self.align);
305310
let dcx = dbg_cx(self.cx);
306311
let members_md = create_DIArray(dcx.builder, self.members);
307312

308313
let struct_md =
309314
do as_c_str(self.name) |name| { unsafe {
310315
llvm::LLVMDIBuilderCreateStructType(
311-
dcx.builder, ptr::null(), name,
316+
dcx.builder, self.file, name,
312317
self.file, self.line as c_uint,
313-
self.total_size as u64, self.align as u64, 0, ptr::null(),
318+
self.total_size * 8 as u64, self.align * 8 as u64, 0, ptr::null(),
314319
members_md, 0, ptr::null())
315320
}};
316321
return struct_md;
317322
}
318323
}
319324

325+
#[inline(always)]
326+
fn roundup(x: uint, a: uint) -> uint {
327+
((x + (a - 1)) / a) * a
328+
}
329+
320330
fn create_struct(cx: @CrateContext, t: ty::t, fields: ~[ty::field], span: span) -> DICompositeType {
321331
let loc = span_start(cx, span);
322332
let file_md = create_file(cx, loc.file.name);
@@ -390,12 +400,12 @@ fn create_fixed_vec(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t,
390400
let (size, align) = size_and_align_of(cx, elem_t);
391401

392402
let subrange = unsafe {
393-
llvm::LLVMDIBuilderGetOrCreateSubrange(dcx.builder, 0_i64, (len-1) as i64) };
403+
llvm::LLVMDIBuilderGetOrCreateSubrange(dcx.builder, 0_i64, len as i64) };
394404

395405
let subscripts = create_DIArray(dcx.builder, [subrange]);
396406
return unsafe {
397-
llvm::LLVMDIBuilderCreateVectorType(dcx.builder,
398-
size * len as u64, align as u64, elem_ty_md, subscripts)
407+
llvm::LLVMDIBuilderCreateArrayType(dcx.builder,
408+
size * len * 8 as u64, align * 8 as u64, elem_ty_md, subscripts)
399409
};
400410
}
401411

@@ -418,8 +428,8 @@ fn create_boxed_vec(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t,
418428
let name = fmt!("[%s]", ty_to_str(cx.tcx, elem_t));
419429

420430
let subscripts = create_DIArray(dcx.builder, [subrange]);
421-
let data_ptr = unsafe { llvm::LLVMDIBuilderCreateVectorType(dcx.builder,
422-
arr_size as u64, arr_align as u64, elem_ty_md, subscripts) };
431+
let data_ptr = unsafe { llvm::LLVMDIBuilderCreateArrayType(dcx.builder,
432+
arr_size * 8 as u64, arr_align * 8 as u64, elem_ty_md, subscripts) };
423433
vec_scx.add_member("data", 0, 0, // clang says the size should be 0
424434
sys::min_align_of::<u8>(), data_ptr);
425435
let vec_md = vec_scx.finalize();

src/rustllvm/RustWrapper.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,17 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateLocalVariable(
725725
unwrapDI<DIType>(Ty), AlwaysPreserve, Flags, ArgNo));
726726
}
727727

728+
extern "C" LLVMValueRef LLVMDIBuilderCreateArrayType(
729+
DIBuilderRef Builder,
730+
uint64_t Size,
731+
uint64_t AlignInBits,
732+
LLVMValueRef Ty,
733+
LLVMValueRef Subscripts) {
734+
return wrap(Builder->createArrayType(Size, AlignInBits,
735+
unwrapDI<DIType>(Ty),
736+
unwrapDI<DIArray>(Subscripts)));
737+
}
738+
728739
extern "C" LLVMValueRef LLVMDIBuilderCreateVectorType(
729740
DIBuilderRef Builder,
730741
uint64_t Size,

src/rustllvm/rustllvm.def.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ LLVMDIBuilderCreatePointerType
601601
LLVMDIBuilderCreateMemberType
602602
LLVMDIBuilderCreateStructType
603603
LLVMDIBuilderGetOrCreateSubrange
604+
LLVMDIBuilderCreateArrayType
604605
LLVMDIBuilderCreateVectorType
605606
LLVMDIBuilderCreateSubroutineType
606607
LLVMDIBuilderGetOrCreateArray

src/test/debug-info/basic-types.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// xfail-test
11+
// xfail-win32 Broken because of LLVM bug: http://llvm.org/bugs/show_bug.cgi?id=16249
1212

1313
// Caveats - gdb prints any 8-bit value (meaning rust i8 and u8 values)
1414
// as its numerical value along with its associated ASCII char, there
@@ -17,8 +17,9 @@
1717
// its numerical value.
1818

1919
// compile-flags:-Z extra-debug-info
20-
// debugger:break 67
20+
// debugger:break _zzz
2121
// debugger:run
22+
// debugger:finish
2223
// debugger:print b
2324
// check:$1 = false
2425
// debugger:print i
@@ -66,5 +67,7 @@ fn main() {
6667
let f: float = 1.5;
6768
let f32: f32 = 2.5;
6869
let f64: f64 = 3.5;
69-
let _z = ();
70+
_zzz();
7071
}
72+
73+
fn _zzz() {()}

src/test/debug-info/box.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// xfail-test
11+
// xfail-win32 Broken because of LLVM bug: http://llvm.org/bugs/show_bug.cgi?id=16249
1212

1313
// compile-flags:-Z extra-debug-info
1414
// debugger:set print pretty off
15-
// debugger:break 29
15+
// debugger:break _zzz
1616
// debugger:run
17+
// debugger:finish
1718
// debugger:print a->boxed
1819
// check:$1 = 1
1920
// debugger:print b->boxed
@@ -28,5 +29,7 @@ fn main() {
2829
let b = ~(2, 3.5);
2930
let c = @4;
3031
let d = @false;
31-
let _z = 0;
32+
_zzz();
3233
}
34+
35+
fn _zzz() {()}

src/test/debug-info/struct.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// xfail-test
11+
// xfail-win32 Broken because of LLVM bug: http://llvm.org/bugs/show_bug.cgi?id=16249
1212

1313
// compile-flags:-Z extra-debug-info
1414
// debugger:set print pretty off
15-
// debugger:break 29
15+
// debugger:break _zzz
1616
// debugger:run
17+
// debugger:finish
1718
// debugger:print pair
1819
// check:$1 = {x = 1, y = 2}
1920
// debugger:print pair.x
@@ -28,5 +29,7 @@ struct Pair {
2829

2930
fn main() {
3031
let pair = Pair { x: 1, y: 2 };
31-
let _z = ();
32+
_zzz();
3233
}
34+
35+
fn _zzz() {()}

src/test/debug-info/tuple.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// xfail-test
11+
// xfail-win32 Broken because of LLVM bug: http://llvm.org/bugs/show_bug.cgi?id=16249
1212

1313
// compile-flags:-Z extra-debug-info
1414
// debugger:set print pretty off
15-
// debugger:break 20
15+
// debugger:break _zzz
1616
// debugger:run
17+
// debugger:finish
1718
// debugger:print t
1819
// check:$1 = {4, 5.5, true}
1920

2021
fn main() {
2122
let t = (4, 5.5, true);
22-
let _z = ();
23+
_zzz();
2324
}
25+
26+
fn _zzz() {()}

src/test/debug-info/vec.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// xfail-test
11+
// xfail-win32 Broken because of LLVM bug: http://llvm.org/bugs/show_bug.cgi?id=16249
1212

1313
// compile-flags:-Z extra-debug-info
1414
// debugger:set print pretty off
15-
// debugger:break 29
15+
// debugger:break _zzz
1616
// debugger:run
17+
// debugger:finish
1718
// debugger:print a
1819
// check:$1 = {1, 2, 3}
1920
// debugger:print b.vec[0]
@@ -28,5 +29,7 @@ fn main() {
2829
let b = &[4, 5, 6];
2930
let c = @[7, 8, 9];
3031
let d = ~[10, 11, 12];
31-
let _z = 0;
32+
_zzz();
3233
}
34+
35+
fn _zzz() {()}

0 commit comments

Comments
 (0)