diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs b/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs index 38f50a6d621bb..8e46d6d718cef 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs @@ -7,14 +7,12 @@ use crate::common::CodegenCx; use crate::value::Value; use rustc_codegen_ssa::traits::*; use rustc_middle::bug; -use rustc_session::config::DebugInfo; - -use rustc_span::symbol::sym; +use rustc_span::def_id::LOCAL_CRATE; /// Inserts a side-effect free instruction sequence that makes sure that the /// .debug_gdb_scripts global is referenced, so it isn't removed by the linker. pub fn insert_reference_to_gdb_debug_scripts_section_global(bx: &mut Builder<'_, '_, '_>) { - if needs_gdb_debug_scripts_section(bx) { + if bx.tcx.needs_gdb_debug_scripts_section(LOCAL_CRATE) { let gdb_debug_scripts_section = get_or_insert_gdb_debug_scripts_section_global(bx); // Load just the first byte as that's all that's necessary to force // LLVM to keep around the reference to the global. @@ -58,14 +56,3 @@ pub fn get_or_insert_gdb_debug_scripts_section_global(cx: &CodegenCx<'ll, '_>) - } }) } - -pub fn needs_gdb_debug_scripts_section(cx: &CodegenCx<'_, '_>) -> bool { - let omit_gdb_pretty_printer_section = cx - .tcx - .sess - .contains_name(&cx.tcx.hir().krate_attrs(), sym::omit_gdb_pretty_printer_section); - - !omit_gdb_pretty_printer_section - && cx.sess().opts.debuginfo != DebugInfo::None - && cx.sess().target.emit_debug_gdb_scripts -} diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index 955e739b2c126..1c5de2ca3ed03 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -106,7 +106,7 @@ pub fn finalize(cx: &CodegenCx<'_, '_>) { debug!("finalize"); - if gdb::needs_gdb_debug_scripts_section(cx) { + if cx.tcx.needs_gdb_debug_scripts_section(LOCAL_CRATE) { // Add a .debug_gdb_scripts section to this compile-unit. This will // cause GDB to try and load the gdb_load_rust_pretty_printers.py file, // which activates the Rust pretty printers for binary this section is diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 0fc11c286f899..7433732de2fc5 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -28,8 +28,9 @@ use rustc_middle::ty::layout::{FAT_PTR_ADDR, FAT_PTR_EXTRA}; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, Instance, Ty, TyCtxt}; use rustc_session::cgu_reuse_tracker::CguReuse; -use rustc_session::config::{self, EntryFnType}; +use rustc_session::config::{self, DebugInfo, EntryFnType}; use rustc_session::Session; +use rustc_span::sym; use rustc_target::abi::{Align, LayoutOf, VariantIdx}; use std::cmp; @@ -828,6 +829,17 @@ pub fn provide(providers: &mut Providers) { } tcx.sess.opts.optimize }; + + providers.needs_gdb_debug_scripts_section = |tcx, cnum| { + assert_eq!(cnum, LOCAL_CRATE); + + let omit_gdb_pretty_printer_section = + tcx.sess.contains_name(&tcx.hir().krate_attrs(), sym::omit_gdb_pretty_printer_section); + + !omit_gdb_pretty_printer_section + && tcx.sess.opts.debuginfo != DebugInfo::None + && tcx.sess.target.emit_debug_gdb_scripts + }; } fn determine_cgu_reuse<'tcx>(tcx: TyCtxt<'tcx>, cgu: &CodegenUnit<'tcx>) -> CguReuse { diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index ca528b2f0914b..a20731360100c 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1214,6 +1214,13 @@ rustc_queries! { desc { "looking up the paths for extern crates" } } + /// Determines if we need to emit a GDB debug script section + /// during codegen for the current crate. The CrateNum + /// should always be LOCAL_CRATE + query needs_gdb_debug_scripts_section(_: CrateNum) -> bool { + desc { "determine if the current crate needs a gdb debug scripts section" } + } + /// Given a crate and a trait, look up all impls of that trait in the crate. /// Return `(impl_id, self_ty)`. query implementations_of_trait(_: (CrateNum, DefId))