1 use syntax_pos::{BytePos, Span};
2 use rustc::hir::def_id::CrateNum;
5 pub enum FunctionDebugContext<D> {
6 RegularContext(FunctionDebugContextData<D>),
8 FunctionWithoutDebugInfo,
11 impl<D> FunctionDebugContext<D> {
12 pub fn get_ref<'a>(&'a self, span: Span) -> &'a FunctionDebugContextData<D> {
14 FunctionDebugContext::RegularContext(ref data) => data,
15 FunctionDebugContext::DebugInfoDisabled => {
18 "debuginfo: Error trying to access FunctionDebugContext \
19 although debug info is disabled!",
22 FunctionDebugContext::FunctionWithoutDebugInfo => {
25 "debuginfo: Error trying to access FunctionDebugContext \
26 for function that should be ignored by debug info!",
33 /// Enables emitting source locations for the given functions.
35 /// Since we don't want source locations to be emitted for the function prelude,
36 /// they are disabled when beginning to codegen a new function. This functions
37 /// switches source location emitting on and must therefore be called before the
38 /// first real statement/expression of the function is codegened.
39 pub fn start_emitting_source_locations<D>(dbg_context: &FunctionDebugContext<D>) {
41 FunctionDebugContext::RegularContext(ref data) => {
42 data.source_locations_enabled.set(true)
44 _ => { /* safe to ignore */ }
48 pub struct FunctionDebugContextData<D> {
50 pub source_locations_enabled: Cell<bool>,
51 pub defining_crate: CrateNum,
54 pub enum VariableAccess<'a, V> {
55 // The llptr given is an alloca containing the variable's value
56 DirectVariable { alloca: V },
57 // The llptr given is an alloca containing the start of some pointer chain
58 // leading to the variable's content.
59 IndirectVariable { alloca: V, address_operations: &'a [i64] }
62 pub enum VariableKind {
63 ArgumentVariable(usize /*index*/),
68 #[derive(Clone, Copy, Debug)]
69 pub struct MirDebugScope<D> {
70 pub scope_metadata: Option<D>,
71 // Start and end offsets of the file to which this DIScope belongs.
72 // These are used to quickly determine whether some span refers to the same file.
73 pub file_start_pos: BytePos,
74 pub file_end_pos: BytePos,
77 impl<D> MirDebugScope<D> {
78 pub fn is_valid(&self) -> bool {
79 !self.scope_metadata.is_none()