Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query-ify needs_gdb_debug_scripts_section #81056

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down