Skip to content

Commit 1373c4f

Browse files
committed
Properly create debug info for functions
We're currently using the actual function type as the return type when creating the debug info for a function, so we're actually creating debug info for a function that takes the same parameters, and returns the actual function type, which is completely wrong.
1 parent 3f50dca commit 1373c4f

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

src/librustc_trans/trans/debuginfo/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ pub fn scope_metadata(fcx: &FunctionContext,
920920
}
921921
}
922922

923-
fn diverging_type_metadata(cx: &CrateContext) -> DIType {
923+
pub fn diverging_type_metadata(cx: &CrateContext) -> DIType {
924924
unsafe {
925925
llvm::LLVMDIBuilderCreateBasicType(
926926
DIB(cx),

src/librustc_trans/trans/debuginfo/mod.rs

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ use self::utils::{DIB, span_start, assert_type_for_node_id, contains_nodebug_att
1818
create_DIArray, is_node_local_to_unit};
1919
use self::namespace::{namespace_for_item, NamespaceTreeNode};
2020
use self::type_names::compute_debuginfo_type_name;
21-
use self::metadata::{type_metadata, file_metadata, scope_metadata, TypeMap, compile_unit_metadata};
21+
use self::metadata::{type_metadata, diverging_type_metadata};
22+
use self::metadata::{file_metadata, scope_metadata, TypeMap, compile_unit_metadata};
2223
use self::source_loc::InternalDebugLocation;
2324

2425
use llvm;
@@ -30,7 +31,7 @@ use rustc::ast_map;
3031
use trans::common::{NodeIdAndSpan, CrateContext, FunctionContext, Block};
3132
use trans;
3233
use trans::monomorphize;
33-
use middle::ty::Ty;
34+
use middle::ty::{self, Ty};
3435
use session::config::{self, FullDebugInfo, LimitedDebugInfo, NoDebugInfo};
3536
use util::nodemap::{NodeMap, FnvHashMap, FnvHashSet};
3637

@@ -325,7 +326,6 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
325326
let function_type_metadata = unsafe {
326327
let fn_signature = get_function_signature(cx,
327328
fn_ast_id,
328-
&*fn_decl,
329329
param_substs,
330330
span);
331331
llvm::LLVMDIBuilderCreateSubroutineType(DIB(cx), file_metadata, fn_signature)
@@ -402,35 +402,42 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
402402

403403
fn get_function_signature<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
404404
fn_ast_id: ast::NodeId,
405-
fn_decl: &ast::FnDecl,
406405
param_substs: &Substs<'tcx>,
407406
error_reporting_span: Span) -> DIArray {
408407
if cx.sess().opts.debuginfo == LimitedDebugInfo {
409408
return create_DIArray(DIB(cx), &[]);
410409
}
411410

412-
let mut signature = Vec::with_capacity(fn_decl.inputs.len() + 1);
413-
414411
// Return type -- llvm::DIBuilder wants this at index 0
415412
assert_type_for_node_id(cx, fn_ast_id, error_reporting_span);
416-
let return_type = cx.tcx().node_id_to_type(fn_ast_id);
417-
let return_type = monomorphize::apply_param_substs(cx.tcx(),
418-
param_substs,
419-
&return_type);
420-
if return_type.is_nil() {
421-
signature.push(ptr::null_mut())
422-
} else {
423-
signature.push(type_metadata(cx, return_type, codemap::DUMMY_SP));
424-
}
413+
let fn_type = cx.tcx().node_id_to_type(fn_ast_id);
414+
415+
let sig = match fn_type.sty {
416+
ty::TyBareFn(_, ref barefnty) => {
417+
cx.tcx().erase_late_bound_regions(&barefnty.sig)
418+
}
419+
ty::TyClosure(def_id, substs) => {
420+
cx.tcx().erase_late_bound_regions(&cx.tcx().closure_type(def_id, substs).sig)
421+
}
422+
423+
_ => cx.sess().bug("get_function_metdata: Expected a function type!")
424+
};
425+
let sig = monomorphize::apply_param_substs(cx.tcx(), param_substs, &sig);
426+
427+
let mut signature = Vec::with_capacity(sig.inputs.len() + 1);
428+
429+
// Return type -- llvm::DIBuilder wants this at index 0
430+
signature.push(match sig.output {
431+
ty::FnConverging(ret_ty) => match ret_ty.sty {
432+
ty::TyTuple(ref tys) if tys.is_empty() => ptr::null_mut(),
433+
_ => type_metadata(cx, ret_ty, codemap::DUMMY_SP)
434+
},
435+
ty::FnDiverging => diverging_type_metadata(cx)
436+
});
425437

426438
// Arguments types
427-
for arg in &fn_decl.inputs {
428-
assert_type_for_node_id(cx, arg.pat.id, arg.pat.span);
429-
let arg_type = cx.tcx().node_id_to_type(arg.pat.id);
430-
let arg_type = monomorphize::apply_param_substs(cx.tcx(),
431-
param_substs,
432-
&arg_type);
433-
signature.push(type_metadata(cx, arg_type, codemap::DUMMY_SP));
439+
for &argument_type in &sig.inputs {
440+
signature.push(type_metadata(cx, argument_type, codemap::DUMMY_SP));
434441
}
435442

436443
return create_DIArray(DIB(cx), &signature[..]);

src/test/debuginfo/basic-types-metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
// gdb-command:whatis f64
4444
// gdb-check:type = f64
4545
// gdb-command:info functions _yyy
46-
// gdb-check:[...]![...]_yyy([...])([...]);
46+
// gdb-check:[...]![...]_yyy([...]);
4747
// gdb-command:continue
4848

4949
#![allow(unused_variables)]

0 commit comments

Comments
 (0)