@@ -2,6 +2,7 @@ use std::borrow::Cow;
2
2
use std:: fmt:: { self , Write } ;
3
3
use std:: hash:: { Hash , Hasher } ;
4
4
use std:: path:: { Path , PathBuf } ;
5
+ use std:: sync:: Arc ;
5
6
use std:: { iter, ptr} ;
6
7
7
8
use libc:: { c_char, c_longlong, c_uint} ;
@@ -38,7 +39,7 @@ use crate::debuginfo::metadata::type_map::build_type_with_children;
38
39
use crate :: debuginfo:: utils:: { WidePtrKind , wide_pointer_kind} ;
39
40
use crate :: llvm;
40
41
use crate :: llvm:: debuginfo:: {
41
- DICompositeType , DIDescriptor , DIFile , DIFlags , DILexicalBlock , DIScope , DIType ,
42
+ DIBuilder , DICompositeType , DIDescriptor , DIFile , DIFlags , DILexicalBlock , DIScope , DIType ,
42
43
DebugEmissionKind , DebugNameTableKind ,
43
44
} ;
44
45
use crate :: value:: Value ;
@@ -623,42 +624,38 @@ pub(crate) fn file_metadata<'ll>(cx: &CodegenCx<'ll, '_>, source_file: &SourceFi
623
624
let source =
624
625
cx. sess ( ) . opts . unstable_opts . embed_source . then_some ( ( ) ) . and ( source_file. src . as_ref ( ) ) ;
625
626
626
- unsafe {
627
- llvm:: LLVMRustDIBuilderCreateFile (
628
- DIB ( cx) ,
629
- file_name. as_c_char_ptr ( ) ,
630
- file_name. len ( ) ,
631
- directory. as_c_char_ptr ( ) ,
632
- directory. len ( ) ,
633
- hash_kind,
634
- hash_value. as_c_char_ptr ( ) ,
635
- hash_value. len ( ) ,
636
- source. map_or ( ptr:: null ( ) , |x| x. as_c_char_ptr ( ) ) ,
637
- source. map_or ( 0 , |x| x. len ( ) ) ,
638
- )
639
- }
627
+ create_file ( DIB ( cx) , & file_name, & directory, & hash_value, hash_kind, source)
640
628
}
641
629
}
642
630
643
631
fn unknown_file_metadata < ' ll > ( cx : & CodegenCx < ' ll , ' _ > ) -> & ' ll DIFile {
644
- debug_context ( cx) . created_files . borrow_mut ( ) . entry ( None ) . or_insert_with ( || unsafe {
645
- let file_name = "<unknown>" ;
646
- let directory = "" ;
647
- let hash_value = "" ;
632
+ debug_context ( cx) . created_files . borrow_mut ( ) . entry ( None ) . or_insert_with ( || {
633
+ create_file ( DIB ( cx ) , "<unknown>" , "" , "" , llvm :: ChecksumKind :: None , None )
634
+ } )
635
+ }
648
636
637
+ fn create_file < ' ll > (
638
+ builder : & DIBuilder < ' ll > ,
639
+ file_name : & str ,
640
+ directory : & str ,
641
+ hash_value : & str ,
642
+ hash_kind : llvm:: ChecksumKind ,
643
+ source : Option < & Arc < String > > ,
644
+ ) -> & ' ll DIFile {
645
+ unsafe {
649
646
llvm:: LLVMRustDIBuilderCreateFile (
650
- DIB ( cx ) ,
647
+ builder ,
651
648
file_name. as_c_char_ptr ( ) ,
652
649
file_name. len ( ) ,
653
650
directory. as_c_char_ptr ( ) ,
654
651
directory. len ( ) ,
655
- llvm :: ChecksumKind :: None ,
652
+ hash_kind ,
656
653
hash_value. as_c_char_ptr ( ) ,
657
654
hash_value. len ( ) ,
658
- ptr:: null ( ) ,
659
- 0 ,
655
+ source . map_or ( ptr:: null ( ) , |x| x . as_c_char_ptr ( ) ) ,
656
+ source . map_or ( 0 , |x| x . len ( ) ) ,
660
657
)
661
- } )
658
+ }
662
659
}
663
660
664
661
trait MsvcBasicName {
@@ -932,17 +929,13 @@ pub(crate) fn build_compile_unit_di_node<'ll, 'tcx>(
932
929
} ;
933
930
934
931
unsafe {
935
- let compile_unit_file = llvm :: LLVMRustDIBuilderCreateFile (
932
+ let compile_unit_file = create_file (
936
933
debug_context. builder . as_ref ( ) ,
937
- name_in_debuginfo. as_c_char_ptr ( ) ,
938
- name_in_debuginfo. len ( ) ,
939
- work_dir. as_c_char_ptr ( ) ,
940
- work_dir. len ( ) ,
934
+ & name_in_debuginfo,
935
+ & work_dir,
936
+ "" ,
941
937
llvm:: ChecksumKind :: None ,
942
- ptr:: null ( ) ,
943
- 0 ,
944
- ptr:: null ( ) ,
945
- 0 ,
938
+ None ,
946
939
) ;
947
940
948
941
let unit_metadata = llvm:: LLVMRustDIBuilderCreateCompileUnit (
0 commit comments