@@ -30,7 +30,7 @@ use tracing::debug;
3030
3131use self :: metadata:: { UNKNOWN_COLUMN_NUMBER , UNKNOWN_LINE_NUMBER , file_metadata, type_di_node} ;
3232use self :: namespace:: mangled_name_of_instance;
33- use self :: utils:: { DIB , create_DIArray, is_node_local_to_unit} ;
33+ use self :: utils:: { DIB , create_DIArray, debug_context , is_node_local_to_unit} ;
3434use crate :: builder:: Builder ;
3535use crate :: common:: { AsCCharPtr , CodegenCx } ;
3636use crate :: llvm;
@@ -131,20 +131,22 @@ impl<'ll, 'tcx> CodegenUnitDebugContext<'ll, 'tcx> {
131131}
132132
133133/// Creates any deferred debug metadata nodes
134- pub ( crate ) fn finalize ( cx : & CodegenCx < ' _ , ' _ > ) {
135- if let Some ( dbg_cx) = & cx. dbg_cx {
136- debug ! ( "finalize" ) ;
137-
138- if gdb:: needs_gdb_debug_scripts_section ( cx) {
139- // Add a .debug_gdb_scripts section to this compile-unit. This will
140- // cause GDB to try and load the gdb_load_rust_pretty_printers.py file,
141- // which activates the Rust pretty printers for binary this section is
142- // contained in.
143- gdb:: get_or_insert_gdb_debug_scripts_section_global ( cx) ;
144- }
134+ pub ( crate ) fn finalize ( cx : & mut CodegenCx < ' _ , ' _ > ) {
135+ if cx. dbg_cx . is_none ( ) {
136+ return ;
137+ }
138+
139+ debug ! ( "finalize" ) ;
145140
146- dbg_cx. finalize ( cx. sess ( ) ) ;
141+ if gdb:: needs_gdb_debug_scripts_section ( cx) {
142+ // Add a .debug_gdb_scripts section to this compile-unit. This will
143+ // cause GDB to try and load the gdb_load_rust_pretty_printers.py file,
144+ // which activates the Rust pretty printers for binary this section is
145+ // contained in.
146+ gdb:: get_or_insert_gdb_debug_scripts_section_global ( cx) ;
147147 }
148+
149+ debug_context ( cx) . finalize ( cx. sess ( ) ) ;
148150}
149151
150152impl < ' ll > Builder < ' _ , ' ll , ' _ > {
@@ -215,10 +217,6 @@ impl<'ll> DebugInfoBuilderMethods for Builder<'_, 'll, '_> {
215217 }
216218 }
217219
218- fn insert_reference_to_gdb_debug_scripts_section_global ( & mut self ) {
219- gdb:: insert_reference_to_gdb_debug_scripts_section_global ( self )
220- }
221-
222220 fn set_var_name ( & mut self , value : & ' ll Value , name : & str ) {
223221 // Avoid wasting time if LLVM value names aren't even enabled.
224222 if self . sess ( ) . fewer_names ( ) {
@@ -614,7 +612,7 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
614612 metadata:: extend_scope_to_file ( self , scope_metadata, file)
615613 }
616614
617- fn debuginfo_finalize ( & self ) {
615+ fn debuginfo_finalize ( & mut self ) {
618616 finalize ( self )
619617 }
620618
0 commit comments