1
Fork 0
rust/src/librustc_codegen_llvm/debuginfo/source_loc.rs

80 lines
2.4 KiB
Rust
Raw Normal View History

2015-04-29 18:14:37 +12:00
use self::InternalDebugLocation::*;
2016-12-16 13:25:18 -07:00
use super::metadata::UNKNOWN_COLUMN_NUMBER;
2019-12-22 17:42:04 -05:00
use super::utils::{debug_context, span_start};
use rustc_codegen_ssa::mir::debuginfo::FunctionDebugContext;
2015-04-29 18:14:37 +12:00
2019-12-22 17:42:04 -05:00
use crate::builder::Builder;
2019-02-18 03:58:58 +09:00
use crate::llvm;
use crate::llvm::debuginfo::DIScope;
rustc: Link LLVM directly into rustc again This commit builds on #65501 continue to simplify the build system and compiler now that we no longer have multiple LLVM backends to ship by default. Here this switches the compiler back to what it once was long long ago, which is linking LLVM directly to the compiler rather than dynamically loading it at runtime. The `codegen-backends` directory of the sysroot no longer exists and all relevant support in the build system is removed. Note that `rustc` still supports a dynamically loaded codegen backend as it did previously, it just no longer supports dynamically loaded codegen backends in its own sysroot. Additionally as part of this the `librustc_codegen_llvm` crate now once again explicitly depends on all of its crates instead of implicitly loading them through the sysroot. This involved filling out its `Cargo.toml` and deleting all the now-unnecessary `extern crate` annotations in the header of the crate. (this in turn required adding a number of imports for names of macros too). The end results of this change are: * Rustbuild's build process for the compiler as all the "oh don't forget the codegen backend" checks can be easily removed. * Building `rustc_codegen_llvm` is much simpler since it's simply another compiler crate. * Managing the dependencies of `rustc_codegen_llvm` is much simpler since it's "just another `Cargo.toml` to edit" * The build process should be a smidge faster because there's more parallelism in the main rustc build step rather than splitting `librustc_codegen_llvm` out to its own step. * The compiler is expected to be slightly faster by default because the codegen backend does not need to be dynamically loaded. * Disabling LLVM as part of rustbuild is still supported, supporting multiple codegen backends is still supported, and dynamic loading of a codegen backend is still supported.
2019-10-22 08:51:35 -07:00
use log::debug;
2019-12-22 17:42:04 -05:00
use rustc_codegen_ssa::traits::*;
2015-04-29 18:14:37 +12:00
use libc::c_uint;
use rustc_span::{Pos, Span};
2015-04-29 18:14:37 +12:00
/// Sets the current debug location at the beginning of the span.
///
/// Maps to a call to llvm::LLVMSetCurrentDebugLocation(...).
pub fn set_source_location<D>(
debug_context: &FunctionDebugContext<D>,
bx: &Builder<'_, 'll, '_>,
scope: &'ll DIScope,
span: Span,
) {
let dbg_loc = if debug_context.source_locations_enabled {
debug!("set_source_location: {}", bx.sess().source_map().span_to_string(span));
let loc = span_start(bx.cx(), span);
InternalDebugLocation::new(scope, loc.line, loc.col.to_usize())
} else {
UnknownLocation
};
2018-01-05 07:12:32 +02:00
set_debug_location(bx, dbg_loc);
2015-04-29 18:14:37 +12:00
}
#[derive(Copy, Clone, PartialEq)]
pub enum InternalDebugLocation<'ll> {
KnownLocation { scope: &'ll DIScope, line: usize, col: usize },
2019-12-22 17:42:04 -05:00
UnknownLocation,
2015-04-29 18:14:37 +12:00
}
impl InternalDebugLocation<'ll> {
pub fn new(scope: &'ll DIScope, line: usize, col: usize) -> Self {
2019-12-22 17:42:04 -05:00
KnownLocation { scope, line, col }
2015-04-29 18:14:37 +12:00
}
}
2019-12-22 17:42:04 -05:00
pub fn set_debug_location(bx: &Builder<'_, 'll, '_>, debug_location: InternalDebugLocation<'ll>) {
let metadata_node = match debug_location {
KnownLocation { scope, line, col } => {
// For MSVC, set the column number to zero.
// Otherwise, emit it. This mimics clang behaviour.
// See discussion in https://github.com/rust-lang/rust/issues/42921
2019-12-22 17:42:04 -05:00
let col_used = if bx.sess().target.target.options.is_like_msvc {
UNKNOWN_COLUMN_NUMBER
} else {
col as c_uint
};
2015-04-29 18:14:37 +12:00
debug!("setting debug location to {} {}", line, col);
unsafe {
Some(llvm::LLVMRustDIBuilderCreateDebugLocation(
debug_context(bx.cx()).llcontext,
2015-04-29 18:14:37 +12:00
line as c_uint,
col_used,
2015-04-29 18:14:37 +12:00
scope,
2019-12-22 17:42:04 -05:00
None,
))
2015-04-29 18:14:37 +12:00
}
}
UnknownLocation => {
debug!("clearing debug location ");
None
2015-04-29 18:14:37 +12:00
}
};
unsafe {
2018-01-05 07:12:32 +02:00
llvm::LLVMSetCurrentDebugLocation(bx.llbuilder, metadata_node);
}
2015-04-29 18:14:37 +12:00
}