|
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::attrs::AttributeKind;
|
8 | 8 | use rustc_hir::def_id::LOCAL_CRATE;
|
@@ -53,10 +53,14 @@ pub(crate) fn get_or_insert_gdb_debug_scripts_section_global<'ll>(
|
53 | 53 |
|
54 | 54 | // Next, add the pretty printers that were specified via the `#[debugger_visualizer]`
|
55 | 55 | // attribute.
|
56 |
| - let visualizers = collect_debugger_visualizers_transitive( |
57 |
| - cx.tcx, |
58 |
| - DebuggerVisualizerType::GdbPrettyPrinter, |
59 |
| - ); |
| 56 | + let visualizers = cx |
| 57 | + .tcx |
| 58 | + .debugger_visualizers(LOCAL_CRATE) |
| 59 | + .iter() |
| 60 | + .filter(|visualizer| { |
| 61 | + visualizer.visualizer_type == DebuggerVisualizerType::GdbPrettyPrinter |
| 62 | + }) |
| 63 | + .collect::<BTreeSet<_>>(); |
60 | 64 | let crate_name = cx.tcx.crate_name(LOCAL_CRATE);
|
61 | 65 | for (index, visualizer) in visualizers.iter().enumerate() {
|
62 | 66 | // The initial byte `4` instructs GDB that the following pretty printer
|
@@ -96,31 +100,14 @@ pub(crate) fn needs_gdb_debug_scripts_section(cx: &CodegenCx<'_, '_>) -> bool {
|
96 | 100 | let omit_gdb_pretty_printer_section =
|
97 | 101 | find_attr!(cx.tcx.hir_krate_attrs(), AttributeKind::OmitGdbPrettyPrinterSection);
|
98 | 102 |
|
99 |
| - // We collect pretty printers transitively for all crates, so we make sure |
100 |
| - // that the section is only emitted for leaf crates. |
101 |
| - let embed_visualizers = cx.tcx.crate_types().iter().any(|&crate_type| match crate_type { |
102 |
| - CrateType::Executable | CrateType::Cdylib | CrateType::Staticlib | CrateType::Sdylib => { |
103 |
| - // These are crate types for which we will embed pretty printers since they |
104 |
| - // are treated as leaf crates. |
105 |
| - true |
106 |
| - } |
107 |
| - CrateType::ProcMacro => { |
108 |
| - // We could embed pretty printers for proc macro crates too but it does not |
109 |
| - // seem like a good default, since this is a rare use case and we don't |
110 |
| - // want to slow down the common case. |
111 |
| - false |
112 |
| - } |
113 |
| - CrateType::Rlib | CrateType::Dylib => { |
114 |
| - // Don't embed pretty printers for these crate types; the compiler |
115 |
| - // can see the `#[debug_visualizer]` attributes when using the |
116 |
| - // library, and emitting `.debug_gdb_scripts` regardless would |
117 |
| - // break `#![omit_gdb_pretty_printer_section]`. |
118 |
| - false |
119 |
| - } |
120 |
| - }); |
| 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 | + let proc_macro_only = |
| 107 | + cx.tcx.crate_types().iter().all(|&crate_type| crate_type == CrateType::ProcMacro); |
121 | 108 |
|
122 | 109 | !omit_gdb_pretty_printer_section
|
123 | 110 | && cx.sess().opts.debuginfo != DebugInfo::None
|
124 | 111 | && cx.sess().target.emit_debug_gdb_scripts
|
125 |
| - && embed_visualizers |
| 112 | + && !proc_macro_only |
126 | 113 | }
|
0 commit comments