Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug info #7134

Closed
wants to merge 11 commits into from
2 changes: 1 addition & 1 deletion src/compiletest/procsrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn target_env(lib_path: &str, prog: &str) -> ~[(~str,~str)] {
assert!(prog.ends_with(".exe"));
let aux_path = prog.slice(0u, prog.len() - 4u).to_owned() + ".libaux";

env = do vec::map(env) |pair| {
env = do env.map() |pair| {
let (k,v) = copy *pair;
if k == ~"PATH" { (~"PATH", v + ";" + lib_path + ";" + aux_path) }
else { (k,v) }
Expand Down
205 changes: 203 additions & 2 deletions src/librustc/lib/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,50 @@ pub type SectionIteratorRef = *SectionIterator_opaque;
pub enum Pass_opaque {}
pub type PassRef = *Pass_opaque;

pub mod debuginfo {
use super::{ValueRef};

pub enum DIBuilder_opaque {}
pub type DIBuilderRef = *DIBuilder_opaque;

pub type DIDescriptor = ValueRef;
pub type DIScope = DIDescriptor;
pub type DILocation = DIDescriptor;
pub type DIFile = DIScope;
pub type DILexicalBlock = DIScope;
pub type DISubprogram = DIScope;
pub type DIType = DIDescriptor;
pub type DIBasicType = DIType;
pub type DIDerivedType = DIType;
pub type DICompositeType = DIDerivedType;
pub type DIVariable = DIDescriptor;
pub type DIArray = DIDescriptor;
pub type DISubrange = DIDescriptor;

pub enum DIDescriptorFlags {
FlagPrivate = 1 << 0,
FlagProtected = 1 << 1,
FlagFwdDecl = 1 << 2,
FlagAppleBlock = 1 << 3,
FlagBlockByrefStruct = 1 << 4,
FlagVirtual = 1 << 5,
FlagArtificial = 1 << 6,
FlagExplicit = 1 << 7,
FlagPrototyped = 1 << 8,
FlagObjcClassComplete = 1 << 9,
FlagObjectPointer = 1 << 10,
FlagVector = 1 << 11,
FlagStaticMember = 1 << 12
}
}

pub mod llvm {
use super::{AtomicBinOp, AtomicOrdering, BasicBlockRef, ExecutionEngineRef};
use super::{Bool, BuilderRef, ContextRef, MemoryBufferRef, ModuleRef};
use super::{ObjectFileRef, Opcode, PassManagerRef, PassManagerBuilderRef};
use super::{SectionIteratorRef, TargetDataRef, TypeKind, TypeRef, UseRef};
use super::{ValueRef,PassRef};

use super::{ValueRef, PassRef};
use super::debuginfo::*;
use core::libc::{c_char, c_int, c_longlong, c_ushort, c_uint, c_ulonglong};

#[link_args = "-Lrustllvm -lrustllvm"]
Expand Down Expand Up @@ -929,6 +966,12 @@ pub mod llvm {
#[fast_ffi]
pub unsafe fn LLVMDeleteBasicBlock(BB: BasicBlockRef);

#[fast_ffi]
pub unsafe fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef, MoveAfter: BasicBlockRef);

#[fast_ffi]
pub unsafe fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef, MoveBefore: BasicBlockRef);

/* Operations on instructions */
#[fast_ffi]
pub unsafe fn LLVMGetInstructionParent(Inst: ValueRef)
Expand Down Expand Up @@ -1885,6 +1928,164 @@ pub mod llvm {
AlignStack: Bool, Dialect: c_uint)
-> ValueRef;


#[fast_ffi]
pub unsafe fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;

#[fast_ffi]
pub unsafe fn LLVMDIBuilderDispose(Builder: DIBuilderRef);

#[fast_ffi]
pub unsafe fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);

#[fast_ffi]
pub unsafe fn LLVMDIBuilderCreateCompileUnit(
Builder: DIBuilderRef,
Lang: c_uint,
File: *c_char,
Dir: *c_char,
Producer: *c_char,
isOptimized: bool,
Flags: *c_char,
RuntimeVer: c_uint,
SplitName: *c_char);

#[fast_ffi]
pub unsafe fn LLVMDIBuilderCreateFile(
Builder: DIBuilderRef,
Filename: *c_char,
Directory: *c_char) -> DIFile;

#[fast_ffi]
pub unsafe fn LLVMDIBuilderCreateSubroutineType(
Builder: DIBuilderRef,
File: DIFile,
ParameterTypes: DIArray) -> DICompositeType;

#[fast_ffi]
pub unsafe fn LLVMDIBuilderCreateFunction(
Builder: DIBuilderRef,
Scope: DIDescriptor,
Name: *c_char,
LinkageName: *c_char,
File: DIFile,
LineNo: c_uint,
Ty: DIType,
isLocalToUnit: bool,
isDefinition: bool,
ScopeLine: c_uint,
Flags: c_uint,
isOptimized: bool,
Fn: ValueRef,
TParam: ValueRef,
Decl: ValueRef) -> DISubprogram;

#[fast_ffi]
pub unsafe fn LLVMDIBuilderCreateBasicType(
Builder: DIBuilderRef,
Name: *c_char,
SizeInBits: c_ulonglong,
AlignInBits: c_ulonglong,
Encoding: c_uint) -> DIBasicType;

#[fast_ffi]
pub unsafe fn LLVMDIBuilderCreatePointerType(
Builder: DIBuilderRef,
PointeeTy: DIType,
SizeInBits: c_ulonglong,
AlignInBits: c_ulonglong,
Name: *c_char) -> DIDerivedType;

#[fast_ffi]
pub unsafe fn LLVMDIBuilderCreateStructType(
Builder: DIBuilderRef,
Scope: DIDescriptor,
Name: *c_char,
File: DIFile,
LineNumber: c_uint,
SizeInBits: c_ulonglong,
AlignInBits: c_ulonglong,
Flags: c_uint,
DerivedFrom: DIType,
Elements: DIArray,
RunTimeLang: c_uint,
VTableHolder: ValueRef) -> DICompositeType;

#[fast_ffi]
pub unsafe fn LLVMDIBuilderCreateMemberType(
Builder: DIBuilderRef,
Scope: DIDescriptor,
Name: *c_char,
File: DIFile,
LineNo: c_uint,
SizeInBits: c_ulonglong,
AlignInBits: c_ulonglong,
OffsetInBits: c_ulonglong,
Flags: c_uint,
Ty: DIType) -> DIDerivedType;

#[fast_ffi]
pub unsafe fn LLVMDIBuilderCreateLexicalBlock(
Builder: DIBuilderRef,
Scope: DIDescriptor,
File: DIFile,
Line: c_uint,
Col: c_uint) -> DILexicalBlock;

#[fast_ffi]
pub unsafe fn LLVMDIBuilderCreateLocalVariable(
Builder: DIBuilderRef,
Tag: c_uint,
Scope: DIDescriptor,
Name: *c_char,
File: DIFile,
LineNo: c_uint,
Ty: DIType,
AlwaysPreserve: bool,
Flags: c_uint,
ArgNo: c_uint) -> DIVariable;

#[fast_ffi]
pub unsafe fn LLVMDIBuilderCreateArrayType(
Builder: DIBuilderRef,
Size: c_ulonglong,
AlignInBits: c_ulonglong,
Ty: DIType,
Subscripts: DIArray) -> DIType;

#[fast_ffi]
pub unsafe fn LLVMDIBuilderCreateVectorType(
Builder: DIBuilderRef,
Size: c_ulonglong,
AlignInBits: c_ulonglong,
Ty: DIType,
Subscripts: DIArray) -> DIType;

#[fast_ffi]
pub unsafe fn LLVMDIBuilderGetOrCreateSubrange(
Builder: DIBuilderRef,
Lo: c_longlong,
Count: c_longlong) -> DISubrange;

#[fast_ffi]
pub unsafe fn LLVMDIBuilderGetOrCreateArray(
Builder: DIBuilderRef,
Ptr: *DIDescriptor,
Count: c_uint) -> DIArray;

#[fast_ffi]
pub unsafe fn LLVMDIBuilderInsertDeclareAtEnd(
Builder: DIBuilderRef,
Val: ValueRef,
VarInfo: DIVariable,
InsertAtEnd: BasicBlockRef) -> ValueRef;

#[fast_ffi]
pub unsafe fn LLVMDIBuilderInsertDeclareBefore(
Builder: DIBuilderRef,
Val: ValueRef,
VarInfo: DIVariable,
InsertBefore: ValueRef) -> ValueRef;
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1908,6 +1908,12 @@ pub fn trans_closure(ccx: @mut CrateContext,
finish(bcx);
cleanup_and_Br(bcx, bcx_top, fcx.llreturn);

// Put return block after all other blocks.
// This somewhat improves single-stepping experience in debugger.
unsafe {
llvm::LLVMMoveBasicBlockAfter(fcx.llreturn, bcx.llbb);
}

// Insert the mandatory first few basic blocks before lltop.
finish_fn(fcx, lltop);
}
Expand Down Expand Up @@ -3102,6 +3108,9 @@ pub fn trans_crate(sess: session::Session,
fill_crate_map(ccx, ccx.crate_map);
glue::emit_tydescs(ccx);
write_abi_version(ccx);
if ccx.sess.opts.debuginfo {
debuginfo::finalize(ccx);
}

// Translate the metadata.
write_metadata(ccx, crate);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl CrateContext {
lib::llvm::associate_type(tn, @"tydesc", tydesc_type);
let crate_map = decl_crate_map(sess, link_meta, llmod);
let dbg_cx = if sess.opts.debuginfo {
Some(debuginfo::mk_ctxt(name.to_owned()))
Some(debuginfo::DebugContext::new(llmod, name.to_owned()))
} else {
None
};
Expand Down