diff options
| author | Sebastian Poeplau <poeplau@adacore.com> | 2025-08-01 13:22:06 +0200 |
|---|---|---|
| committer | Sebastian Poeplau <poeplau@adacore.com> | 2025-08-06 13:24:43 +0200 |
| commit | b4d923cea0509933b1fb859930cb20784251f9be (patch) | |
| tree | 58b8486ceb371d81ba02a30cbc56b9f954596866 /compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs | |
| parent | 868bdde25b030e0b71a29a5dbc04a891036e702e (diff) | |
| download | rust-b4d923cea0509933b1fb859930cb20784251f9be.tar.gz rust-b4d923cea0509933b1fb859930cb20784251f9be.zip | |
Embed GDB pretty printers in rlibs and dylibs
Instead of collecting pretty printers transitively when building executables/staticlibs/cdylibs, let the debugger find each crate's pretty printers via its .debug_gdb_scripts section. This covers the case where libraries defining custom pretty printers are loaded dynamically.
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs | 43 |
1 files changed, 11 insertions, 32 deletions
diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs b/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs index b3e978be570..fccd32dec95 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::{CrateType, DebugInfo}; +use rustc_session::config::DebugInfo; use crate::builder::Builder; use crate::common::CodegenCx; @@ -51,10 +51,14 @@ 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 = collect_debugger_visualizers_transitive( - cx.tcx, - DebuggerVisualizerType::GdbPrettyPrinter, - ); + let visualizers = cx + .tcx + .debugger_visualizers(LOCAL_CRATE) + .iter() + .filter(|visualizer| { + visualizer.visualizer_type == DebuggerVisualizerType::GdbPrettyPrinter + }) + .collect::<BTreeSet<_>>(); 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 @@ -91,30 +95,5 @@ pub(crate) fn get_or_insert_gdb_debug_scripts_section_global<'ll>( } pub(crate) fn needs_gdb_debug_scripts_section(cx: &CodegenCx<'_, '_>) -> bool { - // 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 + cx.sess().opts.debuginfo != DebugInfo::None && cx.sess().target.emit_debug_gdb_scripts } |
