Skip to content

Commit 7e6020d

Browse files
committed
auto merge of #5319 : brson/rust/debuginfo, r=brson
Continuing #5140 For the sake of getting this merged I've disabled debuginfo tests on mac (where running gdb needs root). Please feel free to follow up with further improvements.
2 parents 695e9fd + 3976e56 commit 7e6020d

File tree

6 files changed

+220
-102
lines changed

6 files changed

+220
-102
lines changed

mk/tests.mk

+4
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,10 @@ ifeq ($(CFG_GDB),)
386386
CTEST_DISABLE_debuginfo = "no gdb found"
387387
endif
388388

389+
ifeq ($(CFG_OSTYPE),apple-darwin)
390+
CTEST_DISABLE_debuginfo = "gdb on darwing needs root"
391+
endif
392+
389393
define DEF_CTEST_VARS
390394

391395
# All the per-stage build rules you might want to call from the

src/compiletest/runtest.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,15 @@ actual:\n\
225225
}
226226

227227
fn run_debuginfo_test(config: config, props: TestProps, testfile: &Path) {
228+
// do not optimize debuginfo tests
229+
let config = match config.rustcflags {
230+
Some(flags) => config {
231+
rustcflags: Some(str::replace(flags, ~"-O", ~"")),
232+
.. config
233+
},
234+
None => config
235+
};
236+
228237
// compile test file (it shoud have 'compile-flags:-g' in the header)
229238
let mut ProcRes = compile_test(config, props, testfile);
230239
if ProcRes.status != 0 {
@@ -267,8 +276,8 @@ fn run_debuginfo_test(config: config, props: TestProps, testfile: &Path) {
267276
}
268277
}
269278
if i != num_check_lines {
270-
fatal(fmt!("line not found in debugger output: %s",
271-
props.check_lines[i]));
279+
fatal_ProcRes(fmt!("line not found in debugger output: %s"
280+
props.check_lines[i]), ProcRes);
272281
}
273282
}
274283
}

src/librustc/middle/trans/debuginfo.rs

+126-86
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,31 @@ fn create_basic_type(cx: @CrateContext, t: ty::t, span: span)
356356
option::None => ()
357357
}
358358

359-
let (name, encoding) = (~"uint", DW_ATE_unsigned);
359+
let (name, encoding) = match ty::get(t).sty {
360+
ty::ty_nil | ty::ty_bot => (~"uint", DW_ATE_unsigned),
361+
ty::ty_bool => (~"bool", DW_ATE_boolean),
362+
ty::ty_int(int_ty) => match int_ty {
363+
ast::ty_i => (~"int", DW_ATE_signed),
364+
ast::ty_char => (~"char", DW_ATE_signed_char),
365+
ast::ty_i8 => (~"i8", DW_ATE_signed),
366+
ast::ty_i16 => (~"i16", DW_ATE_signed),
367+
ast::ty_i32 => (~"i32", DW_ATE_signed),
368+
ast::ty_i64 => (~"i64", DW_ATE_signed)
369+
},
370+
ty::ty_uint(uint_ty) => match uint_ty {
371+
ast::ty_u => (~"uint", DW_ATE_unsigned),
372+
ast::ty_u8 => (~"u8", DW_ATE_unsigned),
373+
ast::ty_u16 => (~"i16", DW_ATE_unsigned),
374+
ast::ty_u32 => (~"u32", DW_ATE_unsigned),
375+
ast::ty_u64 => (~"u64", DW_ATE_unsigned)
376+
},
377+
ty::ty_float(float_ty) => match float_ty {
378+
ast::ty_f => (~"float", DW_ATE_float),
379+
ast::ty_f32 => (~"f32", DW_ATE_float),
380+
ast::ty_f64 => (~"f64", DW_ATE_float)
381+
},
382+
_ => cx.sess.bug(~"debuginfo::create_basic_type - t is invalid type")
383+
};
360384

361385
let fname = filename_from_span(cx, span);
362386
let file_node = create_file(cx, fname);
@@ -473,6 +497,53 @@ fn add_member(cx: @mut StructCtxt,
473497
cx.total_size += size * 8;
474498
}
475499

500+
fn create_struct(cx: @CrateContext, t: ty::t, fields: ~[ty::field],
501+
span: span) -> @Metadata<TyDescMetadata> {
502+
let fname = filename_from_span(cx, span);
503+
let file_node = create_file(cx, fname);
504+
let scx = create_structure(file_node, @ty_to_str(cx.tcx, t),
505+
line_from_span(cx.sess.codemap, span) as int);
506+
for fields.each |field| {
507+
let field_t = field.mt.ty;
508+
let ty_md = create_ty(cx, field_t, span);
509+
let (size, align) = size_and_align_of(cx, field_t);
510+
add_member(scx, *cx.sess.str_of(field.ident),
511+
line_from_span(cx.sess.codemap, span) as int,
512+
size as int, align as int, ty_md.node);
513+
}
514+
let mdval = @Metadata {
515+
node: finish_structure(scx),
516+
data: TyDescMetadata {
517+
hash: ty::type_id(t)
518+
}
519+
};
520+
return mdval;
521+
}
522+
523+
fn create_tuple(cx: @CrateContext, t: ty::t, elements: ~[ty::t], span: span)
524+
-> @Metadata<TyDescMetadata> {
525+
let fname = filename_from_span(cx, span);
526+
let file_node = create_file(cx, fname);
527+
let scx = create_structure(file_node,
528+
cx.sess.str_of(
529+
((/*bad*/copy cx.dbg_cx).get().names)
530+
(~"tuple")),
531+
line_from_span(cx.sess.codemap, span) as int);
532+
for elements.each |element| {
533+
let ty_md = create_ty(cx, *element, span);
534+
let (size, align) = size_and_align_of(cx, *element);
535+
add_member(scx, ~"", line_from_span(cx.sess.codemap, span) as int,
536+
size as int, align as int, ty_md.node);
537+
}
538+
let mdval = @Metadata {
539+
node: finish_structure(scx),
540+
data: TyDescMetadata {
541+
hash: ty::type_id(t)
542+
}
543+
};
544+
return mdval;
545+
}
546+
476547
fn create_boxed_type(cx: @CrateContext, outer: ty::t, _inner: ty::t,
477548
span: span, boxed: @Metadata<TyDescMetadata>)
478549
-> @Metadata<TyDescMetadata> {
@@ -538,11 +609,10 @@ fn create_composite_type(type_tag: int, name: &str, file: ValueRef,
538609
}
539610

540611
fn create_vec(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t,
541-
vec_ty_span: codemap::span, elem_ty: @ast::Ty)
542-
-> @Metadata<TyDescMetadata> {
612+
vec_ty_span: codemap::span) -> @Metadata<TyDescMetadata> {
543613
let fname = filename_from_span(cx, vec_ty_span);
544614
let file_node = create_file(cx, fname);
545-
let elem_ty_md = create_ty(cx, elem_t, elem_ty);
615+
let elem_ty_md = create_ty(cx, elem_t, vec_ty_span);
546616
let scx = create_structure(file_node,
547617
@/*bad*/ copy ty_to_str(cx.tcx, vec_t), 0);
548618
let size_t_type = create_basic_type(cx, ty::mk_uint(cx.tcx), vec_ty_span);
@@ -567,94 +637,60 @@ fn create_vec(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t,
567637
}
568638
}
569639

570-
fn create_ty(_cx: @CrateContext, _t: ty::t, _ty: @ast::Ty)
640+
fn create_ty(cx: @CrateContext, t: ty::t, span: span)
571641
-> @Metadata<TyDescMetadata> {
642+
debug!("create_ty: %?", ty::get(t));
572643
/*let cache = get_cache(cx);
573644
match cached_metadata::<@Metadata<TyDescMetadata>>(
574645
cache, tg, {|md| t == md.data.hash}) {
575646
option::Some(md) { return md; }
576647
option::None {}
577648
}*/
578649

579-
/* FIXME (#2012): disabled this code as part of the patch that moves
580-
* recognition of named builtin types into resolve. I tried to fix
581-
* it, but it seems to already be broken -- it's only called when
582-
* --xg is given, and compiling with --xg fails on trivial programs.
583-
*
584-
* Generating an ast::ty from a ty::t seems like it should not be
585-
* needed. It is only done to track spans, but you will not get the
586-
* right spans anyway -- types tend to refer to stuff defined
587-
* elsewhere, not be self-contained.
588-
*/
589-
590-
fail!();
591-
/*
592-
fn t_to_ty(cx: CrateContext, t: ty::t, span: span) -> @ast::ty {
593-
let ty = match ty::get(t).struct {
594-
ty::ty_nil { ast::ty_nil }
595-
ty::ty_bot { ast::ty_bot }
596-
ty::ty_bool { ast::ty_bool }
597-
ty::ty_int(t) { ast::ty_int(t) }
598-
ty::ty_float(t) { ast::ty_float(t) }
599-
ty::ty_uint(t) { ast::ty_uint(t) }
600-
ty::ty_box(mt) { ast::ty_box({ty: t_to_ty(cx, mt.ty, span),
601-
mutbl: mt.mutbl}) }
602-
ty::ty_uniq(mt) { ast::ty_uniq({ty: t_to_ty(cx, mt.ty, span),
603-
mutbl: mt.mutbl}) }
604-
ty::ty_vec(mt) { ast::ty_vec({ty: t_to_ty(cx, mt.ty, span),
605-
mutbl: mt.mutbl}) }
606-
_ {
607-
cx.sess.span_bug(span, "t_to_ty: Can't handle this type");
608-
}
609-
};
610-
return @{node: ty, span: span};
611-
}
612-
613-
match ty.node {
614-
ast::ty_box(mt) {
615-
let inner_t = match ty::get(t).struct {
616-
ty::ty_box(boxed) { boxed.ty }
617-
_ { cx.sess.span_bug(ty.span, "t_to_ty was incoherent"); }
618-
};
619-
let md = create_ty(cx, inner_t, mt.ty);
620-
let box = create_boxed_type(cx, t, inner_t, ty.span, md);
621-
return create_pointer_type(cx, t, ty.span, box);
622-
}
623-
624-
ast::ty_uniq(mt) {
625-
let inner_t = match ty::get(t).struct {
626-
ty::ty_uniq(boxed) { boxed.ty }
627-
// Hoping we'll have a way to eliminate this check soon.
628-
_ { cx.sess.span_bug(ty.span, "t_to_ty was incoherent"); }
629-
};
630-
let md = create_ty(cx, inner_t, mt.ty);
631-
return create_pointer_type(cx, t, ty.span, md);
632-
}
633-
634-
ast::ty_infer {
635-
let inferred = t_to_ty(cx, t, ty.span);
636-
return create_ty(cx, t, inferred);
637-
}
638-
639-
ast::ty_vec(mt) {
640-
let inner_t = ty::sequence_element_type(cx.tcx, t);
641-
let inner_ast_t = t_to_ty(cx, inner_t, mt.ty.span);
642-
let v = create_vec(cx, t, inner_t, ty.span, inner_ast_t);
643-
return create_pointer_type(cx, t, ty.span, v);
644-
}
645-
646-
ast::ty_path(_, id) {
647-
match cx.tcx.def_map.get(id) {
648-
ast::def_prim_ty(pty) {
649-
return create_basic_type(cx, t, pty, ty.span);
650-
}
651-
_ {}
650+
let sty = copy ty::get(t).sty;
651+
match copy sty {
652+
ty::ty_nil | ty::ty_bot | ty::ty_bool | ty::ty_int(_) | ty::ty_uint(_)
653+
| ty::ty_float(_) => create_basic_type(cx, t, span),
654+
ty::ty_estr(_vstore) => {
655+
cx.sess.span_bug(span, ~"debuginfo for estr NYI")
656+
},
657+
ty::ty_enum(_did, _substs) => {
658+
cx.sess.span_bug(span, ~"debuginfo for enum NYI")
652659
}
653-
}
654-
655-
_ {}
656-
};
657-
*/
660+
ty::ty_box(_mt) => {
661+
cx.sess.span_bug(span, ~"debuginfo for box NYI")
662+
},
663+
ty::ty_uniq(_mt) => {
664+
cx.sess.span_bug(span, ~"debuginfo for uniq NYI")
665+
},
666+
ty::ty_evec(_mt, _vstore) => {
667+
cx.sess.span_bug(span, ~"debuginfo for evec NYI")
668+
},
669+
ty::ty_ptr(mt) => {
670+
let pointee = create_ty(cx, mt.ty, span);
671+
create_pointer_type(cx, t, span, pointee)
672+
},
673+
ty::ty_rptr(_region, _mt) => {
674+
cx.sess.span_bug(span, ~"debuginfo for rptr NYI")
675+
},
676+
ty::ty_bare_fn(_barefnty) => {
677+
cx.sess.span_bug(span, ~"debuginfo for bare_fn NYI")
678+
},
679+
ty::ty_closure(_closurety) => {
680+
cx.sess.span_bug(span, ~"debuginfo for closure NYI")
681+
},
682+
ty::ty_trait(_did, _substs, _vstore) => {
683+
cx.sess.span_bug(span, ~"debuginfo for trait NYI")
684+
},
685+
ty::ty_struct(did, substs) => {
686+
let fields = ty::struct_fields(cx.tcx, did, &substs);
687+
create_struct(cx, t, fields, span)
688+
},
689+
ty::ty_tup(elements) => {
690+
create_tuple(cx, t, elements, span)
691+
},
692+
_ => cx.sess.bug(~"debuginfo: unexpected type in create_ty")
693+
}
658694
}
659695

660696
fn filename_from_span(cx: @CrateContext, sp: codemap::span) -> ~str {
@@ -693,7 +729,7 @@ pub fn create_local_var(bcx: block, local: @ast::local)
693729
};
694730
let loc = cx.sess.codemap.lookup_char_pos(local.span.lo);
695731
let ty = node_id_type(bcx, local.node.id);
696-
let tymd = create_ty(cx, ty, local.node.ty);
732+
let tymd = create_ty(cx, ty, local.node.ty.span);
697733
let filemd = create_file(cx, /*bad*/copy loc.file.name);
698734
let context = match bcx.parent {
699735
None => create_function(bcx.fcx).node,
@@ -743,8 +779,11 @@ pub fn create_arg(bcx: block, arg: ast::arg, sp: span)
743779
}
744780
745781
let loc = cx.sess.codemap.lookup_char_pos(sp.lo);
782+
if loc.file.name == ~"<intrinsic>" {
783+
return None;
784+
}
746785
let ty = node_id_type(bcx, arg.id);
747-
let tymd = create_ty(cx, ty, arg.ty);
786+
let tymd = create_ty(cx, ty, arg.ty.span);
748787
let filemd = create_file(cx, /*bad*/copy loc.file.name);
749788
let context = create_function(bcx.fcx);
750789
@@ -856,7 +895,8 @@ pub fn create_function(fcx: fn_ctxt) -> @Metadata<SubProgramMetadata> {
856895
let ty_node = if cx.sess.opts.extra_debuginfo {
857896
match ret_ty.node {
858897
ast::ty_nil => llnull(),
859-
_ => create_ty(cx, ty::node_id_to_type(cx.tcx, id), ret_ty).node
898+
_ => create_ty(cx, ty::node_id_to_type(cx.tcx, id),
899+
ret_ty.span).node
860900
}
861901
} else {
862902
llnull()

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

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Caveats - gdb prints any 8-bit value (meaning rust i8 and u8 values)
12+
// as its numerical value along with its associated ASCII char, there
13+
// doesn't seem to be any way around this. Also, gdb doesn't know
14+
// about UTF-32 character encoding and will print a rust char as only
15+
// its numerical value.
16+
17+
// compile-flags:-Z extra-debug-info
18+
// debugger:break 67
19+
// debugger:run
20+
// debugger:print b
21+
// check:$1 = false
22+
// debugger:print i
23+
// check:$2 = -1
24+
// debugger:print c
25+
// check:$3 = 97
26+
// debugger:print i8
27+
// check:$4 = 68 'D'
28+
// debugger:print i16
29+
// check:$5 = -16
30+
// debugger:print i32
31+
// check:$6 = -32
32+
// debugger:print i64
33+
// check:$7 = -64
34+
// debugger:print u
35+
// check:$8 = 1
36+
// debugger:print u8
37+
// check:$9 = 100 'd'
38+
// debugger:print u16
39+
// check:$10 = 16
40+
// debugger:print u32
41+
// check:$11 = 32
42+
// debugger:print u64
43+
// check:$12 = 64
44+
// debugger:print f
45+
// check:$13 = 1.5
46+
// debugger:print f32
47+
// check:$14 = 2.5
48+
// debugger:print f64
49+
// check:$15 = 3.5
50+
51+
fn main() {
52+
let b: bool = false;
53+
let i: int = -1;
54+
let c: char = 'a';
55+
let i8: i8 = 68;
56+
let i16: i16 = -16;
57+
let i32: i32 = -32;
58+
let i64: i64 = -64;
59+
let u: uint = 1;
60+
let u8: u8 = 100;
61+
let u16: u16 = 16;
62+
let u32: u32 = 32;
63+
let u64: u64 = 64;
64+
let f: float = 1.5;
65+
let f32: f32 = 2.5;
66+
let f64: f64 = 3.5;
67+
let _z = ();
68+
}

0 commit comments

Comments
 (0)