Skip to main content

rustc_codegen_ssa/traits/
debuginfo.rs

1use std::ops::Range;
2
3use rustc_abi::Size;
4use rustc_middle::ty::{ExistentialTraitRef, Instance, Ty};
5use rustc_span::{BytePos, SourceFile, Span, Symbol};
6use rustc_target::callconv::FnAbi;
7
8use super::BackendTypes;
9use crate::mir::debuginfo::VariableKind;
10
11pub trait DebugInfoCodegenMethods<'tcx>: BackendTypes {
12    fn create_vtable_debuginfo(
13        &self,
14        ty: Ty<'tcx>,
15        trait_ref: Option<ExistentialTraitRef<'tcx>>,
16        vtable: Self::Value,
17    );
18
19    fn dbg_create_lexical_block(&self, pos: BytePos, parent_scope: Self::DIScope) -> Self::DIScope;
20
21    fn dbg_location_clone_with_discriminator(
22        &self,
23        loc: Self::DILocation,
24        discriminator: u32,
25    ) -> Option<Self::DILocation>;
26
27    // FIXME(eddyb) find a common convention for all of the debuginfo-related
28    // names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
29    fn dbg_scope_fn(
30        &self,
31        instance: Instance<'tcx>,
32        fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
33        maybe_definition_llfn: Option<Self::Function>,
34    ) -> Self::DIScope;
35
36    fn dbg_loc(
37        &self,
38        scope: Self::DIScope,
39        inlined_at: Option<Self::DILocation>,
40        span: Span,
41    ) -> Self::DILocation;
42
43    fn extend_scope_to_file(
44        &self,
45        scope_metadata: Self::DIScope,
46        file: &SourceFile,
47    ) -> Self::DIScope;
48    fn debuginfo_finalize(&self);
49
50    // FIXME(eddyb) find a common convention for all of the debuginfo-related
51    // names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
52    fn create_dbg_var(
53        &self,
54        variable_name: Symbol,
55        variable_type: Ty<'tcx>,
56        scope_metadata: Self::DIScope,
57        variable_kind: VariableKind,
58        span: Span,
59    ) -> Self::DIVariable;
60}
61
62pub trait DebugInfoBuilderMethods<'tcx>: BackendTypes {
63    // FIXME(eddyb) find a common convention for all of the debuginfo-related
64    // names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
65    fn dbg_var_addr(
66        &mut self,
67        dbg_var: Self::DIVariable,
68        dbg_loc: Self::DILocation,
69        variable_alloca: Self::Value,
70        direct_offset: Size,
71        // NB: each offset implies a deref (i.e. they're steps in a pointer chain).
72        indirect_offsets: &[Size],
73        // Byte range in the `dbg_var` covered by this fragment,
74        // if this is a fragment of a composite `DIVariable`.
75        fragment: &Option<Range<Size>>,
76    );
77    fn dbg_var_value(
78        &mut self,
79        dbg_var: Self::DIVariable,
80        dbg_loc: Self::DILocation,
81        value: Self::Value,
82        direct_offset: Size,
83        // NB: each offset implies a deref (i.e. they're steps in a pointer chain).
84        indirect_offsets: &[Size],
85        // Byte range in the `dbg_var` covered by this fragment,
86        // if this is a fragment of a composite `DIVariable`.
87        fragment: &Option<Range<Size>>,
88    );
89    fn set_dbg_loc(&mut self, dbg_loc: Self::DILocation);
90    fn clear_dbg_loc(&mut self);
91    fn insert_reference_to_gdb_debug_scripts_section_global(&mut self);
92    fn set_var_name(&mut self, value: Self::Value, name: &str);
93
94    /// Hook to allow move/copy operations to be annotated for profiling.
95    ///
96    /// The `instance` parameter should be the monomorphized instance of the
97    /// `compiler_move` or `compiler_copy` function with the actual type and size.
98    ///
99    /// Default implementation does no annotation (just executes the closure).
100    fn with_move_annotation<R>(
101        &mut self,
102        _instance: Instance<'tcx>,
103        f: impl FnOnce(&mut Self) -> R,
104    ) -> R {
105        f(self)
106    }
107}