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 => {
26 span_bug!(span, "{}", FunctionDebugContext::<D>::debuginfo_disabled_message());
28 FunctionDebugContext::FunctionWithoutDebugInfo => {
29 span_bug!(span, "{}", FunctionDebugContext::<D>::should_be_ignored_message());
34 fn debuginfo_disabled_message() -> &'static str {
35 "debuginfo: Error trying to access FunctionDebugContext although debug info is disabled!"
38 fn should_be_ignored_message() -> &'static str {
39 "debuginfo: Error trying to access FunctionDebugContext for function that should be \
40 ignored by debug info!"
44 /// Enables emitting source locations for the given functions.
46 /// Since we don't want source locations to be emitted for the function prelude,
47 /// they are disabled when beginning to codegen a new function. This functions
48 /// switches source location emitting on and must therefore be called before the
49 /// first real statement/expression of the function is codegened.
50 pub fn start_emitting_source_locations<D>(dbg_context: &FunctionDebugContext<D>) {
52 FunctionDebugContext::RegularContext(ref data) => {
53 data.source_locations_enabled.set(true)
55 _ => { /* safe to ignore */ }
59 pub struct FunctionDebugContextData<D> {
61 pub source_locations_enabled: Cell<bool>,
62 pub defining_crate: CrateNum,
65 pub enum VariableAccess<'a, V> {
66 // The llptr given is an alloca containing the variable's value
67 DirectVariable { alloca: V },
68 // The llptr given is an alloca containing the start of some pointer chain
69 // leading to the variable's content.
70 IndirectVariable { alloca: V, address_operations: &'a [i64] }
73 pub enum VariableKind {
74 ArgumentVariable(usize /*index*/),
79 #[derive(Clone, Copy, Debug)]
80 pub struct MirDebugScope<D> {
81 pub scope_metadata: Option<D>,
82 // Start and end offsets of the file to which this DIScope belongs.
83 // These are used to quickly determine whether some span refers to the same file.
84 pub file_start_pos: BytePos,
85 pub file_end_pos: BytePos,
88 impl<D> MirDebugScope<D> {
89 pub fn is_valid(&self) -> bool {
90 !self.scope_metadata.is_none()