1 use gccjit::{FunctionType, RValue};
2 use rustc_codegen_ssa::mir::debuginfo::{FunctionDebugContext, VariableKind};
3 use rustc_codegen_ssa::traits::{BuilderMethods, DebugInfoBuilderMethods, DebugInfoMethods};
4 use rustc_middle::middle::cstore::CrateDepKind;
6 use rustc_middle::ty::{Instance, Ty};
7 use rustc_span::{SourceFile, Span, Symbol};
8 use rustc_span::def_id::LOCAL_CRATE;
9 use rustc_target::abi::Size;
10 use rustc_target::abi::call::FnAbi;
12 use crate::builder::Builder;
13 use crate::context::CodegenCx;
15 impl<'a, 'gcc, 'tcx> DebugInfoBuilderMethods for Builder<'a, 'gcc, 'tcx> {
16 // FIXME(eddyb) find a common convention for all of the debuginfo-related
17 // names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
18 fn dbg_var_addr(&mut self, _dbg_var: Self::DIVariable, _scope_metadata: Self::DIScope, _variable_alloca: Self::Value, _direct_offset: Size, _indirect_offsets: &[Size]) {
22 fn insert_reference_to_gdb_debug_scripts_section_global(&mut self) {
23 // TODO(antoyo): replace with gcc_jit_context_new_global_with_initializer() if it's added:
24 // https://gcc.gnu.org/pipermail/jit/2020q3/001225.html
26 // Call the function to initialize global values here.
27 // We assume this is only called for the main function.
30 for crate_num in self.cx.tcx.crates(()).iter().copied().chain(iter::once(LOCAL_CRATE)) {
31 // FIXME(antoyo): better way to find if a crate is of proc-macro type?
32 if crate_num == LOCAL_CRATE || self.cx.tcx.dep_kind(crate_num) != CrateDepKind::MacrosOnly {
33 // NOTE: proc-macro crates are not included in the executable, so don't call their
34 // initialization routine.
35 let initializer_name = format!("__gccGlobalCrateInit{}", self.cx.tcx.crate_name(crate_num));
36 let codegen_init_func = self.context.new_function(None, FunctionType::Extern, self.context.new_type::<()>(), &[],
37 initializer_name, false);
38 self.llbb().add_eval(None, self.context.new_call(None, codegen_init_func, &[]));
42 // TODO(antoyo): insert reference to gdb debug scripts section global.
45 fn set_var_name(&mut self, _value: RValue<'gcc>, _name: &str) {
49 fn set_dbg_loc(&mut self, _dbg_loc: Self::DILocation) {
54 impl<'gcc, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
55 fn create_vtable_metadata(&self, _ty: Ty<'tcx>, _vtable: Self::Value) {
59 fn create_function_debug_context(&self, _instance: Instance<'tcx>, _fn_abi: &FnAbi<'tcx, Ty<'tcx>>, _llfn: RValue<'gcc>, _mir: &mir::Body<'tcx>) -> Option<FunctionDebugContext<Self::DIScope, Self::DILocation>> {
64 fn extend_scope_to_file(&self, _scope_metadata: Self::DIScope, _file: &SourceFile) -> Self::DIScope {
68 fn debuginfo_finalize(&self) {
72 fn create_dbg_var(&self, _variable_name: Symbol, _variable_type: Ty<'tcx>, _scope_metadata: Self::DIScope, _variable_kind: VariableKind, _span: Span) -> Self::DIVariable {
76 fn dbg_scope_fn(&self, _instance: Instance<'tcx>, _fn_abi: &FnAbi<'tcx, Ty<'tcx>>, _maybe_definition_llfn: Option<RValue<'gcc>>) -> Self::DIScope {
80 fn dbg_loc(&self, _scope: Self::DIScope, _inlined_at: Option<Self::DILocation>, _span: Span) -> Self::DILocation {