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 /compiler/rustc_codegen_llvm/src | |
| parent | 8fb40f798a23adf608182ce5f4eb151fdc8e0da5 (diff) | |
| download | rust-270c1a4d24ba4b244037c3fa1651d17a5f77eae4.tar.gz rust-270c1a4d24ba4b244037c3fa1651d17a5f77eae4.zip | |
Revert "Embed GDB pretty printers in rlibs and dylibs"
This reverts commit b4d923cea0509933b1fb859930cb20784251f9be.
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs | 43 |
1 files changed, 32 insertions, 11 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 } |
