Skip to content

Commit 4bf074c

Browse files
committed
auto merge of #7134 : vadimcn/rust/DIBuilder, r=jdm
This commit fixes rustc's debug info generation and turns debug-info tests back on. The old generator used to write out LLVM metadata directly, however it seems that debug metadata format is not stable and keeps changing from release to release. So I wrapped LLVM's official debug info API - the DIBuilder class, and now rustc will use that. One bit of old functionality that still doesn't work, is debug info for function arguments. Someone more familiar with the compiler guts will need to look into that. Also, unfortunately, debug info is still won't work on Windows,- due to a LLVM bug (http://llvm.org/bugs/show_bug.cgi?id=16249). Resolves issues #5836, #5848, #6814
2 parents 644774c + adff462 commit 4bf074c

File tree

13 files changed

+946
-748
lines changed

13 files changed

+946
-748
lines changed

src/compiletest/procsrv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn target_env(lib_path: &str, prog: &str) -> ~[(~str,~str)] {
2323
assert!(prog.ends_with(".exe"));
2424
let aux_path = prog.slice(0u, prog.len() - 4u).to_owned() + ".libaux";
2525

26-
env = do vec::map(env) |pair| {
26+
env = do env.map() |pair| {
2727
let (k,v) = copy *pair;
2828
if k == ~"PATH" { (~"PATH", v + ";" + lib_path + ";" + aux_path) }
2929
else { (k,v) }

src/librustc/lib/llvm.rs

+203-2
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,50 @@ pub type SectionIteratorRef = *SectionIterator_opaque;
224224
pub enum Pass_opaque {}
225225
pub type PassRef = *Pass_opaque;
226226

227+
pub mod debuginfo {
228+
use super::{ValueRef};
229+
230+
pub enum DIBuilder_opaque {}
231+
pub type DIBuilderRef = *DIBuilder_opaque;
232+
233+
pub type DIDescriptor = ValueRef;
234+
pub type DIScope = DIDescriptor;
235+
pub type DILocation = DIDescriptor;
236+
pub type DIFile = DIScope;
237+
pub type DILexicalBlock = DIScope;
238+
pub type DISubprogram = DIScope;
239+
pub type DIType = DIDescriptor;
240+
pub type DIBasicType = DIType;
241+
pub type DIDerivedType = DIType;
242+
pub type DICompositeType = DIDerivedType;
243+
pub type DIVariable = DIDescriptor;
244+
pub type DIArray = DIDescriptor;
245+
pub type DISubrange = DIDescriptor;
246+
247+
pub enum DIDescriptorFlags {
248+
FlagPrivate = 1 << 0,
249+
FlagProtected = 1 << 1,
250+
FlagFwdDecl = 1 << 2,
251+
FlagAppleBlock = 1 << 3,
252+
FlagBlockByrefStruct = 1 << 4,
253+
FlagVirtual = 1 << 5,
254+
FlagArtificial = 1 << 6,
255+
FlagExplicit = 1 << 7,
256+
FlagPrototyped = 1 << 8,
257+
FlagObjcClassComplete = 1 << 9,
258+
FlagObjectPointer = 1 << 10,
259+
FlagVector = 1 << 11,
260+
FlagStaticMember = 1 << 12
261+
}
262+
}
263+
227264
pub mod llvm {
228265
use super::{AtomicBinOp, AtomicOrdering, BasicBlockRef, ExecutionEngineRef};
229266
use super::{Bool, BuilderRef, ContextRef, MemoryBufferRef, ModuleRef};
230267
use super::{ObjectFileRef, Opcode, PassManagerRef, PassManagerBuilderRef};
231268
use super::{SectionIteratorRef, TargetDataRef, TypeKind, TypeRef, UseRef};
232-
use super::{ValueRef,PassRef};
233-
269+
use super::{ValueRef, PassRef};
270+
use super::debuginfo::*;
234271
use core::libc::{c_char, c_int, c_longlong, c_ushort, c_uint, c_ulonglong};
235272

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

969+
#[fast_ffi]
970+
pub unsafe fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef, MoveAfter: BasicBlockRef);
971+
972+
#[fast_ffi]
973+
pub unsafe fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef, MoveBefore: BasicBlockRef);
974+
932975
/* Operations on instructions */
933976
#[fast_ffi]
934977
pub unsafe fn LLVMGetInstructionParent(Inst: ValueRef)
@@ -1885,6 +1928,164 @@ pub mod llvm {
18851928
AlignStack: Bool, Dialect: c_uint)
18861929
-> ValueRef;
18871930

1931+
1932+
#[fast_ffi]
1933+
pub unsafe fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
1934+
1935+
#[fast_ffi]
1936+
pub unsafe fn LLVMDIBuilderDispose(Builder: DIBuilderRef);
1937+
1938+
#[fast_ffi]
1939+
pub unsafe fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);
1940+
1941+
#[fast_ffi]
1942+
pub unsafe fn LLVMDIBuilderCreateCompileUnit(
1943+
Builder: DIBuilderRef,
1944+
Lang: c_uint,
1945+
File: *c_char,
1946+
Dir: *c_char,
1947+
Producer: *c_char,
1948+
isOptimized: bool,
1949+
Flags: *c_char,
1950+
RuntimeVer: c_uint,
1951+
SplitName: *c_char);
1952+
1953+
#[fast_ffi]
1954+
pub unsafe fn LLVMDIBuilderCreateFile(
1955+
Builder: DIBuilderRef,
1956+
Filename: *c_char,
1957+
Directory: *c_char) -> DIFile;
1958+
1959+
#[fast_ffi]
1960+
pub unsafe fn LLVMDIBuilderCreateSubroutineType(
1961+
Builder: DIBuilderRef,
1962+
File: DIFile,
1963+
ParameterTypes: DIArray) -> DICompositeType;
1964+
1965+
#[fast_ffi]
1966+
pub unsafe fn LLVMDIBuilderCreateFunction(
1967+
Builder: DIBuilderRef,
1968+
Scope: DIDescriptor,
1969+
Name: *c_char,
1970+
LinkageName: *c_char,
1971+
File: DIFile,
1972+
LineNo: c_uint,
1973+
Ty: DIType,
1974+
isLocalToUnit: bool,
1975+
isDefinition: bool,
1976+
ScopeLine: c_uint,
1977+
Flags: c_uint,
1978+
isOptimized: bool,
1979+
Fn: ValueRef,
1980+
TParam: ValueRef,
1981+
Decl: ValueRef) -> DISubprogram;
1982+
1983+
#[fast_ffi]
1984+
pub unsafe fn LLVMDIBuilderCreateBasicType(
1985+
Builder: DIBuilderRef,
1986+
Name: *c_char,
1987+
SizeInBits: c_ulonglong,
1988+
AlignInBits: c_ulonglong,
1989+
Encoding: c_uint) -> DIBasicType;
1990+
1991+
#[fast_ffi]
1992+
pub unsafe fn LLVMDIBuilderCreatePointerType(
1993+
Builder: DIBuilderRef,
1994+
PointeeTy: DIType,
1995+
SizeInBits: c_ulonglong,
1996+
AlignInBits: c_ulonglong,
1997+
Name: *c_char) -> DIDerivedType;
1998+
1999+
#[fast_ffi]
2000+
pub unsafe fn LLVMDIBuilderCreateStructType(
2001+
Builder: DIBuilderRef,
2002+
Scope: DIDescriptor,
2003+
Name: *c_char,
2004+
File: DIFile,
2005+
LineNumber: c_uint,
2006+
SizeInBits: c_ulonglong,
2007+
AlignInBits: c_ulonglong,
2008+
Flags: c_uint,
2009+
DerivedFrom: DIType,
2010+
Elements: DIArray,
2011+
RunTimeLang: c_uint,
2012+
VTableHolder: ValueRef) -> DICompositeType;
2013+
2014+
#[fast_ffi]
2015+
pub unsafe fn LLVMDIBuilderCreateMemberType(
2016+
Builder: DIBuilderRef,
2017+
Scope: DIDescriptor,
2018+
Name: *c_char,
2019+
File: DIFile,
2020+
LineNo: c_uint,
2021+
SizeInBits: c_ulonglong,
2022+
AlignInBits: c_ulonglong,
2023+
OffsetInBits: c_ulonglong,
2024+
Flags: c_uint,
2025+
Ty: DIType) -> DIDerivedType;
2026+
2027+
#[fast_ffi]
2028+
pub unsafe fn LLVMDIBuilderCreateLexicalBlock(
2029+
Builder: DIBuilderRef,
2030+
Scope: DIDescriptor,
2031+
File: DIFile,
2032+
Line: c_uint,
2033+
Col: c_uint) -> DILexicalBlock;
2034+
2035+
#[fast_ffi]
2036+
pub unsafe fn LLVMDIBuilderCreateLocalVariable(
2037+
Builder: DIBuilderRef,
2038+
Tag: c_uint,
2039+
Scope: DIDescriptor,
2040+
Name: *c_char,
2041+
File: DIFile,
2042+
LineNo: c_uint,
2043+
Ty: DIType,
2044+
AlwaysPreserve: bool,
2045+
Flags: c_uint,
2046+
ArgNo: c_uint) -> DIVariable;
2047+
2048+
#[fast_ffi]
2049+
pub unsafe fn LLVMDIBuilderCreateArrayType(
2050+
Builder: DIBuilderRef,
2051+
Size: c_ulonglong,
2052+
AlignInBits: c_ulonglong,
2053+
Ty: DIType,
2054+
Subscripts: DIArray) -> DIType;
2055+
2056+
#[fast_ffi]
2057+
pub unsafe fn LLVMDIBuilderCreateVectorType(
2058+
Builder: DIBuilderRef,
2059+
Size: c_ulonglong,
2060+
AlignInBits: c_ulonglong,
2061+
Ty: DIType,
2062+
Subscripts: DIArray) -> DIType;
2063+
2064+
#[fast_ffi]
2065+
pub unsafe fn LLVMDIBuilderGetOrCreateSubrange(
2066+
Builder: DIBuilderRef,
2067+
Lo: c_longlong,
2068+
Count: c_longlong) -> DISubrange;
2069+
2070+
#[fast_ffi]
2071+
pub unsafe fn LLVMDIBuilderGetOrCreateArray(
2072+
Builder: DIBuilderRef,
2073+
Ptr: *DIDescriptor,
2074+
Count: c_uint) -> DIArray;
2075+
2076+
#[fast_ffi]
2077+
pub unsafe fn LLVMDIBuilderInsertDeclareAtEnd(
2078+
Builder: DIBuilderRef,
2079+
Val: ValueRef,
2080+
VarInfo: DIVariable,
2081+
InsertAtEnd: BasicBlockRef) -> ValueRef;
2082+
2083+
#[fast_ffi]
2084+
pub unsafe fn LLVMDIBuilderInsertDeclareBefore(
2085+
Builder: DIBuilderRef,
2086+
Val: ValueRef,
2087+
VarInfo: DIVariable,
2088+
InsertBefore: ValueRef) -> ValueRef;
18882089
}
18892090
}
18902091

src/librustc/middle/trans/base.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1908,6 +1908,12 @@ pub fn trans_closure(ccx: @mut CrateContext,
19081908
finish(bcx);
19091909
cleanup_and_Br(bcx, bcx_top, fcx.llreturn);
19101910

1911+
// Put return block after all other blocks.
1912+
// This somewhat improves single-stepping experience in debugger.
1913+
unsafe {
1914+
llvm::LLVMMoveBasicBlockAfter(fcx.llreturn, bcx.llbb);
1915+
}
1916+
19111917
// Insert the mandatory first few basic blocks before lltop.
19121918
finish_fn(fcx, lltop);
19131919
}
@@ -3102,6 +3108,9 @@ pub fn trans_crate(sess: session::Session,
31023108
fill_crate_map(ccx, ccx.crate_map);
31033109
glue::emit_tydescs(ccx);
31043110
write_abi_version(ccx);
3111+
if ccx.sess.opts.debuginfo {
3112+
debuginfo::finalize(ccx);
3113+
}
31053114
31063115
// Translate the metadata.
31073116
write_metadata(ccx, crate);

src/librustc/middle/trans/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl CrateContext {
148148
lib::llvm::associate_type(tn, @"tydesc", tydesc_type);
149149
let crate_map = decl_crate_map(sess, link_meta, llmod);
150150
let dbg_cx = if sess.opts.debuginfo {
151-
Some(debuginfo::mk_ctxt(name.to_owned()))
151+
Some(debuginfo::DebugContext::new(llmod, name.to_owned()))
152152
} else {
153153
None
154154
};

0 commit comments

Comments
 (0)