@@ -29,6 +29,7 @@ use rustc_middle::ty::layout::HasTyCtxt;
2929use rustc_middle:: ty:: subst:: { GenericArgKind , SubstsRef } ;
3030use rustc_middle:: ty:: { self , Instance , ParamEnv , Ty , TypeFoldable } ;
3131use rustc_session:: config:: { self , DebugInfo } ;
32+ use rustc_session:: Session ;
3233use rustc_span:: symbol:: Symbol ;
3334use rustc_span:: { self , BytePos , Pos , SourceFile , SourceFileAndLine , Span } ;
3435use rustc_target:: abi:: { LayoutOf , Primitive , Size } ;
@@ -95,45 +96,52 @@ impl<'a, 'tcx> CrateDebugContext<'a, 'tcx> {
9596 composite_types_completed : Default :: default ( ) ,
9697 }
9798 }
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- }
10599
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+ }
107113
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+ }
115118
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+ ) ;
126126 }
127+ }
128+ }
127129
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) ;
131141 }
132142
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+ }
137145}
138146
139147impl DebugInfoBuilderMethods for Builder < ' a , ' ll , ' tcx > {
0 commit comments