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 /// Creates a scope for a function. If `maybe_definition_llfn` is `None`, it's an inlined
22 /// callee; in that case, the implementation may benefit from caching to avoid duplication
23 /// within debuginfo. See `inlined_function_scopes` for an example in `rustc_codegen_llvm`.
24 //
25 // FIXME(eddyb) find a common convention for all of the debuginfo-related
26 // names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
27 fn dbg_scope_fn(
28 &mut self,
29 instance: Instance<'tcx>,
30 fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
31 maybe_definition_llfn: Option<Self::Function>,
32 ) -> Self::DIScope;
33
34 fn dbg_create_lexical_block(
35 &mut self,
36 pos: BytePos,
37 parent_scope: Self::DIScope,
38 ) -> Self::DIScope;
39
40 fn dbg_location_clone_with_discriminator(
41 &mut self,
42 loc: Self::DILocation,
43 discriminator: u32,
44 ) -> Option<Self::DILocation>;
45
46 fn dbg_loc(
47 &mut self,
48 scope: Self::DIScope,
49 inlined_at: Option<Self::DILocation>,
50 span: Span,
51 ) -> Self::DILocation;
52
53 fn extend_scope_to_file(
54 &mut self,
55 scope_metadata: Self::DIScope,
56 file: &SourceFile,
57 ) -> Self::DIScope;
58
59 /// Creates a debug variable. Note: a particular parameter of a function can arrive here from
60 /// several different (inlined) calls, and those calls may differ in `scope_metadata` (e.g.
61 /// bare subprogram vs file-adjusted scope), type, or file/line. The backend must handle that.
62 /// See `params_seen` in the `rustc_codegen_llvm` backend for an example.
63 //
64 // FIXME(eddyb) find a common convention for all of the debuginfo-related
65 // names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
66 fn create_dbg_var(
67 &mut self,
68 variable_name: Symbol,
69 variable_type: Ty<'tcx>,
70 scope_metadata: Self::DIScope,
71 variable_kind: VariableKind,
72 span: Span,
73 ) -> Self::DIVariable;
74
75 // FIXME(eddyb) find a common convention for all of the debuginfo-related
76 // names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
77 fn dbg_var_addr(
78 &mut self,
79 dbg_var: Self::DIVariable,
80 dbg_loc: Self::DILocation,
81 variable_alloca: 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 dbg_var_value(
90 &mut self,
91 dbg_var: Self::DIVariable,
92 dbg_loc: Self::DILocation,
93 value: Self::Value,
94 direct_offset: Size,
95 // NB: each offset implies a deref (i.e. they're steps in a pointer chain).
96 indirect_offsets: &[Size],
97 // Byte range in the `dbg_var` covered by this fragment,
98 // if this is a fragment of a composite `DIVariable`.
99 fragment: &Option<Range<Size>>,
100 );
101 fn set_dbg_loc(&mut self, dbg_loc: Self::DILocation);
102 fn clear_dbg_loc(&mut self);
103 fn insert_reference_to_gdb_debug_scripts_section_global(&mut self);
104 fn set_var_name(&mut self, value: Self::Value, name: &str);
105
106 /// Hook to allow move/copy operations to be annotated for profiling.
107 ///
108 /// The `instance` parameter should be the monomorphized instance of the
109 /// `compiler_move` or `compiler_copy` function with the actual type and size.
110 ///
111 /// Default implementation does no annotation (just executes the closure).
112 fn with_move_annotation<R>(
113 &mut self,
114 _instance: Instance<'tcx>,
115 f: impl FnOnce(&mut Self) -> R,
116 ) -> R {
117 f(self)
118 }
119}