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};
|
2019-09-04 19:44:58 +03:00
|
|
|
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;
|
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;
|
2019-12-31 20:15:40 +03:00
|
|
|
use rustc_span::{Pos, Span};
|
2015-04-29 18:14:37 +12:00
|
|
|
|
|
|
|
/// Sets the current debug location at the beginning of the span.
|
|
|
|
///
|
2016-04-07 22:35:11 +03:00
|
|
|
/// Maps to a call to llvm::LLVMSetCurrentDebugLocation(...).
|
2018-09-20 15:47:22 +02:00
|
|
|
pub fn set_source_location<D>(
|
|
|
|
debug_context: &FunctionDebugContext<D>,
|
2018-07-04 16:36:49 +03:00
|
|
|
bx: &Builder<'_, 'll, '_>,
|
2019-09-11 17:52:39 +03:00
|
|
|
scope: &'ll DIScope,
|
2018-07-04 16:36:49 +03:00
|
|
|
span: Span,
|
2016-12-18 23:04:25 -07:00
|
|
|
) {
|
2019-09-11 17:52:39 +03:00
|
|
|
let dbg_loc = if debug_context.source_locations_enabled {
|
2018-11-27 19:00:25 +01:00
|
|
|
debug!("set_source_location: {}", bx.sess().source_map().span_to_string(span));
|
2018-08-28 17:50:57 +02:00
|
|
|
let loc = span_start(bx.cx(), span);
|
2019-09-11 17:52:39 +03:00
|
|
|
InternalDebugLocation::new(scope, loc.line, loc.col.to_usize())
|
2016-04-07 22:35:11 +03:00
|
|
|
} 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)]
|
2018-07-04 16:36:49 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-07-04 16:36:49 +03: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>) {
|
2016-04-07 22:35:11 +03:00
|
|
|
let metadata_node = match debug_location {
|
2018-07-02 11:40:32 +02:00
|
|
|
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 {
|
2018-07-02 11:40:32 +02:00
|
|
|
UNKNOWN_COLUMN_NUMBER
|
|
|
|
} else {
|
|
|
|
col as c_uint
|
|
|
|
};
|
2015-04-29 18:14:37 +12:00
|
|
|
debug!("setting debug location to {} {}", line, col);
|
|
|
|
|
|
|
|
unsafe {
|
2018-07-10 13:28:39 +03:00
|
|
|
Some(llvm::LLVMRustDIBuilderCreateDebugLocation(
|
2018-08-28 17:50:57 +02:00
|
|
|
debug_context(bx.cx()).llcontext,
|
2015-04-29 18:14:37 +12:00
|
|
|
line as c_uint,
|
2018-07-02 11:40:32 +02:00
|
|
|
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 ");
|
2018-06-27 13:12:47 +03:00
|
|
|
None
|
2015-04-29 18:14:37 +12:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-04-07 22:35:11 +03:00
|
|
|
unsafe {
|
2018-01-05 07:12:32 +02:00
|
|
|
llvm::LLVMSetCurrentDebugLocation(bx.llbuilder, metadata_node);
|
2016-04-07 22:35:11 +03:00
|
|
|
}
|
2015-04-29 18:14:37 +12:00
|
|
|
}
|