@@ -3,12 +3,12 @@ use std::path::{Component, Path};
33
44use crate :: prelude:: * ;
55
6- use rustc_span:: { FileName , SourceFileAndLine , Pos } ;
6+ use rustc_span:: { FileName , SourceFile , SourceFileAndLine , Pos , SourceFileHash , SourceFileHashAlgorithm } ;
77
88use cranelift_codegen:: binemit:: CodeOffset ;
99
1010use gimli:: write:: {
11- Address , AttributeValue , FileId , LineProgram , LineString , LineStringTable , UnitEntryId ,
11+ Address , AttributeValue , FileId , LineProgram , LineString , FileInfo , LineStringTable , UnitEntryId ,
1212} ;
1313
1414// OPTIMIZATION: It is cheaper to do this in one pass than using `.parent()` and `.file_name()`.
@@ -35,12 +35,28 @@ fn osstr_as_utf8_bytes(path: &OsStr) -> &[u8] {
3535 }
3636}
3737
38+ pub ( crate ) const MD5_LEN : usize = 16 ;
39+
40+ pub fn make_file_info ( hash : SourceFileHash ) -> Option < FileInfo > {
41+ if hash. kind == SourceFileHashAlgorithm :: Md5 {
42+ let mut buf = [ 0u8 ; MD5_LEN ] ;
43+ buf. copy_from_slice ( hash. hash_bytes ( ) ) ;
44+ Some ( FileInfo {
45+ timestamp : 0 ,
46+ size : 0 ,
47+ md5 : buf,
48+ } )
49+ } else {
50+ None
51+ }
52+ }
53+
3854fn line_program_add_file (
3955 line_program : & mut LineProgram ,
4056 line_strings : & mut LineStringTable ,
41- file : & FileName ,
57+ file : & SourceFile ,
4258) -> FileId {
43- match file {
59+ match & file. name {
4460 FileName :: Real ( path) => {
4561 let ( dir_path, file_name) = split_path_dir_and_file ( path) ;
4662 let dir_name = osstr_as_utf8_bytes ( dir_path. as_os_str ( ) ) ;
@@ -57,13 +73,17 @@ fn line_program_add_file(
5773 line_program. encoding ( ) ,
5874 line_strings,
5975 ) ;
60- line_program. add_file ( file_name, dir_id, None )
76+
77+ let info = make_file_info ( file. src_hash ) ;
78+
79+ line_program. file_has_md5 &= info. is_some ( ) ;
80+ line_program. add_file ( file_name, dir_id, info)
6181 }
6282 // FIXME give more appropriate file names
63- _ => {
83+ filename => {
6484 let dir_id = line_program. default_directory ( ) ;
6585 let dummy_file_name = LineString :: new (
66- file . to_string ( ) . into_bytes ( ) ,
86+ filename . to_string ( ) . into_bytes ( ) ,
6787 line_program. encoding ( ) ,
6888 line_strings,
6989 ) ;
@@ -79,7 +99,7 @@ impl<'tcx> DebugContext<'tcx> {
7999 let file_id = line_program_add_file (
80100 & mut self . dwarf . unit . line_program ,
81101 & mut self . dwarf . line_strings ,
82- & loc. file . name ,
102+ & loc. file ,
83103 ) ;
84104
85105 let entry = self . dwarf . unit . get_mut ( entry_id) ;
@@ -167,7 +187,7 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
167187 true
168188 } ;
169189 if current_file_changed {
170- let file_id = line_program_add_file ( line_program, line_strings, & file. name ) ;
190+ let file_id = line_program_add_file ( line_program, line_strings, & file) ;
171191 line_program. row ( ) . file = file_id;
172192 last_file = Some ( file. clone ( ) ) ;
173193 }
0 commit comments