Skip to content

Commit

Permalink
Set the DICompileUnit emissionKind
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Jan 25, 2019
1 parent 75d0bce commit cff0750
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/librustc_codegen_llvm/debuginfo/metadata.rs
Expand Up @@ -13,7 +13,7 @@ use value::Value;

use llvm;
use llvm::debuginfo::{DIArray, DIType, DIFile, DIScope, DIDescriptor,
DICompositeType, DILexicalBlock, DIFlags};
DICompositeType, DILexicalBlock, DIFlags, DebugEmissionKind};
use llvm_util;

use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
Expand Down Expand Up @@ -846,6 +846,7 @@ pub fn compile_unit_metadata(tcx: TyCtxt,
let producer = CString::new(producer).unwrap();
let flags = "\0";
let split_name = "\0";
let kind = DebugEmissionKind::from_generic(tcx.sess.opts.debuginfo);

unsafe {
let file_metadata = llvm::LLVMRustDIBuilderCreateFile(
Expand All @@ -859,7 +860,8 @@ pub fn compile_unit_metadata(tcx: TyCtxt,
tcx.sess.opts.optimize != config::OptLevel::No,
flags.as_ptr() as *const _,
0,
split_name.as_ptr() as *const _);
split_name.as_ptr() as *const _,
kind);

if tcx.sess.opts.debugging_opts.profile {
let cu_desc_metadata = llvm::LLVMRustMetadataAsValue(debug_context.llcontext,
Expand Down
25 changes: 23 additions & 2 deletions src/librustc_codegen_llvm/llvm/ffi.rs
Expand Up @@ -2,7 +2,7 @@ use super::debuginfo::{
DIBuilder, DIDescriptor, DIFile, DILexicalBlock, DISubprogram, DIType,
DIBasicType, DIDerivedType, DICompositeType, DIScope, DIVariable,
DIGlobalVariableExpression, DIArray, DISubrange, DITemplateTypeParameter, DIEnumerator,
DINameSpace, DIFlags, DISPFlags,
DINameSpace, DIFlags, DISPFlags, DebugEmissionKind,
};

use libc::{c_uint, c_int, size_t, c_char};
Expand Down Expand Up @@ -605,6 +605,26 @@ pub mod debuginfo {
const SPFlagOptimized = (1 << 4);
}
}

/// LLVMRustDebugEmissionKind
#[derive(Copy, Clone)]
#[repr(C)]
pub enum DebugEmissionKind {
NoDebug,
FullDebug,
LineTablesOnly,
}

impl DebugEmissionKind {
pub fn from_generic(kind: rustc::session::config::DebugInfo) -> Self {
use rustc::session::config::DebugInfo;
match kind {
DebugInfo::None => DebugEmissionKind::NoDebug,
DebugInfo::Limited => DebugEmissionKind::LineTablesOnly,
DebugInfo::Full => DebugEmissionKind::FullDebug,
}
}
}
}

extern { pub type ModuleBuffer; }
Expand Down Expand Up @@ -1381,7 +1401,8 @@ extern "C" {
isOptimized: bool,
Flags: *const c_char,
RuntimeVer: c_uint,
SplitName: *const c_char)
SplitName: *const c_char,
kind: DebugEmissionKind)
-> &'a DIDescriptor;

pub fn LLVMRustDIBuilderCreateFile(Builder: &DIBuilder<'a>,
Expand Down
25 changes: 23 additions & 2 deletions src/rustllvm/RustWrapper.cpp
Expand Up @@ -576,6 +576,25 @@ static DISubprogram::DISPFlags fromRust(LLVMRustDISPFlags SPFlags) {
}
#endif

enum class LLVMRustDebugEmissionKind {
NoDebug,
FullDebug,
LineTablesOnly,
};

static DICompileUnit::DebugEmissionKind fromRust(LLVMRustDebugEmissionKind Kind) {
switch (Kind) {
case LLVMRustDebugEmissionKind::NoDebug:
return DICompileUnit::DebugEmissionKind::NoDebug;
case LLVMRustDebugEmissionKind::FullDebug:
return DICompileUnit::DebugEmissionKind::FullDebug;
case LLVMRustDebugEmissionKind::LineTablesOnly:
return DICompileUnit::DebugEmissionKind::LineTablesOnly;
default:
report_fatal_error("bad DebugEmissionKind.");
}
}

extern "C" uint32_t LLVMRustDebugMetadataVersion() {
return DEBUG_METADATA_VERSION;
}
Expand Down Expand Up @@ -616,11 +635,13 @@ extern "C" void LLVMRustDIBuilderFinalize(LLVMRustDIBuilderRef Builder) {
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateCompileUnit(
LLVMRustDIBuilderRef Builder, unsigned Lang, LLVMMetadataRef FileRef,
const char *Producer, bool isOptimized, const char *Flags,
unsigned RuntimeVer, const char *SplitName) {
unsigned RuntimeVer, const char *SplitName,
LLVMRustDebugEmissionKind Kind) {
auto *File = unwrapDI<DIFile>(FileRef);

return wrap(Builder->createCompileUnit(Lang, File, Producer, isOptimized,
Flags, RuntimeVer, SplitName));
Flags, RuntimeVer, SplitName,
fromRust(Kind)));
}

extern "C" LLVMMetadataRef
Expand Down

0 comments on commit cff0750

Please sign in to comment.