diff --git a/src/rustc/driver/driver.rs b/src/rustc/driver/driver.rs index 52aa88e6cb6..369eccc6bed 100644 --- a/src/rustc/driver/driver.rs +++ b/src/rustc/driver/driver.rs @@ -14,6 +14,7 @@ import io::{reader_util, writer_util}; import getopts::{optopt, optmulti, optflag, optflagopt, opt_present}; import back::{x86, x86_64}; import std::map::hashmap; +import lib::llvm::llvm; enum pp_mode {ppm_normal, ppm_expanded, ppm_typed, ppm_identified, ppm_expanded_identified } @@ -440,6 +441,9 @@ fn build_session_options(match: getopts::match, } debugging_opts |= this_bit; } + if debugging_opts & session::debug_llvm != 0 { + llvm::LLVMSetDebug(1); + } let output_type = if parse_only || no_trans { diff --git a/src/rustc/driver/session.rs b/src/rustc/driver/session.rs index 64ae30895c4..61ef9f73c3f 100644 --- a/src/rustc/driver/session.rs +++ b/src/rustc/driver/session.rs @@ -40,6 +40,7 @@ const borrowck_stats: uint = 1024u; const borrowck_note_pure: uint = 2048; const borrowck_note_loan: uint = 4096; const no_landing_pads: uint = 8192; +const debug_llvm: uint = 16384; fn debugging_opts_map() -> ~[(~str, ~str, uint)] { ~[(~"ppregions", ~"prettyprint regions with \ @@ -61,7 +62,8 @@ fn debugging_opts_map() -> ~[(~str, ~str, uint)] { (~"borrowck-note-loan", ~"note where loans are req'd", borrowck_note_loan), (~"no-landing-pads", ~"omit landing pads for unwinding", - no_landing_pads) + no_landing_pads), + (~"debug-llvm", ~"enable debug output from LLVM", debug_llvm) ] } diff --git a/src/rustc/lib/llvm.rs b/src/rustc/lib/llvm.rs index 376012dcf4e..7dbefa8e498 100644 --- a/src/rustc/lib/llvm.rs +++ b/src/rustc/lib/llvm.rs @@ -969,6 +969,9 @@ extern mod llvm { fn LLVMConstNamedStruct(S: TypeRef, ConstantVals: *ValueRef, Count: c_uint) -> ValueRef; + + /** Enables LLVM debug output. */ + fn LLVMSetDebug(Enabled: c_int); } fn SetInstructionCallConv(Instr: ValueRef, CC: CallConv) { diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index a9f759b26aa..4a927744f07 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -27,6 +27,7 @@ #include "llvm/Support/SourceMgr.h" #include "llvm/Target/TargetOptions.h" #include "llvm/Support/Host.h" +#include "llvm/Support/Debug.h" #include "llvm-c/Core.h" #include "llvm-c/BitReader.h" #include "llvm-c/Object.h" @@ -185,3 +186,7 @@ extern "C" LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, unwrap(target), unwrap(source), order)); } + +extern "C" void LLVMSetDebug(int Enabled) { + DebugFlag = Enabled; +} diff --git a/src/rustllvm/rustllvm.def.in b/src/rustllvm/rustllvm.def.in index f3a3d7f4f23..64b560999be 100644 --- a/src/rustllvm/rustllvm.def.in +++ b/src/rustllvm/rustllvm.def.in @@ -528,6 +528,7 @@ LLVMSetAlignment LLVMSetCleanup LLVMSetCurrentDebugLocation LLVMSetDataLayout +LLVMSetDebug LLVMSetFunctionCallConv LLVMSetGC LLVMSetGlobalConstant