|
1 | 1 | // .debug_gdb_scripts binary section. |
2 | 2 |
|
| 3 | +use std::collections::BTreeSet; |
3 | 4 | use std::ffi::CString; |
4 | 5 |
|
5 | | -use rustc_codegen_ssa::base::collect_debugger_visualizers_transitive; |
6 | 6 | use rustc_codegen_ssa::traits::*; |
7 | 7 | use rustc_hir::def_id::LOCAL_CRATE; |
8 | 8 | use rustc_middle::bug; |
9 | 9 | use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerType; |
10 | | -use rustc_session::config::{CrateType, DebugInfo}; |
| 10 | +use rustc_session::config::DebugInfo; |
11 | 11 |
|
12 | 12 | use crate::builder::Builder; |
13 | 13 | use crate::common::CodegenCx; |
@@ -51,10 +51,14 @@ pub(crate) fn get_or_insert_gdb_debug_scripts_section_global<'ll>( |
51 | 51 |
|
52 | 52 | // Next, add the pretty printers that were specified via the `#[debugger_visualizer]` |
53 | 53 | // attribute. |
54 | | - let visualizers = collect_debugger_visualizers_transitive( |
55 | | - cx.tcx, |
56 | | - DebuggerVisualizerType::GdbPrettyPrinter, |
57 | | - ); |
| 54 | + let visualizers = cx |
| 55 | + .tcx |
| 56 | + .debugger_visualizers(LOCAL_CRATE) |
| 57 | + .iter() |
| 58 | + .filter(|visualizer| { |
| 59 | + visualizer.visualizer_type == DebuggerVisualizerType::GdbPrettyPrinter |
| 60 | + }) |
| 61 | + .collect::<BTreeSet<_>>(); |
58 | 62 | let crate_name = cx.tcx.crate_name(LOCAL_CRATE); |
59 | 63 | for (index, visualizer) in visualizers.iter().enumerate() { |
60 | 64 | // 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>( |
91 | 95 | } |
92 | 96 |
|
93 | 97 | pub(crate) fn needs_gdb_debug_scripts_section(cx: &CodegenCx<'_, '_>) -> bool { |
94 | | - // We collect pretty printers transitively for all crates, so we make sure |
95 | | - // that the section is only emitted for leaf crates. |
96 | | - let embed_visualizers = cx.tcx.crate_types().iter().any(|&crate_type| match crate_type { |
97 | | - CrateType::Executable | CrateType::Cdylib | CrateType::Staticlib | CrateType::Sdylib => { |
98 | | - // These are crate types for which we will embed pretty printers since they |
99 | | - // are treated as leaf crates. |
100 | | - true |
101 | | - } |
102 | | - CrateType::ProcMacro => { |
103 | | - // We could embed pretty printers for proc macro crates too but it does not |
104 | | - // seem like a good default, since this is a rare use case and we don't |
105 | | - // want to slow down the common case. |
106 | | - false |
107 | | - } |
108 | | - CrateType::Rlib | CrateType::Dylib => { |
109 | | - // Don't embed pretty printers for these crate types; the compiler |
110 | | - // can see the `#[debug_visualizer]` attributes when using the |
111 | | - // library, and emitting `.debug_gdb_scripts` regardless would |
112 | | - // break `#![omit_gdb_pretty_printer_section]`. |
113 | | - false |
114 | | - } |
115 | | - }); |
116 | | - |
117 | | - cx.sess().opts.debuginfo != DebugInfo::None |
118 | | - && cx.sess().target.emit_debug_gdb_scripts |
119 | | - && embed_visualizers |
| 98 | + cx.sess().opts.debuginfo != DebugInfo::None && cx.sess().target.emit_debug_gdb_scripts |
120 | 99 | } |
0 commit comments