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