@@ -5,7 +5,7 @@ use rustc_data_structures::memmap::Mmap;
5
5
use rustc_data_structures:: temp_dir:: MaybeTempDir ;
6
6
use rustc_errors:: { ErrorGuaranteed , Handler } ;
7
7
use rustc_fs_util:: fix_windows_verbatim_for_gcc;
8
- use rustc_hir:: def_id:: { CrateNum , LOCAL_CRATE } ;
8
+ use rustc_hir:: def_id:: CrateNum ;
9
9
use rustc_middle:: middle:: dependency_format:: Linkage ;
10
10
use rustc_middle:: middle:: exported_symbols:: SymbolExportKind ;
11
11
use rustc_session:: config:: { self , CFGuard , CrateType , DebugInfo , LdImpl , Strip } ;
@@ -18,6 +18,7 @@ use rustc_session::utils::NativeLibKind;
18
18
/// need out of the shared crate context before we get rid of it.
19
19
use rustc_session:: { filesearch, Session } ;
20
20
use rustc_span:: symbol:: Symbol ;
21
+ use rustc_span:: DebuggerVisualizerFile ;
21
22
use rustc_target:: spec:: crt_objects:: { CrtObjects , CrtObjectsFallback } ;
22
23
use rustc_target:: spec:: { LinkOutputKind , LinkerFlavor , LldFlavor , SplitDebuginfo } ;
23
24
use rustc_target:: spec:: { PanicStrategy , RelocModel , RelroLevel , SanitizerSet , Target } ;
@@ -37,6 +38,7 @@ use regex::Regex;
37
38
use tempfile:: Builder as TempFileBuilder ;
38
39
39
40
use std:: borrow:: Borrow ;
41
+ use std:: collections:: BTreeSet ;
40
42
use std:: ffi:: OsString ;
41
43
use std:: fs:: { File , OpenOptions } ;
42
44
use std:: io:: { BufWriter , Write } ;
@@ -2099,14 +2101,16 @@ fn add_order_independent_options(
2099
2101
// Pass optimization flags down to the linker.
2100
2102
cmd. optimize ( ) ;
2101
2103
2102
- let debugger_visualizer_paths = if sess. target . is_like_msvc {
2103
- collect_debugger_visualizers ( tmpdir, sess, & codegen_results. crate_info )
2104
- } else {
2105
- Vec :: new ( )
2106
- } ;
2104
+ // Gather the set of NatVis files, if any, and write them out to a temp directory.
2105
+ let natvis_visualizers = collect_natvis_visualizers (
2106
+ tmpdir,
2107
+ sess,
2108
+ & codegen_results. crate_info . local_crate_name ,
2109
+ & codegen_results. crate_info . natvis_debugger_visualizers ,
2110
+ ) ;
2107
2111
2108
- // Pass debuginfo and strip flags down to the linker.
2109
- cmd. debuginfo ( strip_value ( sess) , & debugger_visualizer_paths ) ;
2112
+ // Pass debuginfo, NatVis debugger visualizers and strip flags down to the linker.
2113
+ cmd. debuginfo ( strip_value ( sess) , & natvis_visualizers ) ;
2110
2114
2111
2115
// We want to prevent the compiler from accidentally leaking in any system libraries,
2112
2116
// so by default we tell linkers not to link to any default libraries.
@@ -2125,43 +2129,33 @@ fn add_order_independent_options(
2125
2129
add_rpath_args ( cmd, sess, codegen_results, out_filename) ;
2126
2130
}
2127
2131
2128
- // Write the debugger visualizer files for each crate to the temp directory and gather the file paths.
2129
- fn collect_debugger_visualizers (
2132
+ // Write the NatVis debugger visualizer files for each crate to the temp directory and gather the file paths.
2133
+ fn collect_natvis_visualizers (
2130
2134
tmpdir : & Path ,
2131
2135
sess : & Session ,
2132
- crate_info : & CrateInfo ,
2136
+ crate_name : & Symbol ,
2137
+ natvis_debugger_visualizers : & BTreeSet < DebuggerVisualizerFile > ,
2133
2138
) -> Vec < PathBuf > {
2134
- let mut visualizer_paths = Vec :: new ( ) ;
2135
- let debugger_visualizers = & crate_info. debugger_visualizers ;
2136
- let mut index = 0 ;
2139
+ let mut visualizer_paths = Vec :: with_capacity ( natvis_debugger_visualizers. len ( ) ) ;
2137
2140
2138
- for ( & cnum, visualizers) in debugger_visualizers {
2139
- let crate_name = if cnum == LOCAL_CRATE {
2140
- crate_info. local_crate_name . as_str ( )
2141
- } else {
2142
- crate_info. crate_name [ & cnum] . as_str ( )
2143
- } ;
2141
+ for ( index, visualizer) in natvis_debugger_visualizers. iter ( ) . enumerate ( ) {
2142
+ let visualizer_out_file = tmpdir. join ( format ! ( "{}-{}.natvis" , crate_name. as_str( ) , index) ) ;
2144
2143
2145
- for visualizer in visualizers {
2146
- let visualizer_out_file = tmpdir. join ( format ! ( "{}-{}.natvis" , crate_name, index) ) ;
2147
-
2148
- match fs:: write ( & visualizer_out_file, & visualizer. src ) {
2149
- Ok ( ( ) ) => {
2150
- visualizer_paths. push ( visualizer_out_file. clone ( ) ) ;
2151
- index += 1 ;
2152
- }
2153
- Err ( error) => {
2154
- sess. warn (
2155
- format ! (
2156
- "Unable to write debugger visualizer file `{}`: {} " ,
2157
- visualizer_out_file. display( ) ,
2158
- error
2159
- )
2160
- . as_str ( ) ,
2161
- ) ;
2162
- }
2163
- } ;
2164
- }
2144
+ match fs:: write ( & visualizer_out_file, & visualizer. src ) {
2145
+ Ok ( ( ) ) => {
2146
+ visualizer_paths. push ( visualizer_out_file) ;
2147
+ }
2148
+ Err ( error) => {
2149
+ sess. warn (
2150
+ format ! (
2151
+ "Unable to write debugger visualizer file `{}`: {} " ,
2152
+ visualizer_out_file. display( ) ,
2153
+ error
2154
+ )
2155
+ . as_str ( ) ,
2156
+ ) ;
2157
+ }
2158
+ } ;
2165
2159
}
2166
2160
visualizer_paths
2167
2161
}
0 commit comments