Skip to content

Commit ffcd809

Browse files
committed
Debuginfo revamp
1 parent a6d9689 commit ffcd809

File tree

5 files changed

+200
-122
lines changed

5 files changed

+200
-122
lines changed

src/compiletest/runtest.rs

+9
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,15 @@ actual:\n\
227227
}
228228

229229
fn run_debuginfo_test(config: config, props: TestProps, testfile: &Path) {
230+
// do not optimize debuginfo tests
231+
let config = match config.rustcflags {
232+
Some(flags) => config {
233+
rustcflags: Some(str::replace(flags, ~"-O", ~"")),
234+
.. config
235+
},
236+
None => config
237+
};
238+
230239
// compile test file (it shoud have 'compile-flags:-g' in the header)
231240
let mut ProcRes = compile_test(config, props, testfile);
232241
if ProcRes.status != 0 {

src/librustc/middle/trans/debuginfo.rs

+109-110
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,31 @@ fn create_basic_type(cx: @CrateContext, t: ty::t, span: span)
360360
option::None => ()
361361
}
362362

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

365389
let fname = filename_from_span(cx, span);
366390
let file_node = create_file(cx, fname);
@@ -477,22 +501,42 @@ fn add_member(cx: @mut StructCtxt,
477501
cx.total_size += size * 8;
478502
}
479503

480-
fn create_record(cx: @CrateContext, t: ty::t, fields: ~[ast::ty_field],
504+
fn create_struct(cx: @CrateContext, t: ty::t, fields: ~[ty::field],
481505
span: span) -> @Metadata<TyDescMetadata> {
482506
let fname = filename_from_span(cx, span);
483507
let file_node = create_file(cx, fname);
508+
let scx = create_structure(file_node, @ty_to_str(cx.tcx, t),
509+
line_from_span(cx.sess.codemap, span) as int);
510+
for fields.each |field| {
511+
let field_t = field.mt.ty;
512+
let ty_md = create_ty(cx, field_t, span);
513+
let (size, align) = size_and_align_of(cx, field_t);
514+
add_member(scx, *cx.sess.str_of(field.ident),
515+
line_from_span(cx.sess.codemap, span) as int,
516+
size as int, align as int, ty_md.node);
517+
}
518+
let mdval = @Metadata {
519+
node: finish_structure(scx),
520+
data: TyDescMetadata {
521+
hash: ty::type_id(t)
522+
}
523+
};
524+
return mdval;
525+
}
526+
527+
fn create_tuple(cx: @CrateContext, t: ty::t, elements: ~[ty::t], span: span)
528+
-> @Metadata<TyDescMetadata> {
529+
let fname = filename_from_span(cx, span);
530+
let file_node = create_file(cx, fname);
484531
let scx = create_structure(file_node,
485532
cx.sess.str_of(
486533
((/*bad*/copy cx.dbg_cx).get().names)
487-
(~"rec")),
488-
line_from_span(cx.sess.codemap,
489-
span) as int);
490-
for fields.each |field| {
491-
let field_t = ty::get_field(cx.tcx, t, field.node.ident).mt.ty;
492-
let ty_md = create_ty(cx, field_t, field.node.mt.ty);
493-
let (size, align) = size_and_align_of(cx, field_t);
494-
add_member(scx, *cx.sess.str_of(field.node.ident),
495-
line_from_span(cx.sess.codemap, field.span) as int,
534+
(~"tuple")),
535+
line_from_span(cx.sess.codemap, span) as int);
536+
for elements.each |element| {
537+
let ty_md = create_ty(cx, *element, span);
538+
let (size, align) = size_and_align_of(cx, *element);
539+
add_member(scx, ~"", line_from_span(cx.sess.codemap, span) as int,
496540
size as int, align as int, ty_md.node);
497541
}
498542
let mdval = @Metadata {
@@ -569,11 +613,10 @@ fn create_composite_type(type_tag: int, name: &str, file: ValueRef,
569613
}
570614

571615
fn create_vec(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t,
572-
vec_ty_span: codemap::span, elem_ty: @ast::Ty)
573-
-> @Metadata<TyDescMetadata> {
616+
vec_ty_span: codemap::span) -> @Metadata<TyDescMetadata> {
574617
let fname = filename_from_span(cx, vec_ty_span);
575618
let file_node = create_file(cx, fname);
576-
let elem_ty_md = create_ty(cx, elem_t, elem_ty);
619+
let elem_ty_md = create_ty(cx, elem_t, vec_ty_span);
577620
let scx = create_structure(file_node,
578621
@/*bad*/ copy ty_to_str(cx.tcx, vec_t), 0);
579622
let size_t_type = create_basic_type(cx, ty::mk_uint(cx.tcx), vec_ty_span);
@@ -598,108 +641,60 @@ fn create_vec(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t,
598641
}
599642
}
600643

601-
fn create_ty(_cx: @CrateContext, _t: ty::t, _ty: @ast::Ty)
644+
fn create_ty(cx: @CrateContext, t: ty::t, span: span)
602645
-> @Metadata<TyDescMetadata> {
646+
debug!("create_ty: %?", ty::get(t));
603647
/*let cache = get_cache(cx);
604648
match cached_metadata::<@Metadata<TyDescMetadata>>(
605649
cache, tg, {|md| t == md.data.hash}) {
606650
option::Some(md) { return md; }
607651
option::None {}
608652
}*/
609653

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

705700
fn filename_from_span(cx: @CrateContext, sp: codemap::span) -> ~str {
@@ -738,7 +733,7 @@ pub fn create_local_var(bcx: block, local: @ast::local)
738733
};
739734
let loc = cx.sess.codemap.lookup_char_pos(local.span.lo);
740735
let ty = node_id_type(bcx, local.node.id);
741-
let tymd = create_ty(cx, ty, local.node.ty);
736+
let tymd = create_ty(cx, ty, local.node.ty.span);
742737
let filemd = create_file(cx, /*bad*/copy loc.file.name);
743738
let context = match bcx.parent {
744739
None => create_function(bcx.fcx).node,
@@ -788,8 +783,11 @@ pub fn create_arg(bcx: block, arg: ast::arg, sp: span)
788783
}
789784
790785
let loc = cx.sess.codemap.lookup_char_pos(sp.lo);
786+
if loc.file.name == ~"<intrinsic>" {
787+
return None;
788+
}
791789
let ty = node_id_type(bcx, arg.id);
792-
let tymd = create_ty(cx, ty, arg.ty);
790+
let tymd = create_ty(cx, ty, arg.ty.span);
793791
let filemd = create_file(cx, /*bad*/copy loc.file.name);
794792
let context = create_function(bcx.fcx);
795793
@@ -902,7 +900,8 @@ pub fn create_function(fcx: fn_ctxt) -> @Metadata<SubProgramMetadata> {
902900
let ty_node = if cx.sess.opts.extra_debuginfo {
903901
match ret_ty.node {
904902
ast::ty_nil => llnull(),
905-
_ => create_ty(cx, ty::node_id_to_type(cx.tcx, id), ret_ty).node
903+
_ => create_ty(cx, ty::node_id_to_type(cx.tcx, id),
904+
ret_ty.span).node
906905
}
907906
} else {
908907
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+
}

src/test/debug-info/struct.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// xfail-test
12-
// compile-flags:-g
13-
// debugger:break 32
11+
// compile-flags:-Z extra-debug-info
12+
// debugger:break 31
1413
// debugger:run
1514
// debugger:print pair
1615
// check:$1 = {
1716
// check:x = 1,
18-
// check:y = 2,
17+
// check:y = 2
1918
// check:}
2019
// debugger:print pair.x
2120
// check:$2 = 1
@@ -29,5 +28,5 @@ struct Pair {
2928

3029
fn main() {
3130
let pair = Pair { x: 1, y: 2 };
32-
debug!("x = %d, y = %d", pair.x, pair.y);
31+
let _z = ();
3332
}

0 commit comments

Comments
 (0)