use self::metadata::{file_metadata, type_metadata, TypeMap};
use self::namespace::mangled_name_of_instance;
-use self::source_loc::InternalDebugLocation::{self, UnknownLocation};
use self::type_names::compute_debuginfo_type_name;
use self::utils::{create_DIArray, is_node_local_to_unit, span_start, DIB};
use crate::llvm;
use crate::llvm::debuginfo::{
- DIArray, DIBuilder, DIFile, DIFlags, DILexicalBlock, DISPFlags, DIScope, DIType,
+ DIArray, DIBuilder, DIFile, DIFlags, DILexicalBlock, DISPFlags, DIScope, DIType, DIVariable,
};
use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc::ty::subst::{GenericArgKind, SubstsRef};
use std::ffi::CString;
use rustc::ty::layout::{self, HasTyCtxt, LayoutOf, Size};
+use rustc_ast::ast;
use rustc_codegen_ssa::traits::*;
use rustc_span::symbol::Symbol;
-use rustc_span::{self, BytePos, Pos, Span};
+use rustc_span::{self, BytePos, Span};
use smallvec::SmallVec;
-use syntax::ast;
mod create_scope_map;
pub mod gdb;
pub use self::create_scope_map::compute_mir_scopes;
pub use self::metadata::create_global_var_metadata;
pub use self::metadata::extend_scope_to_file;
-pub use self::source_loc::set_source_location;
#[allow(non_upper_case_globals)]
const DW_TAG_auto_variable: c_uint = 0x100;
};
}
-impl DebugInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
- fn declare_local(
+impl DebugInfoBuilderMethods for Builder<'a, 'll, 'tcx> {
+ // FIXME(eddyb) find a common convention for all of the debuginfo-related
+ // names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
+ fn dbg_var_addr(
&mut self,
- dbg_context: &FunctionDebugContext<&'ll DIScope>,
- variable_name: ast::Name,
- variable_type: Ty<'tcx>,
+ dbg_var: &'ll DIVariable,
scope_metadata: &'ll DIScope,
variable_alloca: Self::Value,
direct_offset: Size,
indirect_offsets: &[Size],
- variable_kind: VariableKind,
span: Span,
) {
- assert!(!dbg_context.source_locations_enabled);
let cx = self.cx();
- let file = span_start(cx, span).file;
- let file_metadata = file_metadata(cx, &file.name, dbg_context.defining_crate);
-
- let loc = span_start(cx, span);
- let type_metadata = type_metadata(cx, variable_type, span);
-
- let (argument_index, dwarf_tag) = match variable_kind {
- ArgumentVariable(index) => (index as c_uint, DW_TAG_arg_variable),
- LocalVariable => (0, DW_TAG_auto_variable),
- };
- let align = cx.align_of(variable_type);
-
// Convert the direct and indirect offsets to address ops.
+ // FIXME(eddyb) use `const`s instead of getting the values via FFI,
+ // the values should match the ones in the DWARF standard anyway.
let op_deref = || unsafe { llvm::LLVMRustDIBuilderCreateOpDeref() };
let op_plus_uconst = || unsafe { llvm::LLVMRustDIBuilderCreateOpPlusUconst() };
let mut addr_ops = SmallVec::<[_; 8]>::new();
}
}
- let name = SmallCStr::new(&variable_name.as_str());
- let metadata = unsafe {
- llvm::LLVMRustDIBuilderCreateVariable(
- DIB(cx),
- dwarf_tag,
- scope_metadata,
- name.as_ptr(),
- file_metadata,
- loc.line as c_uint,
- type_metadata,
- cx.sess().opts.optimize != config::OptLevel::No,
- DIFlags::FlagZero,
- argument_index,
- align.bytes() as u32,
- )
- };
- source_loc::set_debug_location(
- self,
- InternalDebugLocation::new(scope_metadata, loc.line, loc.col.to_usize()),
- );
+ // FIXME(eddyb) maybe this information could be extracted from `dbg_var`,
+ // to avoid having to pass it down in both places?
+ // NB: `var` doesn't seem to know about the column, so that's a limitation.
+ let dbg_loc = cx.create_debug_loc(scope_metadata, span);
unsafe {
- let debug_loc = llvm::LLVMGetCurrentDebugLocation(self.llbuilder);
- let instr = llvm::LLVMRustDIBuilderInsertDeclareAtEnd(
+ // FIXME(eddyb) replace `llvm.dbg.declare` with `llvm.dbg.addr`.
+ llvm::LLVMRustDIBuilderInsertDeclareAtEnd(
DIB(cx),
variable_alloca,
- metadata,
+ dbg_var,
addr_ops.as_ptr(),
addr_ops.len() as c_uint,
- debug_loc,
+ dbg_loc,
self.llbb(),
);
-
- llvm::LLVMSetInstDebugLocation(self.llbuilder, instr);
}
- source_loc::set_debug_location(self, UnknownLocation);
}
- fn set_source_location(
- &mut self,
- debug_context: &mut FunctionDebugContext<&'ll DIScope>,
- scope: &'ll DIScope,
- span: Span,
- ) {
- set_source_location(debug_context, &self, scope, span)
+ fn set_source_location(&mut self, scope: &'ll DIScope, span: Span) {
+ debug!("set_source_location: {}", self.sess().source_map().span_to_string(span));
+
+ let dbg_loc = self.cx().create_debug_loc(scope, span);
+
+ unsafe {
+ llvm::LLVMSetCurrentDebugLocation(self.llbuilder, dbg_loc);
+ }
}
fn insert_reference_to_gdb_debug_scripts_section_global(&mut self) {
gdb::insert_reference_to_gdb_debug_scripts_section_global(self)
// Get the linkage_name, which is just the symbol name
let linkage_name = mangled_name_of_instance(self, instance);
- let scope_line = span_start(self, span).line;
+ // FIXME(eddyb) does this need to be separate from `loc.line` for some reason?
+ let scope_line = loc.line;
let function_name = CString::new(name).unwrap();
let linkage_name = SmallCStr::new(&linkage_name.name.as_str());
};
let mut fn_debug_context = FunctionDebugContext {
scopes: IndexVec::from_elem(null_scope, &mir.source_scopes),
- source_locations_enabled: false,
defining_crate: def_id.krate,
};
fn debuginfo_finalize(&self) {
finalize(self)
}
+
+ // FIXME(eddyb) find a common convention for all of the debuginfo-related
+ // names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
+ fn create_dbg_var(
+ &self,
+ dbg_context: &FunctionDebugContext<&'ll DIScope>,
+ variable_name: ast::Name,
+ variable_type: Ty<'tcx>,
+ scope_metadata: &'ll DIScope,
+ variable_kind: VariableKind,
+ span: Span,
+ ) -> &'ll DIVariable {
+ let loc = span_start(self, span);
+ let file_metadata = file_metadata(self, &loc.file.name, dbg_context.defining_crate);
+
+ let type_metadata = type_metadata(self, variable_type, span);
+
+ let (argument_index, dwarf_tag) = match variable_kind {
+ ArgumentVariable(index) => (index as c_uint, DW_TAG_arg_variable),
+ LocalVariable => (0, DW_TAG_auto_variable),
+ };
+ let align = self.align_of(variable_type);
+
+ let name = SmallCStr::new(&variable_name.as_str());
+ unsafe {
+ llvm::LLVMRustDIBuilderCreateVariable(
+ DIB(self),
+ dwarf_tag,
+ scope_metadata,
+ name.as_ptr(),
+ file_metadata,
+ loc.line as c_uint,
+ type_metadata,
+ true,
+ DIFlags::FlagZero,
+ argument_index,
+ align.bytes() as u32,
+ )
+ }
+ }
}