@@ -29,6 +29,7 @@ use rustc_middle::ty::layout::HasTyCtxt;
29
29
use rustc_middle:: ty:: subst:: { GenericArgKind , SubstsRef } ;
30
30
use rustc_middle:: ty:: { self , Instance , ParamEnv , Ty , TypeFoldable } ;
31
31
use rustc_session:: config:: { self , DebugInfo } ;
32
+ use rustc_session:: Session ;
32
33
use rustc_span:: symbol:: Symbol ;
33
34
use rustc_span:: { self , BytePos , Pos , SourceFile , SourceFileAndLine , Span } ;
34
35
use rustc_target:: abi:: { LayoutOf , Primitive , Size } ;
@@ -95,45 +96,52 @@ impl<'a, 'tcx> CrateDebugContext<'a, 'tcx> {
95
96
composite_types_completed : Default :: default ( ) ,
96
97
}
97
98
}
98
- }
99
-
100
- /// Creates any deferred debug metadata nodes
101
- pub fn finalize ( cx : & CodegenCx < ' _ , ' _ > ) {
102
- if cx. dbg_cx . is_none ( ) {
103
- return ;
104
- }
105
99
106
- debug ! ( "finalize" ) ;
100
+ pub fn finalize ( & self , sess : & Session ) {
101
+ unsafe {
102
+ llvm:: LLVMRustDIBuilderFinalize ( self . builder ) ;
103
+
104
+ // Debuginfo generation in LLVM by default uses a higher
105
+ // version of dwarf than macOS currently understands. We can
106
+ // instruct LLVM to emit an older version of dwarf, however,
107
+ // for macOS to understand. For more info see #11352
108
+ // This can be overridden using --llvm-opts -dwarf-version,N.
109
+ // Android has the same issue (#22398)
110
+ if let Some ( version) = sess. target . dwarf_version {
111
+ llvm:: LLVMRustAddModuleFlag ( self . llmod , "Dwarf Version\0 " . as_ptr ( ) . cast ( ) , version)
112
+ }
107
113
108
- if gdb:: needs_gdb_debug_scripts_section ( cx) {
109
- // Add a .debug_gdb_scripts section to this compile-unit. This will
110
- // cause GDB to try and load the gdb_load_rust_pretty_printers.py file,
111
- // which activates the Rust pretty printers for binary this section is
112
- // contained in.
113
- gdb:: get_or_insert_gdb_debug_scripts_section_global ( cx) ;
114
- }
114
+ // Indicate that we want CodeView debug information on MSVC
115
+ if sess. target . is_like_msvc {
116
+ llvm:: LLVMRustAddModuleFlag ( self . llmod , "CodeView\0 " . as_ptr ( ) . cast ( ) , 1 )
117
+ }
115
118
116
- unsafe {
117
- llvm:: LLVMRustDIBuilderFinalize ( DIB ( cx) ) ;
118
- // Debuginfo generation in LLVM by default uses a higher
119
- // version of dwarf than macOS currently understands. We can
120
- // instruct LLVM to emit an older version of dwarf, however,
121
- // for macOS to understand. For more info see #11352
122
- // This can be overridden using --llvm-opts -dwarf-version,N.
123
- // Android has the same issue (#22398)
124
- if let Some ( version) = cx. sess ( ) . target . dwarf_version {
125
- llvm:: LLVMRustAddModuleFlag ( cx. llmod , "Dwarf Version\0 " . as_ptr ( ) . cast ( ) , version)
119
+ // Prevent bitcode readers from deleting the debug info.
120
+ let ptr = "Debug Info Version\0 " . as_ptr ( ) ;
121
+ llvm:: LLVMRustAddModuleFlag (
122
+ self . llmod ,
123
+ ptr. cast ( ) ,
124
+ llvm:: LLVMRustDebugMetadataVersion ( ) ,
125
+ ) ;
126
126
}
127
+ }
128
+ }
127
129
128
- // Indicate that we want CodeView debug information on MSVC
129
- if cx. sess ( ) . target . is_like_msvc {
130
- llvm:: LLVMRustAddModuleFlag ( cx. llmod , "CodeView\0 " . as_ptr ( ) . cast ( ) , 1 )
130
+ /// Creates any deferred debug metadata nodes
131
+ pub fn finalize ( cx : & CodegenCx < ' _ , ' _ > ) {
132
+ if let Some ( dbg_cx) = & cx. dbg_cx {
133
+ debug ! ( "finalize" ) ;
134
+
135
+ if gdb:: needs_gdb_debug_scripts_section ( cx) {
136
+ // Add a .debug_gdb_scripts section to this compile-unit. This will
137
+ // cause GDB to try and load the gdb_load_rust_pretty_printers.py file,
138
+ // which activates the Rust pretty printers for binary this section is
139
+ // contained in.
140
+ gdb:: get_or_insert_gdb_debug_scripts_section_global ( cx) ;
131
141
}
132
142
133
- // Prevent bitcode readers from deleting the debug info.
134
- let ptr = "Debug Info Version\0 " . as_ptr ( ) ;
135
- llvm:: LLVMRustAddModuleFlag ( cx. llmod , ptr. cast ( ) , llvm:: LLVMRustDebugMetadataVersion ( ) ) ;
136
- } ;
143
+ dbg_cx. finalize ( cx. sess ( ) ) ;
144
+ }
137
145
}
138
146
139
147
impl DebugInfoBuilderMethods for Builder < ' a , ' ll , ' tcx > {
0 commit comments