diff options
| author | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2025-08-06 18:00:58 +0000 |
|---|---|---|
| committer | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2025-08-06 18:00:58 +0000 |
| commit | 270c1a4d24ba4b244037c3fa1651d17a5f77eae4 (patch) | |
| tree | 210890e29d66f837787f39f35ea205cc44170884 | |
| parent | 8fb40f798a23adf608182ce5f4eb151fdc8e0da5 (diff) | |
| download | rust-270c1a4d24ba4b244037c3fa1651d17a5f77eae4.tar.gz rust-270c1a4d24ba4b244037c3fa1651d17a5f77eae4.zip | |
Revert "Embed GDB pretty printers in rlibs and dylibs"
This reverts commit b4d923cea0509933b1fb859930cb20784251f9be.
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs | 43 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/base.rs | 10 | ||||
| -rw-r--r-- | src/tools/compiletest/src/directives/directive_names.rs | 1 | ||||
| -rw-r--r-- | tests/debuginfo/embedded-visualizer.rs | 2 |
4 files changed, 33 insertions, 23 deletions
diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs b/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs index fccd32dec95..b3e978be570 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs @@ -1,13 +1,13 @@ // .debug_gdb_scripts binary section. -use std::collections::BTreeSet; use std::ffi::CString; +use rustc_codegen_ssa::base::collect_debugger_visualizers_transitive; use rustc_codegen_ssa::traits::*; use rustc_hir::def_id::LOCAL_CRATE; use rustc_middle::bug; use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerType; -use rustc_session::config::DebugInfo; +use rustc_session::config::{CrateType, DebugInfo}; use crate::builder::Builder; use crate::common::CodegenCx; @@ -51,14 +51,10 @@ pub(crate) fn get_or_insert_gdb_debug_scripts_section_global<'ll>( // Next, add the pretty printers that were specified via the `#[debugger_visualizer]` // attribute. - let visualizers = cx - .tcx - .debugger_visualizers(LOCAL_CRATE) - .iter() - .filter(|visualizer| { - visualizer.visualizer_type == DebuggerVisualizerType::GdbPrettyPrinter - }) - .collect::<BTreeSet<_>>(); + let visualizers = collect_debugger_visualizers_transitive( + cx.tcx, + DebuggerVisualizerType::GdbPrettyPrinter, + ); let crate_name = cx.tcx.crate_name(LOCAL_CRATE); for (index, visualizer) in visualizers.iter().enumerate() { // The initial byte `4` instructs GDB that the following pretty printer @@ -95,5 +91,30 @@ pub(crate) fn get_or_insert_gdb_debug_scripts_section_global<'ll>( } pub(crate) fn needs_gdb_debug_scripts_section(cx: &CodegenCx<'_, '_>) -> bool { - cx.sess().opts.debuginfo != DebugInfo::None && cx.sess().target.emit_debug_gdb_scripts + // We collect pretty printers transitively for all crates, so we make sure + // that the section is only emitted for leaf crates. + let embed_visualizers = cx.tcx.crate_types().iter().any(|&crate_type| match crate_type { + CrateType::Executable | CrateType::Cdylib | CrateType::Staticlib | CrateType::Sdylib => { + // These are crate types for which we will embed pretty printers since they + // are treated as leaf crates. + true + } + CrateType::ProcMacro => { + // We could embed pretty printers for proc macro crates too but it does not + // seem like a good default, since this is a rare use case and we don't + // want to slow down the common case. + false + } + CrateType::Rlib | CrateType::Dylib => { + // Don't embed pretty printers for these crate types; the compiler + // can see the `#[debug_visualizer]` attributes when using the + // library, and emitting `.debug_gdb_scripts` regardless would + // break `#![omit_gdb_pretty_printer_section]`. + false + } + }); + + cx.sess().opts.debuginfo != DebugInfo::None + && cx.sess().target.emit_debug_gdb_scripts + && embed_visualizers } diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index b4556ced0b3..eb21468650c 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -609,15 +609,7 @@ pub fn collect_debugger_visualizers_transitive( ) -> BTreeSet<DebuggerVisualizerFile> { tcx.debugger_visualizers(LOCAL_CRATE) .iter() - .chain( - tcx.crates(()) - .iter() - .filter(|&cnum| { - let used_crate_source = tcx.used_crate_source(*cnum); - used_crate_source.rlib.is_some() || used_crate_source.rmeta.is_some() - }) - .flat_map(|&cnum| tcx.debugger_visualizers(cnum)), - ) + .chain(tcx.crates(()).iter().flat_map(|&cnum| tcx.debugger_visualizers(cnum))) .filter(|visualizer| visualizer.visualizer_type == visualizer_type) .cloned() .collect::<BTreeSet<_>>() diff --git a/src/tools/compiletest/src/directives/directive_names.rs b/src/tools/compiletest/src/directives/directive_names.rs index 099058bf051..f7955429d83 100644 --- a/src/tools/compiletest/src/directives/directive_names.rs +++ b/src/tools/compiletest/src/directives/directive_names.rs @@ -68,7 +68,6 @@ pub(crate) const KNOWN_DIRECTIVE_NAMES: &[&str] = &[ "ignore-gnu", "ignore-haiku", "ignore-horizon", - "ignore-i586-unknown-linux-gnu", "ignore-i686-pc-windows-gnu", "ignore-i686-pc-windows-msvc", "ignore-illumos", diff --git a/tests/debuginfo/embedded-visualizer.rs b/tests/debuginfo/embedded-visualizer.rs index 12d87be7c66..cbd8691394d 100644 --- a/tests/debuginfo/embedded-visualizer.rs +++ b/tests/debuginfo/embedded-visualizer.rs @@ -1,8 +1,6 @@ //@ compile-flags:-g //@ ignore-lldb //@ ignore-windows-gnu: #128981 -//@ ignore-musl: linker too old in CI -//@ ignore-i586-unknown-linux-gnu: linker too old in CI // === CDB TESTS ================================================================================== |
