1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use syntax_pos::{BytePos, Span};
12 use rustc::hir::def_id::CrateNum;
15 pub enum FunctionDebugContext<D> {
16 RegularContext(FunctionDebugContextData<D>),
18 FunctionWithoutDebugInfo,
21 impl<D> FunctionDebugContext<D> {
22 pub fn get_ref<'a>(&'a self, span: Span) -> &'a FunctionDebugContextData<D> {
24 FunctionDebugContext::RegularContext(ref data) => data,
25 FunctionDebugContext::DebugInfoDisabled => {
28 "debuginfo: Error trying to access FunctionDebugContext \
29 although debug info is disabled!",
32 FunctionDebugContext::FunctionWithoutDebugInfo => {
35 "debuginfo: Error trying to access FunctionDebugContext \
36 for function that should be ignored by debug info!",
43 /// Enables emitting source locations for the given functions.
45 /// Since we don't want source locations to be emitted for the function prelude,
46 /// they are disabled when beginning to codegen a new function. This functions
47 /// switches source location emitting on and must therefore be called before the
48 /// first real statement/expression of the function is codegened.
49 pub fn start_emitting_source_locations<D>(dbg_context: &FunctionDebugContext<D>) {
51 FunctionDebugContext::RegularContext(ref data) => {
52 data.source_locations_enabled.set(true)
54 _ => { /* safe to ignore */ }
58 pub struct FunctionDebugContextData<D> {
60 pub source_locations_enabled: Cell<bool>,
61 pub defining_crate: CrateNum,
64 pub enum VariableAccess<'a, V> {
65 // The llptr given is an alloca containing the variable's value
66 DirectVariable { alloca: V },
67 // The llptr given is an alloca containing the start of some pointer chain
68 // leading to the variable's content.
69 IndirectVariable { alloca: V, address_operations: &'a [i64] }
72 pub enum VariableKind {
73 ArgumentVariable(usize /*index*/),
78 #[derive(Clone, Copy, Debug)]
79 pub struct MirDebugScope<D> {
80 pub scope_metadata: Option<D>,
81 // Start and end offsets of the file to which this DIScope belongs.
82 // These are used to quickly determine whether some span refers to the same file.
83 pub file_start_pos: BytePos,
84 pub file_end_pos: BytePos,
87 impl<D> MirDebugScope<D> {
88 pub fn is_valid(&self) -> bool {
89 !self.scope_metadata.is_none()